public class HeaderHttpSessionStrategy extends 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 |
|---|---|
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(String headerName)
The name of the header to obtain the session id from.
|
public String getRequestedSessionId(HttpServletRequest request)
HttpSessionStrategyHttpServletRequest. For example, the session id might
come from a cookie or a request header.getRequestedSessionId in interface HttpSessionStrategyrequest - 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)
HttpSessionStrategySession at this time. For example, they may wish to add the IP Address,
browser headers, the username, etc to the
Session.onNewSession in interface HttpSessionStrategysession - 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)
HttpSessionStrategyonInvalidateSession in interface HttpSessionStrategyrequest - 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(String headerName)
headerName - the name of the header to obtain the session id from.