This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new f8ad340df55 Avoid throwing AuthException to the state machine (#16677)
f8ad340df55 is described below
commit f8ad340df554c200d593257eeb53f3f930eb97b7
Author: shuwenwei <[email protected]>
AuthorDate: Thu Oct 30 20:19:47 2025 +0800
Avoid throwing AuthException to the state machine (#16677)
---
.../confignode/persistence/auth/AuthorInfo.java | 83 +++++++++++++++++-----
.../persistence/auth/AuthorPlanExecutor.java | 7 +-
2 files changed, 70 insertions(+), 20 deletions(-)
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorInfo.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorInfo.java
index 06c564fd5ac..06bcd81b7fa 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorInfo.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorInfo.java
@@ -150,34 +150,74 @@ public class AuthorInfo implements SnapshotProcessor {
return authorPlanExecutor.executeRelationalAuthorNonQuery(authorPlan);
}
- public PermissionInfoResp executeListUsers(final AuthorPlan plan) throws
AuthException {
- return authorPlanExecutor.executeListUsers(plan);
+ public PermissionInfoResp executeListUsers(final AuthorPlan plan) {
+ try {
+ return authorPlanExecutor.executeListUsers(plan);
+ } catch (AuthException e) {
+ PermissionInfoResp resp = new PermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
- public PermissionInfoResp executeListRoles(final AuthorPlan plan) throws
AuthException {
- return authorPlanExecutor.executeListRoles(plan);
+ public PermissionInfoResp executeListRoles(final AuthorPlan plan) {
+ try {
+ return authorPlanExecutor.executeListRoles(plan);
+ } catch (AuthException e) {
+ PermissionInfoResp resp = new PermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
- public PermissionInfoResp executeListRolePrivileges(final AuthorPlan plan)
throws AuthException {
- return authorPlanExecutor.executeListRolePrivileges(plan);
+ public PermissionInfoResp executeListRolePrivileges(final AuthorPlan plan) {
+ try {
+ return authorPlanExecutor.executeListRolePrivileges(plan);
+ } catch (AuthException e) {
+ PermissionInfoResp resp = new PermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
- public PermissionInfoResp executeListUserPrivileges(final AuthorPlan plan)
throws AuthException {
- return authorPlanExecutor.executeListUserPrivileges(plan);
+ public PermissionInfoResp executeListUserPrivileges(final AuthorPlan plan) {
+ try {
+ return authorPlanExecutor.executeListUserPrivileges(plan);
+ } catch (AuthException e) {
+ PermissionInfoResp resp = new PermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
- public TAuthizedPatternTreeResp generateAuthorizedPTree(String username, int
permission)
- throws AuthException {
- return authorPlanExecutor.generateAuthorizedPTree(username, permission);
+ public TAuthizedPatternTreeResp generateAuthorizedPTree(String username, int
permission) {
+ try {
+ return authorPlanExecutor.generateAuthorizedPTree(username, permission);
+ } catch (AuthException e) {
+ TAuthizedPatternTreeResp resp = new TAuthizedPatternTreeResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
- public TPermissionInfoResp checkRoleOfUser(String username, String roleName)
- throws AuthException {
- return authorPlanExecutor.checkRoleOfUser(username, roleName);
+ public TPermissionInfoResp checkRoleOfUser(String username, String roleName)
{
+ try {
+ return authorPlanExecutor.checkRoleOfUser(username, roleName);
+ } catch (AuthException e) {
+ TPermissionInfoResp resp = new TPermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
- public TPermissionInfoResp getUser(String username) throws AuthException {
- return authorPlanExecutor.getUser(username);
+ public TPermissionInfoResp getUser(String username) {
+ try {
+ return authorPlanExecutor.getUser(username);
+ } catch (AuthException e) {
+ TPermissionInfoResp resp = new TPermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
public String getUserName(long userId) throws AuthException {
@@ -199,9 +239,14 @@ public class AuthorInfo implements SnapshotProcessor {
*
* @param username The username of the user that needs to be cached
*/
- public TPermissionInfoResp getUserPermissionInfo(String username, ModelType
type)
- throws AuthException {
- return authorPlanExecutor.getUserPermissionInfo(username, type);
+ public TPermissionInfoResp getUserPermissionInfo(String username, ModelType
type) {
+ try {
+ return authorPlanExecutor.getUserPermissionInfo(username, type);
+ } catch (AuthException e) {
+ TPermissionInfoResp resp = new TPermissionInfoResp();
+ resp.setStatus(new
TSStatus(e.getCode().getStatusCode()).setMessage(e.getMessage()));
+ return resp;
+ }
}
public TSStatus enableSeparationOfAdminPowers(
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorPlanExecutor.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorPlanExecutor.java
index 1056ad735cf..9430cc06f02 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorPlanExecutor.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorPlanExecutor.java
@@ -715,6 +715,11 @@ public class AuthorPlanExecutor implements
IAuthorPlanExecutor {
@Override
public String getUserName(long userId) throws AuthException {
- return authorizer.getUser(userId).getName();
+ User user = authorizer.getUser(userId);
+ if (user == null) {
+ throw new AuthException(
+ TSStatusCode.USER_NOT_EXIST, String.format("No such user id: " +
userId));
+ }
+ return user.getName();
}
}