spring security 自定义注销处理程序 [英] spring security customize logout handler

查看:42
本文介绍了spring security 自定义注销处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I add my own logout handler to LogoutFilter in spring-security ? Thanks!

推荐答案

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

The following solution works for me and may be helpful:

  1. 扩展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 安全配置:

  • Add to your Spring Security Configuration:

    <security:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" />
    <bean id="logoutSuccessHandler" class="your.package.name.LogoutSuccessHandler" >
        <constructor-arg value="/putInYourDefaultTargetURLhere" />
    </bean>
    

  • 这篇关于spring security 自定义注销处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆