]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/auth/UserAdminLoginModule.java
Add a log debug when a new user log in to the CMS.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / UserAdminLoginModule.java
index 53e48e8c1ea4089eb13e7d5bd336c98619dc60c9..2faee6fa1157a5ed0c0e6a2af3da0bbefec9b6ae 100644 (file)
@@ -14,11 +14,14 @@ import javax.security.auth.callback.NameCallback;
 import javax.security.auth.callback.PasswordCallback;
 import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.security.auth.login.CredentialNotFoundException;
+import javax.security.auth.login.FailedLoginException;
 import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
 import org.argeo.cms.internal.kernel.Activator;
 import org.argeo.eclipse.ui.specific.UiContext;
@@ -29,6 +32,9 @@ import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
 
 public class UserAdminLoginModule implements LoginModule, AuthConstants {
+       private final static Log log = LogFactory
+                       .getLog(UserAdminLoginModule.class);
+
        private Subject subject;
        private CallbackHandler callbackHandler;
        private boolean isAnonymous = false;
@@ -70,6 +76,9 @@ public class UserAdminLoginModule implements LoginModule, AuthConstants {
                        } catch (IOException e) {
                                throw new LoginException("Cannot handle http callback: "
                                                + e.getMessage());
+                       } catch (ThreadDeath e) {
+                               throw new ThreadDeathLoginException(
+                                               "Callbackhandler thread died", e);
                        } catch (UnsupportedCallbackException e) {
                                return false;
                        }
@@ -105,9 +114,15 @@ public class UserAdminLoginModule implements LoginModule, AuthConstants {
 
                                        User user = userAdmin.getUser(null, username);
                                        if (user == null)
-                                               return false;
+                                               throw new FailedLoginException("Invalid credentials");
                                        if (!user.hasCredential(null, password))
-                                               return false;
+                                               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);
                                }
                        }
@@ -123,7 +138,7 @@ public class UserAdminLoginModule implements LoginModule, AuthConstants {
        public boolean commit() throws LoginException {
                Authorization authorization = subject
                                .getPrivateCredentials(Authorization.class).iterator().next();
-               if (request != null) {
+               if (request != null && authorization.getName() != null) {
                        request.setAttribute(HttpContext.REMOTE_USER,
                                        authorization.getName());
                        request.setAttribute(HttpContext.AUTHORIZATION, authorization);