You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2025/12/17 05:35:07 UTC
(iotdb) 03/05: Fix compatibility issues for userid (#16473) (cherry-picked from 877c1c0d8574e4fbc0bd2b821b95dca36576b7ea)
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch rc/2.0.6
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c0068a4d0db416403e967db1c07d29e7bc6d241d
Author: wenyanshi-123 <34...@qq.com>
AuthorDate: Wed Sep 24 16:57:53 2025 +0800
Fix compatibility issues for userid (#16473)
(cherry-picked from 877c1c0d8574e4fbc0bd2b821b95dca36576b7ea)
---
.../org/apache/iotdb/commons/auth/entity/User.java | 1 +
.../iotdb/commons/auth/user/BasicUserManager.java | 20 +++++++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/User.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/User.java
index d7963bc3d77..48d4e6b2719 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/User.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/User.java
@@ -35,6 +35,7 @@ import java.util.Set;
/** This class contains all information of a User. */
public class User extends Role {
+ public static final long INTERNAL_USER_END_ID = 9999;
private long userId = -1;
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
index 0253e3dab0f..4f73cb38fba 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java
@@ -39,6 +39,9 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Map;
+import static org.apache.iotdb.commons.auth.entity.User.INTERNAL_USER_END_ID;
+
+
/** This class stores information of each user. */
public abstract class BasicUserManager extends BasicRoleManager {
@@ -54,7 +57,7 @@ public abstract class BasicUserManager extends BasicRoleManager {
return "No such user %s";
}
- protected long nextUserId = 9999;
+ protected long nextUserId = INTERNAL_USER_END_ID;
/**
* BasicUserManager Constructor.
@@ -108,11 +111,7 @@ public abstract class BasicUserManager extends BasicRoleManager {
private void initUserId() {
try {
long maxUserId = this.accessor.loadUserId();
- if (maxUserId < 9999) {
- nextUserId = 9999;
- } else {
- nextUserId = maxUserId;
- }
+ nextUserId = Math.max(maxUserId, INTERNAL_USER_END_ID);
for (Map.Entry<String, Role> userEntry : entityMap.entrySet()) {
User user = (User) userEntry.getValue();
@@ -240,16 +239,23 @@ public abstract class BasicUserManager extends BasicRoleManager {
public void reset() throws AuthException {
accessor.reset();
entityMap.clear();
+ initUserId();
for (String userId : accessor.listAllEntities()) {
try {
User user = (User) accessor.loadEntity(userId);
+ if (user.getUserId() == -1) {
+ if (user.getName().equals(CommonDescriptor.getInstance().getConfig().getAdminName())) {
+ user.setUserId(0);
+ } else {
+ user.setUserId(++nextUserId);
+ }
+ }
entityMap.put(user.getName(), user);
} catch (IOException e) {
LOGGER.warn("Get exception when load user {}", userId);
throw new AuthException(TSStatusCode.AUTH_IO_EXCEPTION, e);
}
}
- initUserId();
initAdmin();
}