So, trying another direction, I tried to remove the userDNPattern and just use a userSearch. I changed my configuration to:
Code:
<beans:bean id="bindAuthenticator" class="org.springframework.security.ldap.authentication.BindAuthenticator">
<beans:constructor-arg ref="contextSource" />
<beans:property name="userSearch" ref="userSearch"/>
</beans:bean>
<beans:bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<beans:constructor-arg>
<beans:value>DC=domain,DC=subdomain,DC=corp</beans:value>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:value>(sAMAccountName={0})</beans:value>
</beans:constructor-arg>
<beans:constructor-arg ref="contextSource" />
<beans:property name="searchSubtree">
<beans:value>true</beans:value>
</beans:property>
</beans:bean>
Now I am getting an error that basically I think is telling me that I can't perform this user search becuase anonymous user searches are not allowed.
Reason: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.
NamingException: [LDAP: error code 1 - 00000000: LdapErr: DSID-0C090627,
comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece];
remaining name 'DC=domain,DC=subdomain,DC=corp'
Is this the case, or could I simply have the searchBase incorrect?
What puzzles me about the existing implementation is that I can't see how what I am trying to do is different.
In the existing implementation, the code basically does a JNDI lookup of the user account using a search:
Look up the context:
Code:
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, getURL());
env.put(Context.SECURITY_AUTHENTICATION, securityAuthenticationType);
env.put(Context.SECURITY_PRINCIPAL, "domain\\" + getUsername());
env.put(Context.SECURITY_CREDENTIALS, getPassword());
Perform the search:
Code:
// Filter = "(sAMAccountName=" + username + ")"
ctx = new InitialDirContext(env);
results = ctx.search(ldapSearch.getDn()
, ldapSearch.getFilter()
, ldapSearch.getControls());
Thanks in advance for any replies!