Skip to content

fix: parse MySQL account authentication as SHOW CREATE USER prints it - #2863

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-account-auth-forms-20261027
Oct 28, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-account-auth-forms-20261027

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

SHOW CREATE USER prints the authentication plugin as a string literal and, with print_identified_with_as_hex enabled, a hash that contains unprintable characters as a hexadecimal literal, for example CREATE USER 'app'@'%' IDENTIFIED WITH 'caching_sha2_password' AS 0x2441…. MySQL also accepts CURRENT_USER() wherever a user account is named. The parser rejected all three: the plugin was read only as an identifier, AS took only a string literal, and an account name had no parentheses after CURRENT_USER. ALTER USER CURRENT_USER() was also routed to the PostgreSQL ALTER ROLE alias.

The plugin now reuses the account-name part production, so it may be unquoted or quoted with ', " or a backtick. UserAuthentication.getPluginName() keeps the quote character and getPlugin() returns the name. The hash after AS may be a hexadecimal literal, returned as a HexValue by getCredentialValue(); getCredential() still returns a string-literal credential and is null for a hexadecimal one. UserAccount.isCurrentUserParentheses() records CURRENT_USER() in user lists: CREATE, ALTER, DROP and RENAME USER, SET PASSWORD FOR and GRANT … TO. Role lists (CREATE and DROP ROLE, SET ROLE, SET DEFAULT ROLE, granted roles, DEFAULT ROLE) keep rejecting it, because MySQL reads them with role_ident.

Public method signatures are retained. For a backquoted plugin, getPlugin() now returns the name without its backquotes, as account names do.

Syntax reference: MySQL 8.4 CREATE USER, ALTER USER, account names, print_identified_with_as_hex.

Validation:

  • CreateUserTest, AlterUserTest and MySqlAccountNameTest add 22 cases. 8 of the 12 statements they parse fail on master 5d07ba424; the others pin unquoted names, plain CURRENT_USER and the grantee form that already worked. Further cases pin the rejections: hexadecimal only after AS, parentheses only after an unquoted CURRENT_USER, and CURRENT_USER() in role lists.
  • Java 17 Gradle check: 12,240 tests, 0 failures, 25 skipped; grammar ambiguity, formatting (Spotless ratchet against upstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass. JaCoCo instrumentation headroom of CCJSqlParser: 967 entries on master, 902 with this change.
  • MySQL 8.4.11: the SHOW CREATE USER output of a caching_sha2_password user with print_identified_with_as_hex enabled parses and renders unchanged, and running the rendered statement for another user stores the same plugin and authentication string. ALTER USER CURRENT_USER() IDENTIFIED BY … RETAIN CURRENT PASSWORD, SET PASSWORD FOR CURRENT_USER() and backquoted or double-quoted plugin names are accepted; SET DEFAULT ROLE ALL TO CURRENT_USER() is a syntax error.

AI assistance: prepared with Claude Code.

SHOW CREATE USER prints the authentication plugin as a string literal
and, with print_identified_with_as_hex enabled, a hash that contains
unprintable characters as a hexadecimal literal. MySQL also accepts
CURRENT_USER() wherever a user account is named. The plugin was read
only as an identifier, AS took only a string literal, and an account
name had no parentheses after CURRENT_USER; ALTER USER CURRENT_USER()
also went to the PostgreSQL ALTER ROLE alias.

The plugin reuses MySqlAccountNamePart, so it keeps its quote character
in UserAuthentication.getPluginName(). The hash after AS may be a
HexValue, returned by getCredentialValue(). UserAccount records
CURRENT_USER() in user lists; role lists still reject it, as MySQL
reads them with role_ident.

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit 19a3585 into JSQLParser:master Oct 28, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants