How do I use "Remember Me" authentication with Spring Security and LDAP?
Asked Answered
N

2

2

I want to use a Spring Security's "Remember me" with LDAP authentication. LDAP authentication configuration is described here, I've just made some tiny changes. Could you explain to me how can i add "Remember me" in that configuration? Or, may be, you can give me a sample which describes how to do it. Thank you.

Natalienatalina answered 2/3, 2010 at 6:43 Comment(1)
It is quite an involved process to get remember-me working with LDAP. Here is a link to a blog with the entire process outlined: tikalk.com/java/…Foregut
W
4

You really just need to give the remember-me attribute a data-source-ref or a token-repository-ref and a user-service-ref. I saw some other examples that used a voter based access-decision-manager-ref in the http element, but that seemed to void the use-expressions="true." The only thing I don't like about this is having to specify the ldap properties twice.

<beans:import resource="datasource-context.xml"/>

<http use-expressions="true" >
    <intercept-url pattern="/auth/**" access="permitAll" />
    <intercept-url pattern="/admin/**" access="hasRole('MY_ROLE_ADMIN')" />
    <intercept-url pattern="/**" access="isAuthenticated()" />
    <form-login  />
    <logout  />
    <remember-me key="_my_remember_me_key" 
        token-validity-seconds="864000" 
        data-source-ref="dataSource"
        user-service-ref="ldapUserService" />
</http>

<ldap-server id="ldapServerContext" ldif="classpath:users.ldif" root="dc=springframework,dc=org" port="33389" />

<ldap-user-service 
    id="ldapUserService" 
    server-ref="ldapServerContext" 
    user-search-base="ou=people"
    user-search-filter="(uid={0})"
    group-search-base="ou=groups"
    group-role-attribute="cn"
    group-search-filter="(member={0})"
    role-prefix="MY_ROLE_" />

<authentication-manager>
    <ldap-authentication-provider
        server-ref="ldapServerContext"
        user-search-base="ou=people"
        user-search-filter="(uid={0})"
        group-search-base="ou=groups"
        group-role-attribute="cn"
        group-search-filter="(member={0})"
        role-prefix="MY_ROLE_" />
</authentication-manager>
Wattmeter answered 7/12, 2011 at 20:38 Comment(0)
S
3

This link should help:

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.html

Important note:

If you are using an authentication provider which doesn't use a UserDetailsService (for example, the LDAP provider) then it won't work unless you also have a UserDetailsService bean in your application context.

Salve answered 15/3, 2010 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.