欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

9、spring security拦截器之LogoutFilter

程序员文章站 2024-03-19 15:10:46
...

LogoutFilter:注销过滤器,默认的url是logout

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
      throws IOException, ServletException {
   HttpServletRequest request = (HttpServletRequest) req;
   HttpServletResponse response = (HttpServletResponse) res;
   //1、检测是否是注销的url,默认值是/logout
   if (requiresLogout(request, response)) {
      Authentication auth = SecurityContextHolder.getContext().getAuthentication();

      if (logger.isDebugEnabled()) {
         logger.debug("Logging out user '" + auth
               + "' and transferring to logout destination");
      }
      //2、执行注销操作
      this.handler.logout(request, response, auth);
      //3、注销成功后的操作
      logoutSuccessHandler.onLogoutSuccess(request, response, auth);

      return;
   }

   chain.doFilter(request, response);
}