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 @@ -81,16 +81,17 @@ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exc
userIdent = ConnectContext.get().getCurrentUserIdentity();
}
}
boolean isSelf = userIdent != null && ConnectContext.get().getCurrentUserIdentity().equals(userIdent);
Preconditions.checkState(isAll || userIdent != null);
UserIdentity self = ConnectContext.get().getCurrentUserIdentity();

// if show all grants, or show other user's grants, need global GRANT priv.
if (isAll || !self.equals(userIdent)) {
if (isAll || !isSelf) {
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.GRANT)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "GRANT");
}
}
if (userIdent != null && !Env.getCurrentEnv().getAccessManager().getAuth().doesUserExist(userIdent)) {
// ldap user not exist in userManager, so should not check
if (userIdent != null && !isSelf && !Env.getCurrentEnv().getAccessManager().getAuth()
.doesUserExist(userIdent)) {
throw new AnalysisException(String.format("User: %s does not exist", userIdent));
}
List<List<String>> infos = Env.getCurrentEnv().getAuth().getAuthInfo(userIdent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,21 @@ void testDorun() throws Exception {
int size = results.size();
Assertions.assertEquals("'zzz'@'%'", results.get(size - 1).get(0));
}

@Test
void testNonExistUser() {
ConnectContext ctx = ConnectContext.get();
UserIdentity nonExistUser = UserIdentity.createAnalyzedUserIdentWithIp("non_exist_user", "%");
Assertions.assertThrows(AnalysisException.class, () -> {
ShowGrantsCommand sg = new ShowGrantsCommand(nonExistUser, false);
sg.doRun(ctx, null);
});

ctx.setIsTempUser(true);
ctx.setCurrentUserIdentity(nonExistUser);
Assertions.assertDoesNotThrow(() -> {
ShowGrantsCommand sg = new ShowGrantsCommand(null, false);
sg.doRun(ctx, null);
});
}
}