Introduce IPA support.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / UserAdminLoginModule.java
index 243eb0fec84e1d6288cd89b187dc63a6f980b640..f5883a54f1035fc10608f7a5152380affa486c7a 100644 (file)
@@ -74,8 +74,10 @@ public class UserAdminLoginModule implements LoginModule {
                if (sharedState.containsKey(CmsAuthUtils.SHARED_STATE_NAME)
                                && sharedState.containsKey(CmsAuthUtils.SHARED_STATE_PWD)) {
                        username = (String) sharedState.get(CmsAuthUtils.SHARED_STATE_NAME);
-                       password = (char[]) sharedState.get(CmsAuthUtils.SHARED_STATE_NAME);
+                       password = (char[]) sharedState.get(CmsAuthUtils.SHARED_STATE_PWD);
                        // TODO locale?
+                       AuthenticatingUser authenticatingUser = new AuthenticatingUser(username, password);
+                       authorization = userAdmin.getAuthorization(authenticatingUser);
                } else {
 
                        // ask for username and password
@@ -114,24 +116,23 @@ public class UserAdminLoginModule implements LoginModule {
                                password = passwordCallback.getPassword();
                        else
                                throw new CredentialNotFoundException("No credentials provided");
+                       // FIXME move Argeo specific convention from user admin to here
+                       User user = userAdmin.getUser(null, username);
+                       if (user == null)
+                               throw new FailedLoginException("Invalid credentials");
+                       if (!user.hasCredential(null, password))
+                               throw new FailedLoginException("Invalid credentials");
+                       // return false;
+
+                       // Log and monitor new login
+                       // if (log.isDebugEnabled())
+                       // log.debug("Logged in to CMS with username [" + username +
+                       // "]");
+
+                       authorization = userAdmin.getAuthorization(user);
+                       assert authorization != null;
                }
 
-               // FIXME move Argeo specific convention from user admin to here
-               User user = userAdmin.getUser(null, username);
-               if (user == null)
-                       throw new FailedLoginException("Invalid credentials");
-               if (!user.hasCredential(null, password))
-                       throw new FailedLoginException("Invalid credentials");
-               // return false;
-
-               // Log and monitor new login
-               // if (log.isDebugEnabled())
-               // log.debug("Logged in to CMS with username [" + username +
-               // "]");
-
-               authorization = userAdmin.getAuthorization(user);
-               assert authorization != null;
-
                // }
                // if
                // (!sharedState.containsKey(CmsAuthUtils.SHARED_STATE_AUTHORIZATION))