Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可以实现 logout吗? #7

Closed
Mryemaozi opened this issue Jun 13, 2018 · 3 comments
Closed

可以实现 logout吗? #7

Mryemaozi opened this issue Jun 13, 2018 · 3 comments

Comments

@Mryemaozi
Copy link

可以实现 logout吗? 就是 使之前的authorization失效!!!

@longfeizheng
Copy link
Owner

也可以指定AppLogoutSuccessHandler

+@Slf4j
 public class AppLogoutSuccessHandler implements LogoutSuccessHandler {
 
     @Autowired
     private SessionRegistry sessionRegistry;
 
     @Override
     public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
         if (authentication != null && authentication.getDetails() != null) {
             removeAuthSession(authentication, sessionRegistry);
             httpServletRequest.getSession().invalidate();
             httpServletResponse.sendRedirect("login.html?logout");
         }
     }
 
     private void removeAuthSession(Authentication authentication, SessionRegistry sessionRegistry) {
         List<SessionInformation> sessions = sessionRegistry.getAllSessions(authentication.getPrincipal(), false);
         if (sessions.size() > 0) { // there is only 1 session allowed
             log.debug("removing session {} from registry", sessions.get(0).getSessionId());
             sessionRegistry.removeSessionInformation(sessions.get(0).getSessionId());
         }
     }
 }

@Mryemaozi
Copy link
Author

谢谢哈!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants