ldap Context accountMapping

This commit is contained in:
MaxKey
2022-02-19 09:04:52 +08:00
parent ee8b7536e1
commit 2fe1f9f612
11 changed files with 68 additions and 8 deletions

View File

@@ -25,5 +25,6 @@ package org.maxkey.authn.realm;
public interface IAuthenticationServer {
public boolean authenticate(String username, String password);
public boolean isMapping();
}

View File

@@ -36,6 +36,8 @@ public final class ActiveDirectoryServer implements IAuthenticationServer {
String filter;
boolean mapping;
/* (non-Javadoc)
* @see com.connsec.web.authentication.realm.IAuthenticationServer#authenticate(java.lang.String, java.lang.String)
*/
@@ -75,4 +77,11 @@ public final class ActiveDirectoryServer implements IAuthenticationServer {
this.filter = filter;
}
public boolean isMapping() {
return mapping;
}
public void setMapping(boolean mapping) {
this.mapping = mapping;
}
}

View File

@@ -61,8 +61,12 @@ public class LdapAuthenticationRealm extends AbstractAuthenticationRealm{
public boolean passwordMatches(UserInfo userInfo, String password) {
boolean isAuthenticated=false;
for (final IAuthenticationServer ldapServer : this.ldapServers) {
_logger.debug("Attempting to authenticate {} at {}", userInfo.getUsername(), ldapServer);
isAuthenticated= ldapServer.authenticate(userInfo.getUsername(), password);
String username = userInfo.getUsername();
if(ldapServer.isMapping()) {//if ldap Context accountMapping equals YES
username = userInfo.getWindowsAccount();
}
_logger.debug("Attempting to authenticate {} at {}", username, ldapServer);
isAuthenticated= ldapServer.authenticate(username, password);
if (isAuthenticated ) {
return true;
}

View File

@@ -60,6 +60,9 @@ public class LdapAuthenticationRealmService {
ldapContext.getCredentials(),
ldapContext.getMsadDomain());
ldapServer.setActiveDirectoryUtils(ldapUtils);
if(ldapContext.getAccountMapping().equalsIgnoreCase("YES")) {
ldapServer.setMapping(true);
}
ldapAuthenticationServers.add(ldapServer);
}else {
@@ -71,6 +74,9 @@ public class LdapAuthenticationRealmService {
ldapContext.getBasedn());
standardLdapServer.setLdapUtils(ldapUtils);
standardLdapServer.setFilterAttribute(ldapContext.getFilters());
if(ldapContext.getAccountMapping().equalsIgnoreCase("YES")) {
standardLdapServer.setMapping(true);
}
ldapAuthenticationServers.add(standardLdapServer);
}
}

View File

@@ -41,6 +41,8 @@ public final class StandardLdapServer implements IAuthenticationServer {
String filterAttribute;
boolean mapping;
/* (non-Javadoc)
* @see com.connsec.web.authentication.realm.IAuthenticationServer#authenticate(java.lang.String, java.lang.String)
*/
@@ -95,4 +97,12 @@ public final class StandardLdapServer implements IAuthenticationServer {
this.filterAttribute = filterAttribute;
}
public boolean isMapping() {
return mapping;
}
public void setMapping(boolean mapping) {
this.mapping = mapping;
}
}