Polish ActiveDirectoryLdapAuthenticationProvider custom environment

Fixes: gh-5674
This commit is contained in:
Rob Winch 2018-08-21 12:05:52 -05:00
parent 669b0ba583
commit ec01657625
1 changed files with 4 additions and 7 deletions

View File

@ -107,7 +107,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
private final String url;
private boolean convertSubErrorCodesToExceptions;
private String searchFilter = "(&(objectClass=user)(userPrincipalName={0}))";
private Hashtable<String, Object> contextEnvironmentProperties = null;
private Map<String, Object> contextEnvironmentProperties = new HashMap<>();
// Only used to allow tests to substitute a mock LdapContext
ContextFactory contextFactory = new ContextFactory();
@ -199,10 +199,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.OBJECT_FACTORIES, DefaultDirObjectFactory.class.getName());
if(contextEnvironmentProperties != null) {
env.putAll(contextEnvironmentProperties);
}
env.putAll(this.contextEnvironmentProperties);
try {
return contextFactory.createContext(env);
@ -406,9 +403,9 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
/**
* Allows a custom environment properties to be used to create initial LDAP context.
*
* @param contextFactory
* @param environment the additional environment parameters to use when creating the LDAP Context
*/
public void setContextEnvironmentProperties(Hashtable<String, Object> environment) {
public void setContextEnvironmentProperties(Map<String, Object> environment) {
Assert.notEmpty(environment, "environment must not be empty");
this.contextEnvironmentProperties = new Hashtable<>(environment);
}