X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fauth%2FSingleUserLoginModule.java;h=10e091ead0a4953e2236f2ad4860c5d04ba277c2;hb=e75cf778a87f1b2ef7cfc57339ccbf9657282e92;hp=4b36f28abb90f927df087b743f81c09852241319;hpb=a4e2def61f587de89a03037aec2b95c54732ec55;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/auth/SingleUserLoginModule.java b/org.argeo.cms/src/org/argeo/cms/auth/SingleUserLoginModule.java index 4b36f28ab..10e091ead 100644 --- a/org.argeo.cms/src/org/argeo/cms/auth/SingleUserLoginModule.java +++ b/org.argeo.cms/src/org/argeo/cms/auth/SingleUserLoginModule.java @@ -7,6 +7,7 @@ import javax.naming.ldap.LdapName; import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.kerberos.KerberosPrincipal; +import javax.security.auth.login.CredentialException; import javax.security.auth.login.LoginException; import javax.security.auth.spi.LoginModule; import javax.security.auth.x500.X500Principal; @@ -35,8 +36,12 @@ public class SingleUserLoginModule implements LoginModule { @Override public boolean login() throws LoginException { String username = System.getProperty("user.name"); - if (!sharedState.containsKey(CmsAuthUtils.SHARED_STATE_NAME)) - sharedState.put(CmsAuthUtils.SHARED_STATE_NAME, username); + if (sharedState.containsKey(CmsAuthUtils.SHARED_STATE_OS_USERNAME) + && !username.equals(sharedState.get(CmsAuthUtils.SHARED_STATE_OS_USERNAME))) + throw new CredentialException( + "OS username already set with " + sharedState.get(CmsAuthUtils.SHARED_STATE_OS_USERNAME)); + if (!sharedState.containsKey(CmsAuthUtils.SHARED_STATE_OS_USERNAME)) + sharedState.put(CmsAuthUtils.SHARED_STATE_OS_USERNAME, username); return true; } @@ -49,7 +54,7 @@ public class SingleUserLoginModule implements LoginModule { X500Principal principal = new X500Principal(userDn.toString()); authorizationName = principal.getName(); } else { - Object username = sharedState.get(CmsAuthUtils.SHARED_STATE_NAME); + Object username = sharedState.get(CmsAuthUtils.SHARED_STATE_OS_USERNAME); if (username == null) throw new LoginException("No username available"); String hostname = CmsContextImpl.getCmsContext().getCmsState().getHostname();