Spring LDAP异常 - 未注册UserDetailsS​​ervice

时间:2011-06-18 23:18:41

标签: spring-security spring-ldap

我正在尝试为JSF网站使用Spring Security 3.0.2 LDAP身份验证。当我在applicationContext-security.xml中使用以下配置时,我得到了这个异常 - org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices的bean的错误# 0':bean的初始化失败;嵌套异常是org.springframework.context.ApplicationContextException:没有注册UserDetailsS​​ervice。

<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="" />

我刚刚进行了实验,发现添加以下内容可以解决问题。

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

但我在Spring LDAP documentation找不到对此的引用。如果我不添加此内容,为什么会出现上述异常?我对这种解决方法不满意,因为我需要在两个地方编写user-search-filter属性。

PS :我已查看Spring Security LDAP - No UserDetailsService registered。异常是不同的,我猜Spring Security版本也不同。

1 个答案:

答案 0 :(得分:9)

我怀疑您稍后在安全上下文中设置了<remember-me/>。根据文件: http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#remember-me

  

如果您使用的是无法使用的身份验证提供程序   UserDetailsS​​ervice(例如,LDAP提供程序)然后它不会工作   除非您的应用程序中还有一个UserDetailsS​​ervice bean   上下文。