Class AbstractSessionManager
- All Implemented Interfaces:
SessionConfig, SessionConfig.Mutable, SessionManager, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
- Direct Known Subclasses:
SessionHandler, SessionHandler
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.ListenerNested classes/interfaces inherited from interface SessionConfig
SessionConfig.Mutable -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaccess(ManagedSession session, boolean secure) Called when a session is first accessed by request processing.protected voidaddSessionStreamWrapper(Request request) longcalculateInactivityTimeout(String id, long timeRemainingMs, long maxInactiveMs) Calculate what the session timer setting should be based on: the time remaining before the session expires and any idle eviction time configured.voidcommit(ManagedSession session) Called when a response is about to be committed.voidcomplete(ManagedSession session) Called when a request is finally leaving a session.voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.getManagedSession(String extendedId) Get a known existing sessionintintintabstract ServergetSessionCookie(ManagedSession session, boolean requestIsSecure) A session cookie is marked as secure IFF any of the following conditions are true: SessionCookieConfig.setSecure == true SessionCookieConfig.setSecure == false && _secureRequestOnly==true && request is HTTPS According to SessionCookieConfig javadoc, case 1 can be used when: "... even though the request that initiated the session came over HTTP, is to support a topology where the web container is front-ended by an SSL offloading load balancer.intdoubledoublelongvoidinvalidate(String id) Called by SessionIdManager to remove a session that has been invalidated, either by this context or another context.booleanbooleanbooleanCheck if id is in use by this contextbooleanbooleanbooleanbooleanbooleanbooleanDeprecated, for removal: This API element is subject to removal in a future version.voidnewSession(Request request, String requestedSessionId, Consumer<ManagedSession> consumer) Create a new Session, using the requested session id if possible.newSessionInactivityTimer(ManagedSession session) Make a new timer for the session.voidonSessionCreated(Session session) voidonSessionDestroyed(Session session) voidonSessionIdChanged(Session session, String oldId) voidrecordSessionTime(ManagedSession session) Record length of time session has been active.voidrenewSessionId(String oldId, String oldExtendedId, String newId, String newExtendedId) Change the existing session id.protected AbstractSessionManager.RequestedSessionresolveRequestedSessionId(Request request) Find any Session associated with the Request.voidscavenge()Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.voidsessionTimerExpired(ManagedSession session, long now) Each session has a timer that is configured to go off when either the session has not been accessed for a configurable amount of time, or the session itself has passed its expiry.voidsetCheckingRemoteSessionIdEncoding(boolean remote) voidsetHttpOnly(boolean httpOnly) Set if Session cookies should use HTTP OnlyvoidsetMaxCookieAge(int maxCookieAge) voidsetMaxInactiveInterval(int seconds) Sets the max period of inactivity, after which the session is invalidated, in seconds.voidsetPartitioned(boolean partitioned) Sets whether session cookies should have thePartitionedattributevoidsetRefreshCookieAge(int ageInSeconds) voidsetSameSite(HttpCookie.SameSite sessionSameSite) voidsetSecureCookies(boolean secure) voidsetSecureRequestOnly(boolean secureRequestOnly) HTTPS request.voidsetSessionCache(SessionCache cache) Set up the SessionCache.voidsetSessionComment(String sessionComment) voidsetSessionCookie(String cookieName) voidsetSessionCookieAttribute(String name, String value) voidsetSessionDomain(String domain) voidsetSessionIdManager(SessionIdManager sessionIdManager) Set up the SessionIdManager.voidSets the session id URL path parameter name.voidsetSessionPath(String sessionPath) voidsetUsingCookies(boolean usingCookies) voidsetUsingUriParameters(boolean usingUriParameters) voidsetUsingURLs(boolean usingURLs) Deprecated, for removal: This API element is subject to removal in a future version.usesetUsingUriParameters(boolean)instead, will be removed in Jetty 12.1.0Methods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stopMethods inherited from interface SessionManager
getManagedSession, newSessionAPIWrapper, onSessionActivation, onSessionAttributeUpdate, onSessionPassivation
-
Constructor Details
-
AbstractSessionManager
public AbstractSessionManager()
-
-
Method Details
-
access
Called when a session is first accessed by request processing. Updates the last access time for the session and generates a fresh cookie if necessary.- Parameters:
session- the session objectsecure- whether the request is secure or not- Returns:
- the session cookie. If not null, this cookie should be set on the response to either migrate the session or to refresh a session cookie that may expire.
- See Also:
-
calculateInactivityTimeout
Calculate what the session timer setting should be based on: the time remaining before the session expires and any idle eviction time configured. The timer value will be the lesser of the above.- Specified by:
calculateInactivityTimeoutin interfaceSessionManager- Parameters:
id- the ID of the sessiontimeRemainingMs- The time in milliseconds remaining before this session is considered IdlemaxInactiveMs- The maximum time in milliseconds that a session may be idle.- Returns:
- the time remaining before expiry or inactivity timeout
-
commit
Called when a response is about to be committed. We might take this opportunity to persist the session so that any subsequent requests to other servers will see the modifications.- Specified by:
commitin interfaceSessionManager
-
complete
Called when a request is finally leaving a session.- Specified by:
completein interfaceSessionManager- Parameters:
session- the session object
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classContainerLifeCycle- Throws:
Exception- If there was a problem starting. Will cause a transition to FAILED state
-
getContext
- Specified by:
getContextin interfaceSessionManager
-
getMaxCookieAge
public int getMaxCookieAge()- Specified by:
getMaxCookieAgein interfaceSessionConfig
-
setMaxCookieAge
public void setMaxCookieAge(int maxCookieAge) - Specified by:
setMaxCookieAgein interfaceSessionConfig.Mutable
-
getMaxInactiveInterval
public int getMaxInactiveInterval()- Specified by:
getMaxInactiveIntervalin interfaceSessionConfig- Returns:
- the max period of inactivity, after which the session is invalidated, in seconds. If less than or equal to zero, then the session is immortal
- See Also:
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int seconds) Sets the max period of inactivity, after which the session is invalidated, in seconds.- Specified by:
setMaxInactiveIntervalin interfaceSessionConfig.Mutable- Parameters:
seconds- the max inactivity period, in seconds. If less than or equal to zero, then the session is immortal- See Also:
-
getRefreshCookieAge
public int getRefreshCookieAge()- Specified by:
getRefreshCookieAgein interfaceSessionConfig
-
setRefreshCookieAge
public void setRefreshCookieAge(int ageInSeconds) - Specified by:
setRefreshCookieAgein interfaceSessionConfig.Mutable
-
getServer
-
getManagedSession
Get a known existing session- Specified by:
getManagedSessionin interfaceSessionManager- Parameters:
extendedId- The session id, possibly including worker name suffix.- Returns:
- the Session matching the id or null if none exists
-
getSessionCache
- Specified by:
getSessionCachein interfaceSessionManager- Returns:
- the session cache
-
setSessionCache
Set up the SessionCache.- Specified by:
setSessionCachein interfaceSessionConfig.Mutable- Specified by:
setSessionCachein interfaceSessionManager- Parameters:
cache- the SessionCache to use
-
getSessionComment
- Specified by:
getSessionCommentin interfaceSessionConfig
-
setSessionComment
- Specified by:
setSessionCommentin interfaceSessionConfig.Mutable
-
getSameSite
- Specified by:
getSameSitein interfaceSessionConfig
-
setSameSite
- Specified by:
setSameSitein interfaceSessionConfig.Mutable
-
getSessionContext
-
getSessionCookie
- Specified by:
getSessionCookiein interfaceSessionConfig
-
setSessionCookie
- Specified by:
setSessionCookiein interfaceSessionConfig.Mutable
-
getSessionDomain
- Specified by:
getSessionDomainin interfaceSessionConfig
-
setSessionDomain
- Specified by:
setSessionDomainin interfaceSessionConfig.Mutable
-
setSessionCookieAttribute
-
getSessionCookieAttribute
-
getSessionCookieAttributes
-
getSessionIdManager
- Specified by:
getSessionIdManagerin interfaceSessionManager
-
setSessionIdManager
Set up the SessionIdManager.- Specified by:
setSessionIdManagerin interfaceSessionConfig.Mutable- Specified by:
setSessionIdManagerin interfaceSessionManager- Parameters:
sessionIdManager- The sessionIdManager used for cross context session management.
-
getSessionIdPathParameterName
- Specified by:
getSessionIdPathParameterNamein interfaceSessionConfig- Returns:
- the URL path parameter name for session id URL rewriting, by default "jsessionid".
- See Also:
-
setSessionIdPathParameterName
Sets the session id URL path parameter name.- Specified by:
setSessionIdPathParameterNamein interfaceSessionConfig.Mutable- Parameters:
param- the URL path parameter name for session id URL rewriting (null or "none" for no rewriting).- See Also:
-
getSessionIdPathParameterNamePrefix
- Specified by:
getSessionIdPathParameterNamePrefixin interfaceSessionConfig- Returns:
- a formatted version of
getSessionIdPathParameterName(), by default ";" + sessionIdParameterName + "=", for easier lookup in URL strings. - See Also:
-
getSessionPath
- Specified by:
getSessionPathin interfaceSessionConfig
-
setSessionPath
- Specified by:
setSessionPathin interfaceSessionConfig.Mutable
-
getSessionTimeMean
- Specified by:
getSessionTimeMeanin interfaceSessionManager- Returns:
- mean amount of time session remained valid
-
getSessionTimeStdDev
@ManagedAttribute("standard deviation a session remained valid (in s)") public double getSessionTimeStdDev()- Specified by:
getSessionTimeStdDevin interfaceSessionManager- Returns:
- standard deviation of amount of time session remained valid
-
getSessionTimeTotal
- Specified by:
getSessionTimeTotalin interfaceSessionManager- Returns:
- total amount of time all sessions remained valid
-
getSessionsCreated
- Specified by:
getSessionsCreatedin interfaceSessionManager
-
encodeURI
- Specified by:
encodeURIin interfaceSessionManager
-
onSessionIdChanged
- Specified by:
onSessionIdChangedin interfaceSessionManager
-
onSessionCreated
- Specified by:
onSessionCreatedin interfaceSessionManager
-
onSessionDestroyed
- Specified by:
onSessionDestroyedin interfaceSessionManager
-
invalidate
Called by SessionIdManager to remove a session that has been invalidated, either by this context or another context. Also called by SessionIdManager when a session has expired in either this context or another context.- Specified by:
invalidatein interfaceSessionManager- Parameters:
id- the session id to invalidate- Throws:
Exception
-
isCheckingRemoteSessionIdEncoding
public boolean isCheckingRemoteSessionIdEncoding()- Specified by:
isCheckingRemoteSessionIdEncodingin interfaceSessionConfig- Returns:
- True if absolute URLs are check for remoteness before being session encoded.
-
setCheckingRemoteSessionIdEncoding
public void setCheckingRemoteSessionIdEncoding(boolean remote) - Specified by:
setCheckingRemoteSessionIdEncodingin interfaceSessionConfig.Mutable- Parameters:
remote- True if absolute URLs are check for remoteness before being session encoded.
-
isHttpOnly
public boolean isHttpOnly()- Specified by:
isHttpOnlyin interfaceSessionConfig- Returns:
- true if session cookies should be HTTP only
- See Also:
-
setHttpOnly
public void setHttpOnly(boolean httpOnly) Set if Session cookies should use HTTP Only- Specified by:
setHttpOnlyin interfaceSessionConfig.Mutable- Parameters:
httpOnly- True if cookies should be HttpOnly.- See Also:
-
isPartitioned
public boolean isPartitioned()- Specified by:
isPartitionedin interfaceSessionConfig- Returns:
- true if session cookies should have the
Partitionedattribute - See Also:
-
setPartitioned
public void setPartitioned(boolean partitioned) Sets whether session cookies should have thePartitionedattribute- Specified by:
setPartitionedin interfaceSessionConfig.Mutable- Parameters:
partitioned- whether session cookies should have thePartitionedattribute- See Also:
-
isIdInUse
Check if id is in use by this context- Specified by:
isIdInUsein interfaceSessionManager- Parameters:
id- identity of session to check- Returns:
trueif this manager knows about this id- Throws:
Exception- if any error occurred
-
isSecureCookies
public boolean isSecureCookies()- Specified by:
isSecureCookiesin interfaceSessionConfig- Returns:
- same as SessionCookieConfig.getSecure(). If true, session cookies are ALWAYS marked as secure. If false, a session cookie is ONLY marked as secure if _secureRequestOnly == true and it is an HTTPS request.
-
setSecureCookies
public void setSecureCookies(boolean secure) - Specified by:
setSecureCookiesin interfaceSessionConfig.Mutable
-
isSecureRequestOnly
public boolean isSecureRequestOnly()- Specified by:
isSecureRequestOnlyin interfaceSessionConfig- Returns:
- true if session cookie is to be marked as secure only on HTTPS requests
-
setSecureRequestOnly
public void setSecureRequestOnly(boolean secureRequestOnly) HTTPS request. Can be overridden by setting SessionCookieConfig.setSecure(true), in which case the session cookie will be marked as secure on both HTTPS and HTTP.- Specified by:
setSecureRequestOnlyin interfaceSessionConfig.Mutable- Parameters:
secureRequestOnly- true to set Session Cookie Config as secure
-
isUsingCookies
public boolean isUsingCookies()- Specified by:
isUsingCookiesin interfaceSessionConfig- Returns:
- true if using session cookies is allowed, false otherwise
-
setUsingCookies
public void setUsingCookies(boolean usingCookies) - Specified by:
setUsingCookiesin interfaceSessionConfig.Mutable- Parameters:
usingCookies- true if cookies are used to track sessions
-
isUsingUriParameters
public boolean isUsingUriParameters()- Specified by:
isUsingUriParametersin interfaceSessionConfig- Returns:
- whether the session management is handled via URLs.
-
setUsingUriParameters
public void setUsingUriParameters(boolean usingUriParameters) - Specified by:
setUsingUriParametersin interfaceSessionConfig.Mutable
-
isUsingURLs
Deprecated, for removal: This API element is subject to removal in a future version.useisUsingUriParameters()instead, will be removed in Jetty 12.1.0 -
setUsingURLs
Deprecated, for removal: This API element is subject to removal in a future version.usesetUsingUriParameters(boolean)instead, will be removed in Jetty 12.1.0 -
newSession
public void newSession(Request request, String requestedSessionId, Consumer<ManagedSession> consumer) Create a new Session, using the requested session id if possible.- Specified by:
newSessionin interfaceSessionManager- Parameters:
request- the inbound requestrequestedSessionId- the session id used by the request
-
newSessionInactivityTimer
Make a new timer for the session.- Specified by:
newSessionInactivityTimerin interfaceSessionManager- Parameters:
session- the session to time
-
recordSessionTime
Record length of time session has been active. Called when the session is about to be invalidated.- Specified by:
recordSessionTimein interfaceSessionManager- Parameters:
session- the session whose time to record
-
renewSessionId
Change the existing session id.- Specified by:
renewSessionIdin interfaceSessionManager- Parameters:
oldId- the old session idoldExtendedId- the session id including worker suffixnewId- the new session idnewExtendedId- the new session id including worker suffix
-
scavenge
public void scavenge()Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.- Specified by:
scavengein interfaceSessionManager
-
sessionTimerExpired
Each session has a timer that is configured to go off when either the session has not been accessed for a configurable amount of time, or the session itself has passed its expiry.If it has passed its expiry, then we will mark it for scavenging by next run of the HouseKeeper; if it has been idle longer than the configured eviction period, we evict from the cache.
If none of the above are true, then the System timer is inconsistent and the caller of this method will need to reset the timer.
- Specified by:
sessionTimerExpiredin interfaceSessionManager- Parameters:
session- the sessionnow- the time at which to check for expiry
-
addSessionStreamWrapper
-
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContainerLifeCycle- Throws:
Exception- If there was a problem stopping. Will cause a transition to FAILED state
-
resolveRequestedSessionId
Find any Session associated with the Request.- Parameters:
request- The request from which to obtain the ID
-
getSessionCookie
A session cookie is marked as secure IFF any of the following conditions are true:- SessionCookieConfig.setSecure == true
- SessionCookieConfig.setSecure == false && _secureRequestOnly==true && request is HTTPS
For case 2, you can use _secureRequestOnly to determine if you want the Servlet Spec 3.0 default behavior when SessionCookieConfig.setSecure==false, which is: "they shall be marked as secure only if the request that initiated the corresponding session was also secure"
The default for _secureRequestOnly is true, which gives the above behavior. If you set it to false, then a session cookie is NEVER marked as secure, even if the initiating request was secure.
- Specified by:
getSessionCookiein interfaceSessionManager- Parameters:
session- the session to which the cookie should refer.requestIsSecure- whether the client is accessing the server over a secure protocol (i.e. HTTPS).- Returns:
- if this
SessionManageruses cookies, then this method will return a newcookie objectthat should be set on the client in order to link future HTTP requests with thesession. If cookies are not in use, this method returnsnull.
-
isUsingUriParameters()instead, will be removed in Jetty 12.1.0