Issue
Probably the answer is simple: How can I manually logout the currently logged in user in spring security? Is it sufficient to call:
SecurityContextHolder.getContext().getAuthentication().setAuthenticated(false);
?
Solution
In Servlet 3.0 container Spring logout functionality is integrated with servlet and you just invoke logout()
on your HttpServletRequest
. Still need to write valid response content.
According to documentation (Spring 3.2):
The HttpServletRequest.logout() method can be used to log the current user out.
Typically this means that the SecurityContextHolder will be cleared out, the HttpSession will be invalidated, any "Remember Me" authentication will be cleaned up, etc.
Answered By - Piotr Müller
Answer Checked By - Pedro (JavaFixing Volunteer)