[英]Spring security and custom AuthenticationFilter with Spring boot
[英]Custom authenticationFilter Spring Security 3.2
對於一個項目,我嘗試使用Spring Security 3.2作為基本安全性。 因為這個項目已經啟動並運行,所以我已經擁有了另一個(自己的)安全層。 因此,我制作了一個自定義身份驗證提供程序來融化安全層。 工作正常,直到我還需要進行自定義匿名身份驗證( Spring Security Documentation,第13章 )。
所以我做了一個自定義過濾器並刪除了orignal過濾器:
<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沒有被觸發?
PS我確實在web.xml文件中命名了delegatingFilterProxy,所以這不是問題。
由於ANONYMOUS_FILTER
是與名稱空間相關的過濾器。 您必須避免引用特定過濾器psoition的任何名稱空間標記:
<http auto-config='false' request-matcher="regex" use-expressions="true">
<custom-filter ref="anonymousAuthFilter" position="ANONYMOUS_FILTER"/>
...
</http>
有關進一步參考,請參閱2.3.5節中的Spring安全性文檔: http : //static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html
編輯:並確保保留<anonymous-enabled=false/>
標記。
編輯2:糾正了我的回答。 這種配置應該有效。 如果沒有,那么我們需要開始查看更大的圖片並且您必須發布更多應用,從完整配置開始。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.