Someone can say that this is a duplicate question but I have looked through a lot of answers, tried a bunch of methods but can not understand what I have missed.
I use very basic Spring Security in my REST server. When I first time make a request to my server directly from a browser to localhost:.../getData I am of course asked to authorize.
Then the server permits this request every time. How I can logout so that the next requests require an authorization again?
Now I tried to use several methods on my server for logout:
@RequestMapping(value = "/logoutMe2", method = RequestMethod.GET)
public void logout2() {
SecurityContextHolder.getContext().setAuthentication(null);
}
@RequestMapping(value = "/logoutMe3", method = RequestMethod.GET)
public void logout3() {
SecurityContextHolder.clearContext();
}
@RequestMapping(value = "/logoutMe", method = RequestMethod.GET)
public void logout(HttpServletRequest rq, HttpServletResponse rs) {
SecurityContextLogoutHandler securityContextLogoutHandler =
new SecurityContextLogoutHandler();
securityContextLogoutHandler.logout(rq, rs, null);
}
@RequestMapping(value = "/logoutMe4", method = RequestMethod.GET)
public static void myLogoff(HttpServletRequest request, HttpServletResponse response) {
CookieClearingLogoutHandler cookieClearingLogoutHandler = new CookieClearingLogoutHandler(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
SecurityContextLogoutHandler securityContextLogoutHandler = new SecurityContextLogoutHandler();
cookieClearingLogoutHandler.logout(request, response, null);
securityContextLogoutHandler.logout(request, response, null);
}
If I use direct link
I receive a Not Found error.
What I am missing? It seems that I have forget some obvious thing...