對於一個項目,我嘗試使用Spring Security 3.2作爲基本安全。因爲這個項目已經啓動並且正在運行,我已經有了其他(自己的)安全層。因此,我做了一個自定義身份驗證提供程序來融合安全層。工作正常,直到我還需要進行自定義匿名身份驗證(Spring Security Documentation, chapter 13)。自定義身份驗證過濾器Spring Security 3.2
所以我做了一個自定義過濾器和刪除的一部開拓創新的過濾器:
<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>
和Te的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沒有被解僱?
P.S.我確實在web.xml文件中命名了delegatingFilterProxy,所以這不是問題。
嘗試將自定義過濾器注入某個其他位置(例如** after =「ANONYMOUS_FILTER」**)。可能是** anonymous enabled =「false」**通過過濾器位置工作? –
@MaksymDemidas:Thx的評論,不幸的是它不會改變任何東西。 –
你試過刪除** anonymous enabled =「false」**? –