java - How do I use a custom authorities populator with Spring Security and the ActiveDirectoryLdapAuthenticationProvider? -
i've connected active directory through ldap authenticate, , following in ldap.xml i've called custom authorities populator:
<bean id="ldapauthenticationprovider" class="org.springframework.security.ldap.authentication.ldapauthenticationprovider"> <constructor-arg ref="ldapbindauthenticator"/> <constructor-arg ref="ldapauthoritiespopulator"/> </bean> <bean id="ldapbindauthenticator" class="org.springframework.security.ldap.authentication.bindauthenticator"> <constructor-arg ref="ldapserver"/> <property name="usersearch" ref="ldapsearch"/> </bean> <bean id="ldapsearch" class="org.springframework.security.ldap.search.filterbasedldapusersearch"> <constructor-arg value="cn=users"/> <constructor-arg value="(samaccountname={0})"/> <constructor-arg ref="ldapserver"/> </bean> <bean id="ldapauthoritiespopulator" class="my.project.package.activedirectoryldapauthoritiespopulator"/> <bean id="ldapserver" class="org.springframework.security.ldap.defaultspringsecuritycontextsource"> <constructor-arg value="ldap://192.168.0.2/dc=test,dc=server"/> <property name="userdn" value="ldap@test.server"/> <property name="password" value="ldap"/> <property name="baseenvironmentproperties"> <map> <entry key="java.naming.referral"> <value>follow</value> </entry> </map> </property> </bean>
this works fine, , can ascertain user's authorization based on group membership, rather through built-in active directory ldap authentication provider:
<bean id="ldapauthenticationprovider" class="org.springframework.security.ldap.authentication.ad.activedirectoryldapauthenticationprovider"> <constructor-arg value="test.server"/> <constructor-arg value="ldap://192.168.0.2:389"/> <property name="convertsuberrorcodestoexceptions" value="true"/> </bean>
the problem above custom authorities populator (obviously) not called, while can authenticate users (which works above), left without groups (which need determine authorization).
i feel simple question, life of me cannot find answer here or anywhere else. have extend activedirectoryldapauthenticationprovider class, , call authorities populator there?
(thanks site has given me several years running; effectiveness of site can gauged fact i've bothered create account, , first question. in advance help.)
spring's activedirectoryldapauthenticationprovider class final
, real option (i'll entertain better ones if there takers) fork class. copied , pasted contents, refactored slightly, , removed final
designation. then, created separate subclass of forked class, overriding loaduserauthorities()
method, , added own code building permissions mask.
i able edit ldap.xml
file follows:
<bean id="ldapauthenticationprovider" class="my.project.package.overrideactivedirectoryldapauthenticationprovider"> <constructor-arg value="test.server"/> <constructor-arg value="ldap://192.168.0.2:389"/> <property name="convertsuberrorcodestoexceptions" value="true"/> </bean>
for other n00bs me, subclass looks this:
public class overrideactivedirectoryldapauthenticationprovider extends testactivedirectoryldapauthenticationprovider { //my assignments public overrideactivedirectoryldapauthenticationprovider(string domain, string url) { super(domain, url); } @override protected collection<? extends grantedauthority> loaduserauthorities(dircontextoperations userdata, string username, string password) { //original code own additions //in case, injected code for(group : groups) loop }
worked charm.
much zagyi assistance.
Comments
Post a Comment