2
votes

Can I have a Spring Security project where I authenticate against LDAP and set authorities to the authenticated user against a Data Base?

Thanks!

2
Welcome to Stack Overflow! We encourage you to research your questions. If you've tried something already, please add it to the question - if not, research and attempt your question first, and then come back. - user647772

2 Answers

1
votes

I've achieved the solution for this, answer cames above:

<authentication-manager >
    <authentication-provider ref="ldapAuthProvider" />            
</authentication-manager>


<beans:bean id="contextSource"
    class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">        
<beans:constructor-arg value="ldap://IP:port/...."/>

</beans:bean>

<beans:bean id="ldapAuthProvider"
   class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <beans:constructor-arg>
    <beans:bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
    <beans:constructor-arg ref="contextSource"/>
    <beans:property name="userSearch" ref="ldapUserSearch" />
    </beans:bean>
    </beans:constructor-arg>
    <beans:constructor-arg>
    <beans:bean
    class="prpa.athos.security.listener.MyLDAPAuthorities">
    </beans:bean>
    </beans:constructor-arg>
    </beans:bean>
    <beans:bean id="authenticationSuccessListener"   
    class="prpa.athos.security.listener.AuthenticationSuccessListener">
    </beans:bean>        
    <beans:bean id="ldapUserSearch"   
    class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
    <beans:constructor-arg index="0" value=""/>
    <beans:constructor-arg index="1" value="(uid={0})"/>
    <beans:constructor-arg index="2" ref="contextSource" />
    </beans:bean>

On the class MyLDAPAuthorities I implements the classe LdapAuthoritiesPopulator getting authorities form database.

0
votes

Yes, you will need a LdapBindAuthenticator and a DAO-based AuthoritiesPopulator.