ojus kulkarni
ojus kulkarni

Reputation: 1907

clear cookies while logout in spring security or in angular

My trial code to remove cookies

.logout()
.logoutUrl("/access/logout")
.logoutSuccessHandler(new LogoutSuccessHandler() {
 @Override
public void onLogoutSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication a) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
  }
})
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)

This code is of logout security with HttpSecurity.

Here I am getting issue to delete cookies
in logoutSuccessHandler in logger it shows cookies = 1 and i.e JESSESIONID
So my problem is how to delete cookie at the time of logout
or if is there any another way or any way in angular then please tell me

Upvotes: 2

Views: 11229

Answers (1)

ojus kulkarni
ojus kulkarni

Reputation: 1907

After going through many blogs on spring security I got answer,

.invalidateHttpSession(true) :- it is used to clear our session
and
.deleteCookies("JSESSIONID") :- it is used to delete cookies

use this after your success handler so that it will remove all cookies after logout

EDIT

And if any one want to handle cookies from frontend side then you can handle it using ng-cookies in AngularJs.

Upvotes: 3

Related Questions