java – spring安全自定义注销处理程序

如何在弹簧安全性中将自己的注销处理程序添加到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:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" />
<bean id="logoutSuccessHandler" class="your.package.name.LogoutSuccessHandler" >
    <constructor-arg value="/putInYourDefaultTargetURLhere" />
</bean>

转载注明原文:java – spring安全自定义注销处理程序 - 代码日志