5

我正在尝试对 JSF 网站使用 Spring Security 3.0.2 LDAP 身份验证。当我在 applicationContext-security.xml 中使用以下配置时,我得到了这个异常 - org.springframework.beans.factory.BeanCreationException: Error Creating bean with name 'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0': bean初始化失败;嵌套异常是 org.springframework.context.ApplicationContextException: No 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 文档中找不到对此的引用。如果我不添加这个,为什么会出现上述异常?我对这种解决方法不满意,因为我需要在两个地方编写 user-search-filter 属性。

PS:我已经检查了Spring Security LDAP-No UserDetailsS​​ervice 注册。那里的例外是不同的,我猜 Spring Security 版本也不同。

4

1 回答 1

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,否则它将无法工作。

于 2012-05-07T21:24:22.860 回答