Class HeaderHttpSessionIdResolver
java.lang.Object
org.springframework.session.web.http.HeaderHttpSessionIdResolver
- All Implemented Interfaces:
HttpSessionIdResolver
A
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:
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionHeaderHttpSessionIdResolver(String headerName) The name of the header to obtain the session id from. -
Method Summary
Modifier and TypeMethodDescriptionstatic HeaderHttpSessionIdResolverConvenience factory to createHeaderHttpSessionIdResolverthat uses "Authentication-Info" header.voidexpireSession(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Instruct the client to end the current session.resolveSessionIds(jakarta.servlet.http.HttpServletRequest request) Resolve the session ids associated with the providedHttpServletRequest.voidsetSessionId(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sessionId) Send the given session id to the client.static HeaderHttpSessionIdResolverConvenience factory to createHeaderHttpSessionIdResolverthat uses "X-Auth-Token" header.
-
Constructor Details
-
HeaderHttpSessionIdResolver
The name of the header to obtain the session id from.- Parameters:
headerName- the name of the header to obtain the session id from.
-
-
Method Details
-
xAuthToken
Convenience factory to createHeaderHttpSessionIdResolverthat uses "X-Auth-Token" header.- Returns:
- the instance configured to use "X-Auth-Token" header
-
authenticationInfo
Convenience factory to createHeaderHttpSessionIdResolverthat uses "Authentication-Info" header.- Returns:
- the instance configured to use "Authentication-Info" header
-
resolveSessionIds
Description copied from interface:HttpSessionIdResolverResolve the session ids associated with the providedHttpServletRequest. For example, the session id might come from a cookie or a request header.- Specified by:
resolveSessionIdsin interfaceHttpSessionIdResolver- Parameters:
request- the current request- Returns:
- the session ids
-
setSessionId
public void setSessionId(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String sessionId) Description copied from interface:HttpSessionIdResolverSend the given session id to the client. This method is invoked when a new session is created and should inform a client what the new session id is. For example, it might create a new cookie with the session id in it or set an HTTP response header with the value of the new session id.- Specified by:
setSessionIdin interfaceHttpSessionIdResolver- Parameters:
request- the current requestresponse- the current responsesessionId- the session id
-
expireSession
public void expireSession(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Description copied from interface:HttpSessionIdResolverInstruct the client to end the current session. This method is invoked when a session is invalidated and should inform a client that the session id is no longer valid. For example, it might remove a cookie with the session id in it or set an HTTP response header with an empty value indicating to the client to no longer submit that session id.- Specified by:
expireSessionin interfaceHttpSessionIdResolver- Parameters:
request- the current requestresponse- the current response
-