How to manually log out a user with spring security?

后端 未结 9 1290
情话喂你
情话喂你 2020-11-29 21:06

Probably the answer is simple: How can I manually logout the currently logged in user in spring security? Is it sufficient to call:

SecurityContextHolder.get         


        
9条回答
  •  一整个雨季
    2020-11-29 21:29

    You can also use SessionRegistry as:

    sessionRegistry.getSessionInformation(sessionId).expireNow();
    

    If you want to force logout in all sessions of a user then use getAllSessions method and call expireNow of each session information.

    Edit
    This requires ConcurrentSessionFilter (or any other filter in the chain), that checks SessionInformation and calls all logout handlers and then do redirect.

提交回复
热议问题