public final class CookieHttpSessionIdResolver extends java.lang.Object implements HttpSessionIdResolver
HttpSessionIdResolver
that uses a cookie to obtain the session from.
Specifically, this implementation will allow specifying a cookie serialization strategy
using setCookieSerializer(CookieSerializer)
. The
default is cookie name is "SESSION".
When a session is created, the HTTP response will have a cookie with the specified
cookie name and the value of the session id. The cookie will be marked as a session
cookie, use the context path for the path of the cookie, marked as HTTPOnly, and if
ServletRequest.isSecure()
returns true, the cookie will
be marked as secure. For example:
HTTP/1.1 200 OK Set-Cookie: SESSION=f81d4fae-7dec-11d0-a765-00a0c91e6bf6; Path=/context-root; Secure; HttpOnlyThe client should now include the session in each request by specifying the same cookie in their request. For example:
GET /messages/ HTTP/1.1 Host: example.com Cookie: SESSION=f81d4fae-7dec-11d0-a765-00a0c91e6bf6When the session is invalidated, the server will send an HTTP response that expires the cookie. For example:
HTTP/1.1 200 OK Set-Cookie: SESSION=f81d4fae-7dec-11d0-a765-00a0c91e6bf6; Expires=Thur, 1 Jan 1970 00:00:00 GMT; Secure; HttpOnly
Constructor and Description |
---|
CookieHttpSessionIdResolver() |
Modifier and Type | Method and Description |
---|---|
void |
expireSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Instruct the client to end the current session.
|
java.util.List<java.lang.String> |
resolveSessionIds(javax.servlet.http.HttpServletRequest request)
Resolve the session ids associated with the provided
HttpServletRequest . |
void |
setCookieSerializer(CookieSerializer cookieSerializer)
Sets the
CookieSerializer to be used. |
void |
setSessionId(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String sessionId)
Send the given session id to the client.
|
public java.util.List<java.lang.String> resolveSessionIds(javax.servlet.http.HttpServletRequest request)
HttpSessionIdResolver
HttpServletRequest
.
For example, the session id might come from a cookie or a request header.resolveSessionIds
in interface HttpSessionIdResolver
request
- the current requestpublic void setSessionId(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String sessionId)
HttpSessionIdResolver
setSessionId
in interface HttpSessionIdResolver
request
- the current requestresponse
- the current responsesessionId
- the session idpublic void expireSession(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
HttpSessionIdResolver
expireSession
in interface HttpSessionIdResolver
request
- the current requestresponse
- the current responsepublic void setCookieSerializer(CookieSerializer cookieSerializer)
CookieSerializer
to be used.cookieSerializer
- the cookieSerializer to set. Cannot be null.