spring security customize logout handler

前端 未结 4 2118
谎友^
谎友^ 2020-12-15 05:25

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

4条回答
  •  半阙折子戏
    2020-12-15 05:36

    The following solution works for me and may be helpful:

    1. Extend the SimpleUrlLogoutSuccessHandler or implement the 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. Add to your Spring Security Configuration:

      
      
          
      
      

提交回复
热议问题