|
@@ -107,6 +107,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
|
|
private final String url;
|
|
private final String url;
|
|
private boolean convertSubErrorCodesToExceptions;
|
|
private boolean convertSubErrorCodesToExceptions;
|
|
private String searchFilter = "(&(objectClass=user)(userPrincipalName={0}))";
|
|
private String searchFilter = "(&(objectClass=user)(userPrincipalName={0}))";
|
|
|
|
+ private Hashtable<String, Object> contextEnvironmentProperties = null;
|
|
|
|
|
|
// Only used to allow tests to substitute a mock LdapContext
|
|
// Only used to allow tests to substitute a mock LdapContext
|
|
ContextFactory contextFactory = new ContextFactory();
|
|
ContextFactory contextFactory = new ContextFactory();
|
|
@@ -190,7 +191,7 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
|
|
// TODO. add DNS lookup based on domain
|
|
// TODO. add DNS lookup based on domain
|
|
final String bindUrl = url;
|
|
final String bindUrl = url;
|
|
|
|
|
|
- Hashtable<String, String> env = new Hashtable<>();
|
|
|
|
|
|
+ Hashtable<String, Object> env = new Hashtable<>();
|
|
env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
|
env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
|
String bindPrincipal = createBindPrincipal(username);
|
|
String bindPrincipal = createBindPrincipal(username);
|
|
env.put(Context.SECURITY_PRINCIPAL, bindPrincipal);
|
|
env.put(Context.SECURITY_PRINCIPAL, bindPrincipal);
|
|
@@ -199,6 +200,10 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
|
|
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
|
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
|
env.put(Context.OBJECT_FACTORIES, DefaultDirObjectFactory.class.getName());
|
|
env.put(Context.OBJECT_FACTORIES, DefaultDirObjectFactory.class.getName());
|
|
|
|
|
|
|
|
+ if(contextEnvironmentProperties != null) {
|
|
|
|
+ env.putAll(contextEnvironmentProperties);
|
|
|
|
+ }
|
|
|
|
+
|
|
try {
|
|
try {
|
|
return contextFactory.createContext(env);
|
|
return contextFactory.createContext(env);
|
|
}
|
|
}
|
|
@@ -398,6 +403,16 @@ public final class ActiveDirectoryLdapAuthenticationProvider extends
|
|
this.searchFilter = searchFilter;
|
|
this.searchFilter = searchFilter;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Allows a custom environment properties to be used to create initial LDAP context.
|
|
|
|
+ *
|
|
|
|
+ * @param contextFactory
|
|
|
|
+ */
|
|
|
|
+ public void setContextEnvironmentProperties(Hashtable<String, Object> environment) {
|
|
|
|
+ Assert.notEmpty(environment, "environment must not be empty");
|
|
|
|
+ this.contextEnvironmentProperties = new Hashtable<>(environment);
|
|
|
|
+ }
|
|
|
|
+
|
|
static class ContextFactory {
|
|
static class ContextFactory {
|
|
DirContext createContext(Hashtable<?, ?> env) throws NamingException {
|
|
DirContext createContext(Hashtable<?, ?> env) throws NamingException {
|
|
return new InitialLdapContext(env, null);
|
|
return new InitialLdapContext(env, null);
|