3939import java .io .IOException ;
4040import 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. */
4346public 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