lasdf1234 commented on code in PR #11226:
URL: https://github.com/apache/gravitino/pull/11226#discussion_r3310765206


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/IdpUserGroupManager.java:
##########
@@ -45,28 +53,87 @@
  */
 public class IdpUserGroupManager implements Closeable {
 
-  private static final IdpUserMetaService USER_SERVICE = 
IdpUserMetaService.getInstance();
-  private static final IdpGroupMetaService GROUP_SERVICE = 
IdpGroupMetaService.getInstance();
+  private static final String BASIC_AUTHENTICATOR_CLASS_NAME =
+      BasicAuthenticator.class.getCanonicalName();
+
+  private static volatile IdpUserGroupManager instance;
 
   private final IdpRelationalStorage relationalStorage;
   private final IdGenerator idGenerator;
   private final PasswordHasher passwordHasher;
+  private final IdpUserMetaService userMetaService;
+  private final IdpGroupMetaService groupMetaService;
   private final IdpGarbageCollector garbageCollector;
 
-  /**
-   * Creates a built-in IdP user and group manager.
-   *
-   * @param config The server configuration.
-   * @param idGenerator The id generator.
-   */
-  public IdpUserGroupManager(Config config, IdGenerator idGenerator) {
+  public static IdpUserGroupManager getInstance(Config config, IdGenerator 
idGenerator) {
+    IdpUserGroupManager local = instance;
+    if (local == null) {
+      synchronized (IdpUserGroupManager.class) {
+        local = instance;
+        if (local == null) {
+          instance = new IdpUserGroupManager(config, idGenerator);
+          local = instance;
+        }
+      }
+    }
+    return local;
+  }
+
+  private IdpUserGroupManager(Config config, IdGenerator idGenerator) {
     this.relationalStorage = new IdpRelationalStorage(config);
     this.idGenerator = idGenerator;
     this.passwordHasher = PasswordHasherFactory.create();
+    this.userMetaService = IdpUserMetaService.getInstance();
+    this.groupMetaService = IdpGroupMetaService.getInstance();
     this.garbageCollector = new IdpGarbageCollector(config);
     garbageCollector.start();
   }
 
+  IdpUserGroupManager(
+      IdGenerator idGenerator, IdpUserMetaService userMetaService, 
PasswordHasher passwordHasher) {
+    this.relationalStorage = null;
+    this.idGenerator = idGenerator;
+    this.passwordHasher = passwordHasher;
+    this.userMetaService = userMetaService;
+    this.groupMetaService = null;
+    this.garbageCollector = null;
+  }
+
+  public void initializeConfiguredServiceAdmins(Config config, String 
initialAdminPassword)
+      throws IOException {
+    if (!basicAuthenticatorEnabled(config)) {
+      return;
+    }
+
+    List<String> serviceAdmins = config.get(Configs.SERVICE_ADMINS);
+    if (serviceAdmins == null || serviceAdmins.isEmpty()) {

Review Comment:
   Rsolved



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/IdpUserGroupManager.java:
##########
@@ -161,17 +243,34 @@ public IdpGroup changeGroupMembership(
     Preconditions.checkArgument(
         !usersToAddList.isEmpty() || !usersToRemoveList.isEmpty(),
         "usersToAdd and usersToRemove cannot both be empty");
-    GROUP_SERVICE.changeGroupMembership(groupName, usersToAddList, 
usersToRemoveList);
+    groupMetaService.changeGroupMembership(groupName, usersToAddList, 
usersToRemoveList);
     return getGroup(groupName);
   }
 
   @Override
   public void close() throws IOException {
-    garbageCollector.close();
-    relationalStorage.close();
+    try {
+      if (garbageCollector != null) {
+        garbageCollector.close();
+      }
+      if (relationalStorage != null) {
+        relationalStorage.close();
+      }
+    } finally {
+      synchronized (IdpUserGroupManager.class) {

Review Comment:
   Resolved



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to