java - Spring Security - 两个独立的身份验证信息源

标签 java spring-security

我的 Spring Security 基于表单的登录当前包含一个表单和默认的 LdapAuthenticationProvider,我能够正确进行身份验证。 但有一个新的要求来检查用户是否已启用。此信息位于数据库而不是 LDAP 中。那么我该怎么做呢?

我是否应该考虑使用 AbstractAuthenticationProcessingFilter 并在 successAuthentication 方法中执行额外检查

或者有更好的方法来做到这一点。

最佳答案

我想说,扩展UsernamePasswordAuthenticationFilter并覆盖attemptAuthentication()是一个好方法。在 attemptAuthentication() 中,您可以检查数据库数据和 LDAP 数据。您可以使用 UserDetailsS​​ervice 加载用户信息,例如 this .

另一种方法是(正如您自己建议的那样)扩展 AbstractAuthenticationProcessingFilter 并在 FORM_LOGIN 过滤器之后运行过滤器,如下所示:

<http ...>
    ...
    <custom-filter after="FORM_LOGIN_FILTER" ref="myAuthenticationProcessingFilter" />
</http>

一个好主意可能是为 LDAP 和 DB 身份验证创建 2 个单独的过滤器,并一个接一个地运行。这样您就可以根据需要关闭其中任何一个。

This spring 文档的一部分将帮助您自定义过滤器。

关于java - Spring Security - 两个独立的身份验证信息源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6438093/

相关文章:

java - Spring Security 定义自定义匿名过滤器

java - 使用媒体播放器播放音频文件时出现问题

java - Scanner 类的 nextInt() 方法不会在 while 循环中再次要求我输入?

java - OpenSaml3 文档

spring-mvc - 创建名称为 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration' : 的 bean 时出错

spring-security - 运行 JUnit 测试时,Spring Security 不调用我的自定义身份验证过滤器

java - 验证在eclipse中做什么?

java - Apache Shiro 是否支持 bCrypt?

java - Firefox Webdriver 无法使用扩展启动

java - 为什么我的项目需要使用 JavaConfig 的 Spring Security 的 applicationContext.xml