ActiveDirectoryLdapAuthenticationProvider custom environment

This change allows to inject custom environment properties for directory
context initialization.

Fixes: gh-2312
This commit is contained in:
Yuri Konotopov
2018-08-16 20:18:27 +04:00
committed by Rob Winch
parent f5701b5fe0
commit 669b0ba583
2 changed files with 41 additions and 1 deletions

View File

@@ -393,6 +393,31 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
}
@Test(expected = IllegalArgumentException.class)
public void setContextEnvironmentPropertiesNull() {
provider.setContextEnvironmentProperties(null);
}
@Test(expected = IllegalArgumentException.class)
public void setContextEnvironmentPropertiesEmpty() {
provider.setContextEnvironmentProperties(new Hashtable<String, Object>());
}
@Test
public void contextEnvironmentPropertiesUsed() throws Exception {
Hashtable<String, Object> env = new Hashtable<>();
env.put("java.naming.ldap.factory.socket", "unknown.package.NonExistingSocketFactory");
provider.setContextEnvironmentProperties(env);
try {
provider.authenticate(joe);
}
catch (org.springframework.ldap.CommunicationException expected) {
assertThat(expected.getCause()).isNotInstanceOf(ClassNotFoundException.class);
}
}
ContextFactory createContextFactoryThrowing(final NamingException e) {
return new ContextFactory() {
@Override