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


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/IdpUserGroupManager.java:
##########
@@ -182,6 +281,29 @@ private IdpUserPO newUserPO(String username, String 
passwordHash) {
         .build();
   }
 
+  private boolean userExists(String username) {

Review Comment:
   Got code has modified



##########
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(

Review Comment:
   Got code has modified



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/IdpUserGroupManager.java:
##########
@@ -96,8 +163,22 @@ public boolean removeUser(String username) {
    * @return The built-in IdP user.
    */
   public IdpUser getUser(String username) {
-    IdpUserPO userPO = USER_SERVICE.getIdpUserByUsername(username);
-    return new IdpUser(userPO.getUsername(), 
USER_SERVICE.listGroupNamesByUsername(username));
+    IdpUserPO userPO = userMetaService.getIdpUserByUsername(username);
+    return new IdpUser(userPO.getUsername(), 
userMetaService.listGroupNamesByUsername(username));
+  }
+
+  public IdpUser authenticate(String username, String password) {
+    try {
+      IdpUserPO userPO = userMetaService.getIdpUserByUsername(username);
+      if (!passwordHasher.verify(password, userPO.getPasswordHash())) {
+        throw new UnauthorizedException(
+            "Invalid username or password", 
AuthConstants.AUTHORIZATION_BASIC_HEADER.trim());
+      }
+      return new IdpUser(username, 
userMetaService.listGroupNamesByUsername(username));

Review Comment:
   Got code has modified



-- 
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