gpt4 book ai didi

java - Spring 安全自定义注销处理程序

转载 作者:IT老高 更新时间:2023-10-28 13:49:30 25 4
gpt4 key购买 nike

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

最佳答案

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

  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);
    }
    }
  2. 添加到您的 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 安全自定义注销处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3112972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com