如何在spring-security中将自己的注销处理程序添加到LogoutFilter?
谢谢!

最佳答案

以下解决方案对我有用,可能会有所帮助:

  • 扩展SimpleUrlLogoutSuccessHandler或实现LogoutHandler:
    public class LogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
    
       // Just for setting the default target URL
       public LogoutSuccessHandler(String defaultTargetURL) {
            this.setDefaultTargetUrl(defaultTargetURL);
       }
    
       @Override
       public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    
            // do whatever you want
            super.onLogoutSuccess(request, response, authentication);
       }
    }
    
  • 添加到您的Spring Security配置中:
    <security:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" />
    <bean id="logoutSuccessHandler" class="your.package.name.LogoutSuccessHandler" >
        <constructor-arg value="/putInYourDefaultTargetURLhere" />
    </bean>
    
  • 10-08 02:50