]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/auth/IdentLoginModule.java
Refactor CMS life cycle.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / IdentLoginModule.java
index b4c49b285ed56ebe6e3ea729a7f6d61de67595d4..097e588e43737e83f09e6633a5309dcc8bdf25c4 100644 (file)
@@ -9,24 +9,22 @@ import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
-import javax.servlet.http.HttpServletRequest;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.cms.internal.kernel.Activator;
-import org.argeo.ident.IdentClient;
+import org.argeo.api.cms.CmsLog;
+import org.argeo.cms.auth.ident.IdentClient;
+import org.argeo.cms.internal.runtime.CmsStateImpl;
 
+/** Use an ident service to identify. */
 public class IdentLoginModule implements LoginModule {
-       private final static Log log = LogFactory.getLog(IdentLoginModule.class);
+       private final static CmsLog log = CmsLog.getLog(IdentLoginModule.class);
 
-       private Subject subject = null;
        private CallbackHandler callbackHandler = null;
        private Map<String, Object> sharedState = null;
 
+       @SuppressWarnings("unchecked")
        @Override
        public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
                        Map<String, ?> options) {
-               this.subject = subject;
                this.callbackHandler = callbackHandler;
                this.sharedState = (Map<String, Object>) sharedState;
        }
@@ -35,7 +33,7 @@ public class IdentLoginModule implements LoginModule {
        public boolean login() throws LoginException {
                if (callbackHandler == null)
                        return false;
-               HttpRequestCallback httpCallback = new HttpRequestCallback();
+               RemoteAuthCallback httpCallback = new RemoteAuthCallback();
                try {
                        callbackHandler.handle(new Callback[] { httpCallback });
                } catch (IOException e) {
@@ -43,8 +41,10 @@ public class IdentLoginModule implements LoginModule {
                } catch (UnsupportedCallbackException e) {
                        return false;
                }
-               HttpServletRequest request = httpCallback.getRequest();
-               IdentClient identClient = Activator.getIdentClient(request.getRemoteAddr());
+               RemoteAuthRequest request = httpCallback.getRequest();
+               if (request == null)
+                       return false;
+               IdentClient identClient = CmsStateImpl.getIdentClient(request.getRemoteAddr());
                if (identClient == null)
                        return false;
                String identUsername;
@@ -56,7 +56,8 @@ public class IdentLoginModule implements LoginModule {
                }
                if (identUsername != null) {
                        if (log.isDebugEnabled())
-                               log.debug("Ident username: " + identUsername);
+                               log.debug("Ident username: " + identUsername + " (local port: " + request.getLocalPort()
+                                               + ", remote port: " + request.getRemotePort() + ")");
                        sharedState.put(CmsAuthUtils.SHARED_STATE_NAME, identUsername);
                        sharedState.put(CmsAuthUtils.SHARED_STATE_REMOTE_ADDR, request.getRemoteAddr());
                        sharedState.put(CmsAuthUtils.SHARED_STATE_REMOTE_PORT, request.getRemotePort());