Rename LDAP enums
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / SingleUserLoginModule.java
index 5d46839e0be753e9ea18cb01bdded345ce788c06..4b36f28abb90f927df087b743f81c09852241319 100644 (file)
@@ -1,7 +1,5 @@
 package org.argeo.cms.auth;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.Locale;
 import java.util.Map;
 
@@ -13,16 +11,15 @@ import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 import javax.security.auth.x500.X500Principal;
 
-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.osgi.useradmin.OsUserUtils;
+import org.argeo.api.acr.ldap.LdapAttr;
+import org.argeo.cms.directory.ldap.IpaUtils;
+import org.argeo.cms.internal.runtime.CmsContextImpl;
+import org.argeo.cms.osgi.useradmin.OsUserUtils;
 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;
@@ -55,19 +52,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);
+                       X500Principal principal = new X500Principal(LdapAttr.uid + "=" + username + baseDn);
                        authorizationName = principal.getName();
                }
 
-               HttpRequest request = (HttpRequest) 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();
@@ -75,8 +66,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)