【问题标题】:Custom filter position in spring security弹簧安全中的自定义过滤器位置
【发布时间】:2014-05-30 16:25:05
【问题描述】:

如何在链顶的 Spring Security 链中插入多个自定义过滤器?

我可以使用position="FIRST" 和after="FIRST" 插入一个,但是如何在链的顶部添加两个或三个?如果我尝试多个after="FIRST",我会遇到无法将多个过滤器放在同一位置的冲突错误。

    <custom-filter ref="customExceptionJSONFilter" position="FIRST"/>
    <custom-filter ref="logHeadersFilter" after="FIRST"/>
    <custom-filter ref="thirdCustomFilter" after="FIRST"/>       <---- this causes a conflict

是否有任何基于另一个过滤器的定位方式?或者说“FIRST+1”、“FIRST+2”等?

【问题讨论】:

  • 你可以省略安全命名空间但手动配置spring security。
  • @DirkLachowski - 你能详细说明一下吗?我不确定你的建议是什么。
  • 我现在不在办公室,所以先简短回复一下。您必须手动配置 FilterChainProxy。查看stackoverflow.com/a/22716881/1686330 以获得第一印象。我会回来的,但这需要一段时间。

标签: java spring filter spring-security


【解决方案1】:

最好的方法可能是将要插入的过滤器包装到单个Filter 中。您可以从 Spring Security 中的VirtualFilterChain 复制代码来实现它:https://github.com/spring-projects/spring-security/blob/6be4e3a9fc99d676f367a5e9eed3ea61fbba122c/web/src/main/java/org/springframework/security/web/FilterChainProxy.java#L306

【讨论】:

  • 我意识到了这一点,但希望我缺少一些东西。当我查看org.springframework.security.config.http.SecurityFilters 中的条例FIRST 并看到它被定义为-MAXINT 并且过滤器定义之间允许有100 个点时,我想一定有一种方法可以使用额外的点。就是想不通怎么弄。此外,令我惊讶的是 Spring 没有提供我可以开箱即用的 VirtualFilterChain 的公共形式,因此推测必须有其他东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
  • 2018-11-09
  • 2017-03-18
  • 2017-03-18
相关资源
最近更新 更多