
Originally Posted by
havenn
Overriding/Customising the DefaultLdapAuthoritiesPopulator and BindAuthenticator worked for me. Those classes encapsulate the ldapTemplate. Because I am using Spring LDAP 1.3.0 I set it to ignore the partial result exception by calling ldapTemplate.setIgnorePartialResultException(true) ;
Yes, I did this for use of the LDAPTemplate:
Code:
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
<property name="ignorePartialResultException" value="true"/>
</bean>
But for simple authentication against AD you should not have to set that or even have that bean present. I don't use that bean for authentication - I use it for LDAP searches/lookups in my AD user management services layer (actually haven't used it for anything but testing yet) - the basic Spring Sec. setup I use without that template works for me (I am sure an LDAPTemplate is used somewhere under the covers but I use nothing but the Spring Security layer for authentication and no problems with partial results (debug log warnings aside) - IIRC there is something in various docs about this being the default?
But back to the original question:
The hardest problem I had was getting config to work with our AD instance. Once I did that I was fine - but then I don't think we have any 'referrals'?
Anyway, I had similar problems. What I did was start from the root:
Code:
<bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0">
<value>DC=example,DC=com</value> <!-- Start at the root -->
<!-- <value>OU=WesternOrg,DC=example,DC=com</value>
- previous value, we don't need to start there, we can start at the root instead and get everybody. Yahoo!
-->
</constructor-arg>
<constructor-arg index="1">
<value>sAMAccountName={0}</value>
</constructor-arg>
<constructor-arg index="2">
<ref local="securityContextSource" />
</constructor-arg>
<property name="searchSubtree" value="true" />
</bean>
The other key part was the populator:
Code:
<bean id="ldapAuthoritiesPopulator" class="org.springframework.security.ldap.populator.DefaultLdapAuthoritiesPopulator">
<constructor-arg index="0">
<ref local="securityContextSource" />
</constructor-arg>
<constructor-arg index="1">
<value>CN=TheCNWhereTheGroupsAreKept,DC=example,DC=com</value>
</constructor-arg>
<property name="searchSubtree" value="true"/>
</bean>
For us, the 'TheCNWhereTheGroupsAreKept' is "BuiltIn" off the root ("example.com"). I think "BuiltIn" may be a default AD entry where groups are kept? I am still learning - maybe that is obvious to AD people? Once I got those two settings correct everything kind of fell into place for me. Hope this helps.