Introduce CMS event bus and use it in UI.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / auth / SingleUserLoginModule.java
index 08380ac5a227cd165756e9b430cec4e6fd9c5e6d..956987d52ddde586d7b9ff8cf370e1608dc8b72a 100644 (file)
@@ -14,8 +14,9 @@ import javax.security.auth.spi.LoginModule;
 import javax.security.auth.x500.X500Principal;
 
 import org.argeo.api.cms.CmsLog;
-import org.argeo.osgi.useradmin.IpaUtils;
+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;
 
@@ -54,13 +55,7 @@ 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();
@@ -74,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)