【发布时间】:2013-05-22 08:26:21
【问题描述】:
对于一个项目,我尝试使用 Spring Security 3.2 作为基础安全性。因为这个项目已经启动并运行了,所以我已经有了另一个(自己的)安全层。因此,我制作了一个自定义身份验证提供程序来融化安全层。工作正常,直到我还需要进行自定义匿名身份验证 (Spring Security Documentation, chapter 13)。
所以我做了一个自定义过滤器并删除了原始过滤器:
<http request-matcher="regex" use-expressions="true">
<anonymous enabled="false" />
<custom-filter ref="anonymousAuthFilter" position="ANONYMOUS_FILTER"/>
...
</http>
豆子:
<beans:bean id="anonymousAuthFilter" class="own.package.auth.SecurityAnonymousAuthenticationFilter">
<beans:property name="key" value="anonymousKey "/>
<beans:property name="userAttribute" value="anonymous,ROLE_ANONYMOUS"/>
</beans:bean>
还有 Java 类:
public class SecurityAnonymousAuthenticationFilter extends GenericFilterBean implements InitializingBean {
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
logger.info("Entering doFilter method");
//implementation code here
}
//other methods
}
问题是请求服务器时没有调用doFilter方法。但是 init 方法 afterPropertiesSet() 被调用...有谁明白为什么我的 customFilter 没有被触发?
附:我确实在 web.xml 文件中命名了 delegatingFilterProxy,所以这不是问题。
【问题讨论】:
-
尝试将您的自定义过滤器注入到其他位置(例如 after="ANONYMOUS_FILTER")。可能是 anonymous enabled="false" 按过滤器位置工作吗?
-
@MaksymDemidas:谢谢你的评论,不幸的是它没有改变任何东西。
-
你试过删除 anonymous enabled="false" 吗?
-
是的,尝试了 after 两个
都被排除在外
标签: java spring spring-security