【问题标题】:Does the spring security filterchain always run twice for Asynchronous requests?spring 安全过滤器链是否总是为异步请求运行两次?
【发布时间】:2016-09-05 10:21:46
【问题描述】:

据我所知,对于@Async 请求,spring 安全过滤器链在每个请求中运行两次,因为它在入站请求线程上运行,然后被传递给在不同线程上运行的异步代码,然后当它尝试写入响应线程,安全过滤器链再次运行。我相信这是由于使用 ThreadLocal 来存储安全上下文。

我能够成功地将安全上下文传递到异步代码中,问题是每当我尝试编写响应时,过滤器链会再次运行。

我遇到了与此处描述的类似情况:

http://forum.spring.io/forum/spring-projects/security/747178-security-filter-chain-is-always-calling-authenticationmanager-twice-per-request

这是我们在使用 Spring Security 时应该考虑的简单预期行为,还是我缺少的配置会阻止过滤器链的第二次执行?

【问题讨论】:

    标签: spring asynchronous spring-security


    【解决方案1】:

    在这里得到了答案:https://github.com/spring-projects/spring-security-oauth/issues/736

    显然解决方法是configure security.filter-dispatcher-types=REQUEST, ERROR

    【讨论】:

      【解决方案2】:

      设置属性spring.security.filter.dispatcher-types=REQUEST,ERROR。 Spring 不会对从异步上下文调度的调用应用过滤器。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-20
        • 2013-05-25
        • 2016-05-07
        • 1970-01-01
        • 2012-06-03
        • 1970-01-01
        • 1970-01-01
        • 2023-02-04
        相关资源
        最近更新 更多