mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-15 04:52:09 +08:00
ldap Context accountMapping
This commit is contained in:
@@ -25,5 +25,6 @@ package org.maxkey.authn.realm;
|
||||
public interface IAuthenticationServer {
|
||||
|
||||
public boolean authenticate(String username, String password);
|
||||
|
||||
|
||||
public boolean isMapping();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user