Skip to content

Commit c0068a4

Browse files
wenyanshi-123JackieTien97
authored andcommitted
Fix compatibility issues for userid (#16473)
(cherry-picked from 877c1c0)
1 parent 9f22f8e commit c0068a4

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/entity/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
/** This class contains all information of a User. */
3737
public class User extends Role {
38+
public static final long INTERNAL_USER_END_ID = 9999;
3839

3940
private long userId = -1;
4041

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
import java.io.IOException;
4040
import java.util.Map;
4141

42+
import static org.apache.iotdb.commons.auth.entity.User.INTERNAL_USER_END_ID;
43+
44+
4245
/** This class stores information of each user. */
4346
public abstract class BasicUserManager extends BasicRoleManager {
4447

@@ -54,7 +57,7 @@ protected String getNoSuchEntityError() {
5457
return "No such user %s";
5558
}
5659

57-
protected long nextUserId = 9999;
60+
protected long nextUserId = INTERNAL_USER_END_ID;
5861

5962
/**
6063
* BasicUserManager Constructor.
@@ -108,11 +111,7 @@ private void initAdmin() throws AuthException {
108111
private void initUserId() {
109112
try {
110113
long maxUserId = this.accessor.loadUserId();
111-
if (maxUserId < 9999) {
112-
nextUserId = 9999;
113-
} else {
114-
nextUserId = maxUserId;
115-
}
114+
nextUserId = Math.max(maxUserId, INTERNAL_USER_END_ID);
116115

117116
for (Map.Entry<String, Role> userEntry : entityMap.entrySet()) {
118117
User user = (User) userEntry.getValue();
@@ -240,16 +239,23 @@ private void init() throws AuthException {
240239
public void reset() throws AuthException {
241240
accessor.reset();
242241
entityMap.clear();
242+
initUserId();
243243
for (String userId : accessor.listAllEntities()) {
244244
try {
245245
User user = (User) accessor.loadEntity(userId);
246+
if (user.getUserId() == -1) {
247+
if (user.getName().equals(CommonDescriptor.getInstance().getConfig().getAdminName())) {
248+
user.setUserId(0);
249+
} else {
250+
user.setUserId(++nextUserId);
251+
}
252+
}
246253
entityMap.put(user.getName(), user);
247254
} catch (IOException e) {
248255
LOGGER.warn("Get exception when load user {}", userId);
249256
throw new AuthException(TSStatusCode.AUTH_IO_EXCEPTION, e);
250257
}
251258
}
252-
initUserId();
253259
initAdmin();
254260
}
255261

0 commit comments

Comments
 (0)