I'm using Spring Security in my web app. As far as I know, the JSESSIONID cookie is used for authentication.
It's clear to me that the cookie should exist after successful authentication but what's the point of this cookie before authentication takes place?
I'm using default spring boot with spring security configuration.
When I go to default /login
URL the cookie already exists
I tried to debug the authentication process by creating a breakpoint in UsernamePasswordAuthenticationFilter
. After I enter my username and the password, I'm successfully authenticated using the same cookie (sessionId
) in details
of the UsernameAuthenticationToken
However, when I'm finally authenticated the cookie gets replaced by another one like so:
From now on, the cookie in response is used inside the application.
My question is how (regarding cookie generation) where and why this cookie set before the user is authenticated? In addition, is the "pre-JSESSIONID" cookie somehow used to create "real" JSESSIONID?