public class HeaderHttpSessionIdResolver extends java.lang.Object implements HttpSessionIdResolver
HttpSessionIdResolver
that uses a header to resolve the session id.
Specifically, this implementation will allow specifying a header name using
HeaderHttpSessionIdResolver(String)
. Convenience factory methods for creating
instances that use common header names, such as "X-Auth-Token" and
"Authentication-Info", are available as well.
When a session is created, the HTTP response will have a response header of the specified name and the value of the session id. For example:
HTTP/1.1 200 OK X-Auth-Token: f81d4fae-7dec-11d0-a765-00a0c91e6bf6The client should now include the session in each request by specifying the same header in their request. For example:
GET /messages/ HTTP/1.1 Host: example.com X-Auth-Token: f81d4fae-7dec-11d0-a765-00a0c91e6bf6When the session is invalidated, the server will send an HTTP response that has the header name and a blank value. For example:
HTTP/1.1 200 OK X-Auth-Token:
Constructor and Description |
---|
HeaderHttpSessionIdResolver(java.lang.String headerName)
The name of the header to obtain the session id from.
|
Modifier and Type | Method and Description |
---|---|
static HeaderHttpSessionIdResolver |
authenticationInfo()
Convenience factory to create
HeaderHttpSessionIdResolver that uses
"Authentication-Info" header. |
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 |
setSessionId(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String sessionId)
Send the given session id to the client.
|
static HeaderHttpSessionIdResolver |
xAuthToken()
Convenience factory to create
HeaderHttpSessionIdResolver that uses
"X-Auth-Token" header. |
public HeaderHttpSessionIdResolver(java.lang.String headerName)
headerName
- the name of the header to obtain the session id from.public static HeaderHttpSessionIdResolver xAuthToken()
HeaderHttpSessionIdResolver
that uses
"X-Auth-Token" header.public static HeaderHttpSessionIdResolver authenticationInfo()
HeaderHttpSessionIdResolver
that uses
"Authentication-Info" header.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 response