Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring LDAP exception - No UserDetailsService registered

I am trying to use Spring Security 3.0.2 LDAP authentication for a JSF website. When I use the below configuration in applicationContext-security.xml I get this exception - org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0': Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextException: No UserDetailsService registered.

<authentication-manager>
    <ldap-authentication-provider
        user-search-filter="(uid={0})" user-search-base="ou=users,ou=system"
        group-search-base="ou=groups,ou=system">
    </ldap-authentication-provider>
</authentication-manager>

<ldap-server id="ldapServer" url="ldap://localhost:10389"
    root="" />

I just experimented and found that adding the below makes things work.

<ldap-user-service server-ref="ldapServer" user-search-filter="(uid={0})" />

But I could not find references to this in the Spring LDAP documentation. Why do I get the above exception if I do not add this? I am not happy with this workaround as I need to write user-search-filter attribute at two places.

PS: I have checked Spring Security LDAP - No UserDetailsService registered. There the exception is different and I guess the Spring Security version is different as well.

like image 313
Cracker Avatar asked Jun 18 '11 23:06

Cracker


1 Answers

I suspect you have <remember-me/> set later in the security context. As per documentation: http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#remember-me

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.

like image 59
Tomasz Avatar answered Oct 04 '22 04:10

Tomasz