Class AbstractSessionManager
- All Implemented Interfaces:
SessionConfig
,SessionConfig.Mutable
,SessionManager
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
- Direct Known Subclasses:
SessionHandler
,SessionHandler
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.session.SessionConfig
SessionConfig.Mutable
-
Field Summary
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPING
Fields inherited from interface org.eclipse.jetty.session.SessionConfig
__CheckRemoteSessionEncodingProperty, __DefaultSessionCookie, __DefaultSessionDomain, __DefaultSessionIdPathParameterName, __MaxAgeProperty, __SessionCookieProperty, __SessionDomainProperty, __SessionIdPathParameterNameProperty, __SessionPathProperty
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaccess
(ManagedSession session, boolean secure) Called when a session is first accessed by request processing.protected void
addSessionStreamWrapper
(Request request) long
calculateInactivityTimeout
(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.void
commit
(ManagedSession session) Called when a response is about to be committed.void
complete
(ManagedSession session) Called when a request is finally leaving a session.void
doStart()
Starts the managed lifecycle beans in the order they were added.protected void
doStop()
Stops the managed lifecycle beans in the reverse order they were added.getManagedSession
(String extendedId) Get a known existing sessionint
int
int
abstract Server
getSessionCookie
(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: "...int
double
double
long
void
invalidate
(String id) Called by SessionIdManager to remove a session that has been invalidated, either by this context or another context.boolean
boolean
boolean
Check if id is in use by this contextboolean
boolean
boolean
boolean
boolean
boolean
Deprecated, for removal: This API element is subject to removal in a future version.void
newSession
(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.void
onSessionCreated
(Session session) void
onSessionDestroyed
(Session session) void
onSessionIdChanged
(Session session, String oldId) void
recordSessionTime
(ManagedSession session) Record length of time session has been active.void
renewSessionId
(String oldId, String oldExtendedId, String newId, String newExtendedId) Change the existing session id.protected AbstractSessionManager.RequestedSession
resolveRequestedSessionId
(Request request) Find any Session associated with the Request.void
scavenge()
Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.void
sessionTimerExpired
(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.void
setCheckingRemoteSessionIdEncoding
(boolean remote) void
setHttpOnly
(boolean httpOnly) Set if Session cookies should use HTTP Onlyvoid
setMaxCookieAge
(int maxCookieAge) void
setMaxInactiveInterval
(int seconds) Sets the max period of inactivity, after which the session is invalidated, in seconds.void
setPartitioned
(boolean partitioned) Sets whether session cookies should have thePartitioned
attributevoid
setRefreshCookieAge
(int ageInSeconds) void
setSameSite
(HttpCookie.SameSite sessionSameSite) void
setSecureCookies
(boolean secure) void
setSecureRequestOnly
(boolean secureRequestOnly) HTTPS request.void
setSessionCache
(SessionCache cache) Set up the SessionCache.void
setSessionComment
(String sessionComment) void
setSessionCookie
(String cookieName) void
setSessionCookieAttribute
(String name, String value) void
setSessionDomain
(String domain) void
setSessionIdManager
(SessionIdManager sessionIdManager) Set up the SessionIdManager.void
Sets the session id URL path parameter name.void
setSessionPath
(String sessionPath) void
setUsingCookies
(boolean usingCookies) void
setUsingUriParameters
(boolean usingUriParameters) void
setUsingURLs
(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 org.eclipse.jetty.util.component.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, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
Methods inherited from interface org.eclipse.jetty.session.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:
calculateInactivityTimeout
in 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:
commit
in interfaceSessionManager
-
complete
Called when a request is finally leaving a session.- Specified by:
complete
in interfaceSessionManager
- Parameters:
session
- the session object
-
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
getContext
- Specified by:
getContext
in interfaceSessionManager
-
getMaxCookieAge
public int getMaxCookieAge()- Specified by:
getMaxCookieAge
in interfaceSessionConfig
-
setMaxCookieAge
public void setMaxCookieAge(int maxCookieAge) - Specified by:
setMaxCookieAge
in interfaceSessionConfig.Mutable
-
getMaxInactiveInterval
public int getMaxInactiveInterval()- Specified by:
getMaxInactiveInterval
in 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:
setMaxInactiveInterval
in 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:
getRefreshCookieAge
in interfaceSessionConfig
-
setRefreshCookieAge
public void setRefreshCookieAge(int ageInSeconds) - Specified by:
setRefreshCookieAge
in interfaceSessionConfig.Mutable
-
getServer
-
getManagedSession
Get a known existing session- Specified by:
getManagedSession
in 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:
getSessionCache
in interfaceSessionManager
- Returns:
- the session cache
-
setSessionCache
Set up the SessionCache.- Specified by:
setSessionCache
in interfaceSessionConfig.Mutable
- Specified by:
setSessionCache
in interfaceSessionManager
- Parameters:
cache
- the SessionCache to use
-
getSessionComment
- Specified by:
getSessionComment
in interfaceSessionConfig
-
setSessionComment
- Specified by:
setSessionComment
in interfaceSessionConfig.Mutable
-
getSameSite
- Specified by:
getSameSite
in interfaceSessionConfig
-
setSameSite
- Specified by:
setSameSite
in interfaceSessionConfig.Mutable
-
getSessionContext
-
getSessionCookie
- Specified by:
getSessionCookie
in interfaceSessionConfig
-
setSessionCookie
- Specified by:
setSessionCookie
in interfaceSessionConfig.Mutable
-
getSessionDomain
- Specified by:
getSessionDomain
in interfaceSessionConfig
-
setSessionDomain
- Specified by:
setSessionDomain
in interfaceSessionConfig.Mutable
-
setSessionCookieAttribute
-
getSessionCookieAttribute
-
getSessionCookieAttributes
- Returns:
- all of the cookie config attributes EXCEPT for those that have explicit setter/getters
-
getSessionIdManager
- Specified by:
getSessionIdManager
in interfaceSessionManager
-
setSessionIdManager
Set up the SessionIdManager.- Specified by:
setSessionIdManager
in interfaceSessionConfig.Mutable
- Specified by:
setSessionIdManager
in interfaceSessionManager
- Parameters:
sessionIdManager
- The sessionIdManager used for cross context session management.
-
getSessionIdPathParameterName
- Specified by:
getSessionIdPathParameterName
in 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:
setSessionIdPathParameterName
in 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:
getSessionIdPathParameterNamePrefix
in interfaceSessionConfig
- Returns:
- a formatted version of
getSessionIdPathParameterName()
, by default ";" + sessionIdParameterName + "=", for easier lookup in URL strings. - See Also:
-
getSessionPath
- Specified by:
getSessionPath
in interfaceSessionConfig
-
setSessionPath
- Specified by:
setSessionPath
in interfaceSessionConfig.Mutable
-
getSessionTimeMean
- Specified by:
getSessionTimeMean
in interfaceSessionManager
- Returns:
- mean amount of time session remained valid
-
getSessionTimeStdDev
@ManagedAttribute("standard deviation a session remained valid (in s)") public double getSessionTimeStdDev()- Specified by:
getSessionTimeStdDev
in interfaceSessionManager
- Returns:
- standard deviation of amount of time session remained valid
-
getSessionTimeTotal
- Specified by:
getSessionTimeTotal
in interfaceSessionManager
- Returns:
- total amount of time all sessions remained valid
-
getSessionsCreated
- Specified by:
getSessionsCreated
in interfaceSessionManager
-
encodeURI
- Specified by:
encodeURI
in interfaceSessionManager
-
onSessionIdChanged
- Specified by:
onSessionIdChanged
in interfaceSessionManager
-
onSessionCreated
- Specified by:
onSessionCreated
in interfaceSessionManager
-
onSessionDestroyed
- Specified by:
onSessionDestroyed
in 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:
invalidate
in interfaceSessionManager
- Parameters:
id
- the session id to invalidate- Throws:
Exception
-
isCheckingRemoteSessionIdEncoding
public boolean isCheckingRemoteSessionIdEncoding()- Specified by:
isCheckingRemoteSessionIdEncoding
in interfaceSessionConfig
- Returns:
- True if absolute URLs are check for remoteness before being session encoded.
-
setCheckingRemoteSessionIdEncoding
public void setCheckingRemoteSessionIdEncoding(boolean remote) - Specified by:
setCheckingRemoteSessionIdEncoding
in interfaceSessionConfig.Mutable
- Parameters:
remote
- True if absolute URLs are check for remoteness before being session encoded.
-
isHttpOnly
public boolean isHttpOnly()- Specified by:
isHttpOnly
in 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:
setHttpOnly
in interfaceSessionConfig.Mutable
- Parameters:
httpOnly
- True if cookies should be HttpOnly.- See Also:
-
isPartitioned
public boolean isPartitioned()- Specified by:
isPartitioned
in interfaceSessionConfig
- Returns:
- true if session cookies should have the
Partitioned
attribute - See Also:
-
setPartitioned
public void setPartitioned(boolean partitioned) Sets whether session cookies should have thePartitioned
attribute- Specified by:
setPartitioned
in interfaceSessionConfig.Mutable
- Parameters:
partitioned
- whether session cookies should have thePartitioned
attribute- See Also:
-
isIdInUse
Check if id is in use by this context- Specified by:
isIdInUse
in interfaceSessionManager
- Parameters:
id
- identity of session to check- Returns:
true
if this manager knows about this id- Throws:
Exception
- if any error occurred
-
isSecureCookies
public boolean isSecureCookies()- Specified by:
isSecureCookies
in 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:
setSecureCookies
in interfaceSessionConfig.Mutable
-
isSecureRequestOnly
public boolean isSecureRequestOnly()- Specified by:
isSecureRequestOnly
in 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:
setSecureRequestOnly
in interfaceSessionConfig.Mutable
- Parameters:
secureRequestOnly
- true to set Session Cookie Config as secure
-
isUsingCookies
public boolean isUsingCookies()- Specified by:
isUsingCookies
in interfaceSessionConfig
- Returns:
- true if using session cookies is allowed, false otherwise
-
setUsingCookies
public void setUsingCookies(boolean usingCookies) - Specified by:
setUsingCookies
in interfaceSessionConfig.Mutable
- Parameters:
usingCookies
- true if cookies are used to track sessions
-
isUsingUriParameters
public boolean isUsingUriParameters()- Specified by:
isUsingUriParameters
in interfaceSessionConfig
- Returns:
- whether the session management is handled via URLs.
-
setUsingUriParameters
public void setUsingUriParameters(boolean usingUriParameters) - Specified by:
setUsingUriParameters
in 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:
newSession
in interfaceSessionManager
- Parameters:
request
- the inbound requestrequestedSessionId
- the session id used by the request
-
newSessionInactivityTimer
Make a new timer for the session.- Specified by:
newSessionInactivityTimer
in 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:
recordSessionTime
in interfaceSessionManager
- Parameters:
session
- the session whose time to record
-
renewSessionId
Change the existing session id.- Specified by:
renewSessionId
in 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:
scavenge
in 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:
sessionTimerExpired
in interfaceSessionManager
- Parameters:
session
- the sessionnow
- the time at which to check for expiry
-
addSessionStreamWrapper
-
doStop
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in 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:
getSessionCookie
in 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
SessionManager
uses cookies, then this method will return a newcookie object
that 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