From b28ae7f7c8ccfd011d53212f5f6920a0bb0e9563 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Thu, 16 Apr 2026 18:39:58 +0800 Subject: [PATCH 1/2] fix --- .../iotdb/db/auth/AuthorityChecker.java | 4 ++-- .../db/auth/ClusterAuthorityFetcher.java | 23 +++++++++++-------- .../iotdb/db/auth/IAuthorityFetcher.java | 2 +- .../config/TableConfigTaskVisitor.java | 5 +--- .../config/TreeConfigTaskVisitor.java | 15 ++++-------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java index fa7edec953ccb..eef9d9277b44a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java @@ -138,11 +138,11 @@ public static void invalidateAllCache() { } public static User getUser(String username) { - return authorityFetcher.get().getUser(username); + return authorityFetcher.get().getUser(username, false); } public static Optional getUserId(String username) { - User user = authorityFetcher.get().getUser(username); + User user = authorityFetcher.get().getUser(username, false); return Optional.ofNullable(user == null ? null : user.getUserId()); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/ClusterAuthorityFetcher.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/ClusterAuthorityFetcher.java index 325476174c667..f255d30385b6b 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/ClusterAuthorityFetcher.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/ClusterAuthorityFetcher.java @@ -32,6 +32,7 @@ import org.apache.iotdb.commons.conf.CommonDescriptor; import org.apache.iotdb.commons.consensus.ConfigRegionId; import org.apache.iotdb.commons.exception.IoTDBException; +import org.apache.iotdb.commons.exception.IoTDBRuntimeException; import org.apache.iotdb.commons.exception.MetadataException; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.commons.path.PathPatternTree; @@ -172,7 +173,7 @@ public List checkUserPathPrivileges( return posList; } checkCacheAvailable(); - User user = getUser(username); + User user = getUser(username, true); if (user.isOpenIdUser()) { return posList; } @@ -443,13 +444,12 @@ private SettableFuture handleAccountUnlock( Object authorStatement, String username, boolean isRelational, Runnable successCallback) { if (isUnlockStatement(authorStatement, isRelational)) { - SettableFuture future = SettableFuture.create(); - User user = getUser(username); - if (user == null) { - future.setException( - new IoTDBException( - String.format("User %s does not exist", username), - TSStatusCode.USER_NOT_EXIST.getStatusCode())); + final SettableFuture future = SettableFuture.create(); + final User user; + try { + user = getUser(username, false); + } catch (final IoTDBRuntimeException e) { + future.setException(e); return future; } String loginAddr = @@ -593,7 +593,8 @@ public TSStatus checkUser( } } - public User getUser(String userName) { + @Override + public User getUser(String userName, final boolean force) { checkCacheAvailable(); User user = iAuthorCache.getUserCache(userName); if (user != null) { @@ -616,6 +617,10 @@ public User getUser(String userName) { } } } + if (user == null && force) { + throw new IoTDBRuntimeException( + "User " + userName + " does not exist", TSStatusCode.USER_NOT_EXIST.getStatusCode()); + } return user; } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/IAuthorityFetcher.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/IAuthorityFetcher.java index 302679878955b..b14d5c599c142 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/IAuthorityFetcher.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/IAuthorityFetcher.java @@ -86,5 +86,5 @@ PathPatternTree getAuthorizedPatternTree(String username, PrivilegeType permissi void refreshToken(); - User getUser(String username); + User getUser(String username, final boolean force); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java index 0bb2efa9fd54e..1b0ea2c75e882 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java @@ -1491,10 +1491,7 @@ protected IConfigTask visitRelationalAuthorPlan( } private void visitUpdateUser(RelationalAuthorStatement node) { - User user = AuthorityChecker.getAuthorityFetcher().getUser(node.getUserName()); - if (user == null) { - throw new SemanticException("User " + node.getUserName() + " not found"); - } + final User user = AuthorityChecker.getAuthorityFetcher().getUser(node.getUserName(), true); node.setOldPassword(user.getPassword()); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java index 362982f645ccf..4e33c8240b449 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TreeConfigTaskVisitor.java @@ -22,7 +22,6 @@ import org.apache.iotdb.common.rpc.thrift.Model; import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.audit.UserEntity; -import org.apache.iotdb.commons.auth.entity.User; import org.apache.iotdb.commons.exception.auth.AccessDeniedException; import org.apache.iotdb.commons.executable.ExecutableManager; import org.apache.iotdb.commons.path.PartialPath; @@ -340,18 +339,14 @@ public IConfigTask visitAuthor(AuthorStatement statement, MPPQueryContext contex } private void visitUpdateUser(AuthorStatement statement) { - User user = AuthorityChecker.getAuthorityFetcher().getUser(statement.getUserName()); - if (user == null) { - throw new SemanticException("User " + statement.getUserName() + " not found"); - } - statement.setPassWord(user.getPassword()); + statement.setPassWord( + AuthorityChecker.getAuthorityFetcher() + .getUser(statement.getUserName(), true) + .getPassword()); } private void visitRenameUser(AuthorStatement statement) { - User user = AuthorityChecker.getAuthorityFetcher().getUser(statement.getUserName()); - if (user == null) { - throw new SemanticException("User " + statement.getUserName() + " not found"); - } + AuthorityChecker.getAuthorityFetcher().getUser(statement.getUserName(), true); } @Override From 4513c6b4eb987cb04e8d6c554e01f6469e6911a0 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 17 Apr 2026 10:07:41 +0800 Subject: [PATCH 2/2] fix-ci --- .../java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java index 5c8420752da9d..960c35f217ad7 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java @@ -564,7 +564,7 @@ public void testAlterNonExistingUser() throws SQLException { try { adminStmt.execute("ALTER USER nonExist SET PASSWORD 'asdfer1124566'"); } catch (SQLException e) { - assertEquals("701: User nonExist not found", e.getMessage()); + assertEquals("804: User nonExist does not exist", e.getMessage()); } } }