Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ userIdentify
;

grantUserIdentify
: userIdentify (IDENTIFIED BY PASSWORD? STRING_LITERAL)?
: userIdentify (IDENTIFIED BY PASSWORD? pwd=STRING_LITERAL)?
;

explain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.parser;

import org.apache.doris.analysis.BrokerDesc;
import org.apache.doris.analysis.UserDesc;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.DatasourcePrintableMap;
import org.apache.doris.nereids.DorisParser;
Expand Down Expand Up @@ -85,6 +86,15 @@ public SetVarOp visitSetPassword(DorisParser.SetPasswordContext ctx) {
return super.visitSetPassword(ctx);
}

// grant user identity clause
@Override
public UserDesc visitGrantUserIdentify(DorisParser.GrantUserIdentifyContext ctx) {
if (ctx.pwd != null) {
encryptPassword(ctx.pwd.getStartIndex(), ctx.pwd.getStopIndex());
}
return super.visitGrantUserIdentify(ctx);
}

// set ldap password clause
@Override
public SetVarOp visitSetLdapAdminPassword(DorisParser.SetLdapAdminPasswordContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* AlterUserCommand
*/
public class AlterUserCommand extends AlterCommand {
public class AlterUserCommand extends AlterCommand implements NeedAuditEncryption {
Comment thread
iaorekhov-1980 marked this conversation as resolved.

private final AlterUserInfo alterUserInfo;

Expand Down Expand Up @@ -57,4 +57,9 @@ public void validate() throws UserException {
public StmtType stmtType() {
return StmtType.ALTER;
}

@Override
public boolean needAuditEncryption() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,68 @@ public void testEncryption() throws Exception {
}
}

@Test
public void testCreateUserPasswordMasking() throws Exception {
ctx.setDatabase("test");
try (MockedConstruction<StmtExecutor> ignored = Mockito.mockConstruction(StmtExecutor.class,
Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS),
(mock, context) -> {
Mockito.doReturn(false).when(mock).isForwardToMaster();
Profile profile = new Profile(false, 0, 0);
Deencapsulation.setField(mock, "profile", profile);
Mockito.doReturn(profile).when(mock).getProfile();
Mockito.doReturn(ctx).when(mock).getContext();
Mockito.doNothing().when(mock).execute();
Deencapsulation.setField(mock, "context", ctx);
if (context.arguments().size() >= 2
&& context.arguments().get(1) instanceof StatementBase) {
Deencapsulation.setField(mock, "parsedStmt",
context.arguments().get(1));
}
if (ctx.getStatementContext() == null) {
ctx.setStatementContext(new StatementContext());
}
})) {
ctx.setEnv(env);
ctx.setCurrentUserIdentity(UserIdentity.ROOT);
// testing for https://github.com/apache/doris/issues/62140
String sql = "CREATE USER 'test_user62140'@'%' IDENTIFIED BY '123456'";
String res = "CREATE USER 'test_user62140'@'%' IDENTIFIED BY '*XXX'";
parseAndCheck(sql, res);
}
}

@Test
public void testAlterUserPasswordMasking() throws Exception {
ctx.setDatabase("test");
try (MockedConstruction<StmtExecutor> ignored = Mockito.mockConstruction(StmtExecutor.class,
Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS),
(mock, context) -> {
Mockito.doReturn(false).when(mock).isForwardToMaster();
Profile profile = new Profile(false, 0, 0);
Deencapsulation.setField(mock, "profile", profile);
Mockito.doReturn(profile).when(mock).getProfile();
Mockito.doReturn(ctx).when(mock).getContext();
Mockito.doNothing().when(mock).execute();
Deencapsulation.setField(mock, "context", ctx);
if (context.arguments().size() >= 2
&& context.arguments().get(1) instanceof StatementBase) {
Deencapsulation.setField(mock, "parsedStmt",
context.arguments().get(1));
}
if (ctx.getStatementContext() == null) {
ctx.setStatementContext(new StatementContext());
}
})) {
ctx.setEnv(env);
ctx.setCurrentUserIdentity(UserIdentity.ROOT);
// testing for https://github.com/apache/doris/issues/62140
String sql = "ALTER USER 'test_user62140'@'%' IDENTIFIED BY '123456'";
String res = "ALTER USER 'test_user62140'@'%' IDENTIFIED BY '*XXX'";
parseAndCheck(sql, res);
}
}

private void parseAndCheck(String sql, String expected) throws Exception {
processor.executeQuery(sql);
AuditEvent event = auditEvents.get(auditEvents.size() - 1);
Expand Down
Loading