I currently have an application running that uses java Spring to handle sessions. I have the following code, which handles all the sessions for me.
@RequestMapping(value = "/login", method = GET)
public @ResponseBody
UserCredentials startLoginProcess(HttpSession session)
{
//initiate session if none exists
}
@RequestMapping(value = "/login", method = POST)
@ResponseStatus(value = HttpStatus.OK)
public void login(@RequestBody UserCredentials user, HttpSession session)
{
//do login stuff
}
@RequestMapping(value = "/logout", method = GET)
@ResponseStatus(value = HttpStatus.OK)
public void logout(HttpSession session)
{
session.invalidate();
}
The key here is the logout which calls invalidate(). This should mark the session as invalid.
However, when a call is made after invalidate using the same session, the server sends a response with a 200 OK and a new set-cookie header. I instead want an error to be thrown such as a 403 or something to state that the cookie is now invalid.
What are some ways I can do this?
To be a little more specific, I would like the login GET call to handle creating new sessions if none exists, but all other calls should throw some type of error if the session is invalid. Apparently there is no isInvalid method on HttpSession.
logoutaction you want to verify whether session is valid or not if valid you want to proceedlogoutotherwisesessionExpired?sessionExpiredon all endpoints except for GET /login if the session is not validif(session==null)if that is null redirect tosessionExpiredpage.logoutaction You assign session with null and redirect to logout page ..