public class HeaderHttpSessionStrategy extends java.lang.Object implements HttpSessionStrategy
HttpSessionStrategy
that uses a header to obtain the session from.
Specifically, this implementation will allow specifying a header name using
setHeaderName(String)
. The default is "x-auth-token".
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 |
---|
HeaderHttpSessionStrategy() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getRequestedSessionId(HttpServletRequest request)
Obtains the requested session id from the provided
HttpServletRequest . |
void |
onInvalidateSession(HttpServletRequest request,
HttpServletResponse response)
This method is invoked when a session is invalidated and should inform a client
that the session id is no longer valid.
|
void |
onNewSession(Session session,
HttpServletRequest request,
HttpServletResponse response)
This method is invoked when a new session is created and should inform a client
what the new session id is.
|
void |
setHeaderName(java.lang.String headerName)
The name of the header to obtain the session id from.
|
public java.lang.String getRequestedSessionId(HttpServletRequest request)
HttpSessionStrategy
HttpServletRequest
. For example, the session id might
come from a cookie or a request header.getRequestedSessionId
in interface HttpSessionStrategy
request
- the HttpServletRequest
to obtain the
session id from. Cannot be null.HttpServletRequest
to obtain the session id
from.public void onNewSession(Session session, HttpServletRequest request, HttpServletResponse response)
HttpSessionStrategy
Session
at this time. For example, they may wish to add the IP Address,
browser headers, the username, etc to the
Session
.onNewSession
in interface HttpSessionStrategy
session
- the Session
that is being sent
to the client. Cannot be null.request
- the HttpServletRequest
that create the
new Session
Cannot be null.response
- the HttpServletResponse
that is
associated with the HttpServletRequest
that created the
new Session
Cannot be null.public void onInvalidateSession(HttpServletRequest request, HttpServletResponse response)
HttpSessionStrategy
onInvalidateSession
in interface HttpSessionStrategy
request
- the HttpServletRequest
that invalidated
the Session
Cannot be null.response
- the HttpServletResponse
that is
associated with the HttpServletRequest
that invalidated
the Session
Cannot be null.public void setHeaderName(java.lang.String headerName)
headerName
- the name of the header to obtain the session id from.