【问题标题】:Cumulative filters in Spring Security 3Spring Security 3 中的累积过滤器
【发布时间】:2011-09-28 05:50:13
【问题描述】:

我需要使用 2 层来保护我的网站。首先是 LDAP 检查,接下来是用户名/密码条目。我已经为这两项检查编写了两个自定义身份验证过滤器。

如果 LDAP 过滤器失败,则应将用户重定向到“拒绝访问”页面,如果用户名/密码失败,则应将用户重定向回登录页面。

如何在我的 config.xml 文件中设置这些过滤器?这是我目前拥有的

<sec:http entry-point-ref="loginAuthenticationEntryPoint"
    auto-config="false" use-expressions="true">
    <sec:intercept-url pattern="/login.htm" access="isAnonymous()" />
    <sec:intercept-url pattern="/*"
        access="hasRole('ROLE_LDAP') and hasRole('ROLE_CRESTA')" />

    <sec:custom-filter ref="ldapAuthenticationFilter"
        before="FORM_LOGIN_FILTER" />
    <sec:custom-filter ref="usernameAuthenticationFilter"
        position="FORM_LOGIN_FILTER" />
</sec:http>

public class LdapAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter

public class CrestaUsernameAuthenticationFilter extends AbstractAuthenticationProcessingFilter

我目前的想法是让每个过滤器添加一个所需的角色,但是当 LDAP 过滤器没有添加这两个角色时,我会立即被拒绝访问。

非常感谢

【问题讨论】:

    标签: java spring-security servlet-filters


    【解决方案1】:

    我认为这种方法行不通,因为一旦您的 LDAP 过滤器成功返回,Spring Security 就会认为用户已完全通过身份验证并跳过用户名/密码过滤器。

    在您的情况下,我将使用标准表单登录安全性,只自定义我的 UserDetailsS​​ervice,这样它就不会只去 Cresta 创建 UserDetails 实例,它也会查询您的 LDAP 服务器以获取用户角色。

    【讨论】:

    • 谢谢,这就是我最终要做的事情
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2013-04-13
    • 2016-04-26
    • 2019-04-13
    相关资源
    最近更新 更多