Introduce CMS event bus and use it in UI.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / SingleUserLoginModule.java
index 240564f9ec894b809c956829e01fc653dc8d0942..956987d52ddde586d7b9ff8cf370e1608dc8b72a 100644 (file)
@@ -12,18 +12,17 @@ import javax.security.auth.kerberos.KerberosPrincipal;
 import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 import javax.security.auth.x500.X500Principal;
-import javax.servlet.http.HttpServletRequest;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.naming.LdapAttrs;
-import org.argeo.osgi.useradmin.IpaUtils;
+import org.argeo.api.cms.CmsLog;
+import org.argeo.cms.internal.runtime.CmsContextImpl;
 import org.argeo.osgi.useradmin.OsUserUtils;
+import org.argeo.util.directory.ldap.IpaUtils;
+import org.argeo.util.naming.LdapAttrs;
 import org.osgi.service.useradmin.Authorization;
 
 /** Login module for when the system is owned by a single user. */
 public class SingleUserLoginModule implements LoginModule {
-       private final static Log log = LogFactory.getLog(SingleUserLoginModule.class);
+       private final static CmsLog log = CmsLog.getLog(SingleUserLoginModule.class);
 
        private Subject subject;
        private Map<String, Object> sharedState = null;
@@ -56,19 +55,13 @@ public class SingleUserLoginModule implements LoginModule {
                        Object username = sharedState.get(CmsAuthUtils.SHARED_STATE_NAME);
                        if (username == null)
                                throw new LoginException("No username available");
-                       String hostname;
-                       try {
-                               hostname = InetAddress.getLocalHost().getHostName();
-                       } catch (UnknownHostException e) {
-                               log.warn("Using localhost as hostname", e);
-                               hostname = "localhost";
-                       }
+                       String hostname = CmsContextImpl.getCmsContext().getCmsState().getHostname();
                        String baseDn = ("." + hostname).replaceAll("\\.", ",dc=");
                        X500Principal principal = new X500Principal(LdapAttrs.uid + "=" + username + baseDn);
                        authorizationName = principal.getName();
                }
 
-               HttpServletRequest request = (HttpServletRequest) sharedState.get(CmsAuthUtils.SHARED_STATE_HTTP_REQUEST);
+               RemoteAuthRequest request = (RemoteAuthRequest) sharedState.get(CmsAuthUtils.SHARED_STATE_HTTP_REQUEST);
                Locale locale = Locale.getDefault();
                if (request != null)
                        locale = request.getLocale();
@@ -76,8 +69,8 @@ public class SingleUserLoginModule implements LoginModule {
                        locale = Locale.getDefault();
                Authorization authorization = new SingleUserAuthorization(authorizationName);
                CmsAuthUtils.addAuthorization(subject, authorization);
-               
-               // Add standard Java OS login 
+
+               // Add standard Java OS login
                OsUserUtils.loginAsSystemUser(subject);
 
                // additional principals (must be after Authorization registration)