2014-06-23 40 views
0

我们正试图在我们的应用程序中实现Spring安全性。我们正在扩展RememberMeAuthenticationFilter。但麻烦的是我们的应用程序控制器在RememberMeAuthenticationFilter之前被调用。 有没有办法强制在应用程序控制器之前调用RememberMeAuthenticationFilter? 以下是我的配置。在调试模式下,我可以看到FilterChainProxy.VirtualFilterChain有两组过滤器 - 原始过滤器和附加过滤器。原始过滤器具有springSecurityFilterChain,但它不调用自定义的RememberMeAuthenticationFilter。另外的过滤器有RememberMeAuthenticationFilter。控制器在原始过滤器末尾通过DispatcherServlet调用。在定制之前调用应用程序控制器RememberMeAuthenticationFilter

的web.xml

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

弹簧安全的context.xml

<http use-expressions="true" auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint" create-session="ifRequired" > 
<long list of intercept-url here> 
    <intercept-url pattern="/**" access="permitAll" requires-channel="any"/> 



    <custom-filter ref="rememberMeProcessingFilter" position="REMEMBER_ME_FILTER" /> 
     <custom-filter ref="authenticationProcessingFilter" position="FORM_LOGIN_FILTER" /> 


</http> 



<beans:bean id="rememberMeProcessingFilter" class="uk.co.and.dealofday.security.SecurityRememberMeAuthenticationFilter"> 
    <beans:property name="authenticationManager" ref="authenticationManager" /> 
    <beans:property name="rememberMeServices" ref="rememberMeServices" /> 
</beans:bean> 



<beans:bean id="authenticationProcessingFilter" class="uk.co.and.dealofday.security.SecurityUsernamePasswordAuthenticationFilter"> 
    <beans:property name="authenticationManager" ref="authenticationManager" /> 
    <beans:property name="rememberMeServices" ref="rememberMeServices" /> 
    <beans:property name="userService" ref="userService"/> 
    <beans:property name="securityHelper" ref="securityHelper" /> 
</beans:bean> 
+0

它应该叫,因为?没有安全的URL(没有''元素),所以过滤器从不执行。 –

+0

有一长串的拦截网址。我刚刚跳过那部分。 \t \t <禁止访问的处理程序REF = “exceptionResolver”/> \t \t \t <截距-URL图案= “/付款/判定/ *” 访问= “permitAll” 要求沟道=“$ {configurationBean .springSecurityChannel}“/> \t

+0

你刚开始没有提到:)。过滤器应该总是在servlet之前执行(因此也是控制器)。如果没有,你的配置有什么问题。 –

回答

-1

声明自定义remember过滤后的自定义过滤器authentication

<custom-filter ref="authenticationProcessingFilter" position="FORM_LOGIN_FILTER" /> 
<custom-filter ref="rememberMeProcessingFilter" position="REMEMBER_ME_FILTER" /> 
相关问题