Top Description Inners Fields Constructors Methods
org.eclipse.jetty.session

public abstract Class AbstractSessionManager

extends ContainerLifeCycle
implements SessionManager, Mutable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.session.SessionConfig.Mutable, org.eclipse.jetty.session.SessionConfig, org.eclipse.jetty.session.SessionManager, org.eclipse.jetty.util.component.LifeCycle
Known Direct Subclasses
org.eclipse.jetty.session.SessionHandler
Imports
java.nio.ByteBuffer, java.util.ArrayList, .Arrays, .Collections, .HashSet, .List, .Map, .Objects, .Set, .TreeMap, java.util.concurrent.ConcurrentHashMap, .TimeUnit, java.util.function.Consumer, java.util.stream.Collectors, org.eclipse.jetty.http.BadMessageException, .HttpCookie, .HttpScheme, .HttpURI, .MetaData, .Syntax, org.eclipse.jetty.server.Context, .HttpStream, .Request, .Server, .Session, org.eclipse.jetty.server.handler.ContextHandler, org.eclipse.jetty.util.Callback, .StringUtil, .URIUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, org.eclipse.jetty.util.component.ContainerLifeCycle, org.eclipse.jetty.util.statistic.CounterStatistic, .SampleStatistic, org.eclipse.jetty.util.thread.AutoLock, .ScheduledExecutorScheduler, .Scheduler, org.slf4j.Logger, .LoggerFactory

AbstractSessionHandler Class to implement most non-servlet-spec specific session behaviour.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static record
private class
AbstractSessionManager.SessionStreamWrapper

StreamWrapper to intercept commit and complete events to ensure session handling happens in context, with request available.

Field Summary

Modifier and TypeField and Description
private final Set<String>
private boolean
private Context
private int
_dftMaxIdleSecs

Setting of max inactive interval for new sessions -1 means no timeout

private ClassLoader
private boolean
private int
private Scheduler
private boolean
private SessionCache
private SessionContext
private String
private final Map<String, String>
private Map<String, String>
private SessionIdManager
private String
private String
private List<Session.LifeCycleListener>
private final CounterStatistic
private final SampleStatistic
private boolean
private boolean
pack-priv static final Logger
private static final AbstractSessionManager.RequestedSession

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HttpCookie

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.
access
(ManagedSession
the session object
session
,
boolean
whether the request is secure or not
secure
)

Called when a session is first accessed by request processing.

protected void
public long

Returns:

the time remaining before expiry or inactivity timeout
calculateInactivityTimeout
(String
the ID of the session
id
,
long
The time in milliseconds remaining before this session is considered Idle
timeRemainingMs
,
long
The maximum time in milliseconds that a session may be idle.
maxInactiveMs
)

Implements org.eclipse.jetty.session.SessionManager.calculateInactivityTimeout.

Calculate what the session timer setting should be based on: the time remaining before the session expires and any idle eviction time configured.
public void
commit(ManagedSession session)

Implements org.eclipse.jetty.session.SessionManager.commit.

Called when a response is about to be committed.
public void
complete(ManagedSession
the session object
session
)

Implements org.eclipse.jetty.session.SessionManager.complete.

Called when a request is finally leaving a session.
public void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.
protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.
private static String
duplicateSession(String id0, boolean valid0, boolean cookie0, String id1, boolean valid1, boolean cookie1)

public String
encodeURI(Request request, String uri, boolean cookiesInUse)

Implements org.eclipse.jetty.session.SessionManager.encodeURI.

public Context
public ManagedSession

Returns:

the Session matching the id or null if none exists
getManagedSession
(String
The session id, possibly imcluding worker name suffix.
extendedId
)

Implements org.eclipse.jetty.session.SessionManager.getManagedSession.

Get a known existing session
public int
public int

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
getMaxInactiveInterval
()

Implements org.eclipse.jetty.session.SessionConfig.getMaxInactiveInterval.

public int
public HttpCookie.SameSite
public abstract Server
public SessionCache
public String
public SessionContext
public String
public HttpCookie

Returns:

if this SessionManager uses cookies, then this method will return a new cookie object that should be set on the client in order to link future HTTP requests with the session. If cookies are not in use, this method returns null.
getSessionCookie
(ManagedSession
the session to which the cookie should refer.
session
,
boolean
whether the client is accessing the server over a secure protocol (i.e. HTTPS).
requestIsSecure
)

Implements org.eclipse.jetty.session.SessionManager.getSessionCookie.

A session cookie is marked as secure IFF any of the following conditions are true:
  1. SessionCookieConfig.setSecure == true
  2. SessionCookieConfig.setSecure == false && _secureRequestOnly==true && request is HTTPS
public String
public Map<String, String>

Returns:

all of the cookie config attributes EXCEPT for those that have explicit setter/getters
getSessionCookieAttributes
()

public String
public SessionIdManager
public String

Returns:

the URL path parameter name for session id URL rewriting, by default "jsessionid".
getSessionIdPathParameterName
()

Implements org.eclipse.jetty.session.SessionConfig.getSessionIdPathParameterName.

public String

Returns:

a formatted version of getSessionIdPathParameterName(), by default ";" + sessionIdParameterName + "=", for easier lookup in URL strings.
getSessionIdPathParameterNamePrefix
()

Implements org.eclipse.jetty.session.SessionConfig.getSessionIdPathParameterNamePrefix.

public String
public int
public double

Returns:

mean amount of time session remained valid
getSessionTimeMean
()

Implements org.eclipse.jetty.session.SessionManager.getSessionTimeMean.

public double

Returns:

standard deviation of amount of time session remained valid
getSessionTimeStdDev
()

Implements org.eclipse.jetty.session.SessionManager.getSessionTimeStdDev.

public long

Returns:

total amount of time all sessions remained valid
getSessionTimeTotal
()

Implements org.eclipse.jetty.session.SessionManager.getSessionTimeTotal.

public void
invalidate(String
the session id to invalidate
id
)

Implements org.eclipse.jetty.session.SessionManager.invalidate.

Called by SessionIdManager to remove a session that has been invalidated, either by this context or another context.
public boolean

Returns:

True if absolute URLs are check for remoteness before being session encoded.
isCheckingRemoteSessionIdEncoding
()

Implements org.eclipse.jetty.session.SessionConfig.isCheckingRemoteSessionIdEncoding.

public boolean

Returns:

true if session cookies should be HTTP only
isHttpOnly
()

Implements org.eclipse.jetty.session.SessionConfig.isHttpOnly.

public boolean

Returns:

true if this manager knows about this id
isIdInUse
(String
identity of session to check
id
)

Implements org.eclipse.jetty.session.SessionManager.isIdInUse.

Check if id is in use by this context
public boolean

Returns:

true if session cookies should have the Partitioned attribute
isPartitioned
()

Implements org.eclipse.jetty.session.SessionConfig.isPartitioned.

public boolean

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.
isSecureCookies
()

Implements org.eclipse.jetty.session.SessionConfig.isSecureCookies.

public boolean

Returns:

true if session cookie is to be marked as secure only on HTTPS requests
isSecureRequestOnly
()

Implements org.eclipse.jetty.session.SessionConfig.isSecureRequestOnly.

public boolean

Returns:

true if using session cookies is allowed, false otherwise
isUsingCookies
()

Implements org.eclipse.jetty.session.SessionConfig.isUsingCookies.

public boolean

Returns:

whether the session management is handled via URLs.
isUsingUriParameters
()

Implements org.eclipse.jetty.session.SessionConfig.isUsingUriParameters.

public boolean
isUsingURLs()

Deprecated for removal since 12.0.1. use isUsingUriParameters() instead, will be removed in Jetty 12.1.0
public void
newSession(Request
the inbound request
request
,
String
the session id used by the request
requestedSessionId
,
Consumer<ManagedSession> consumer)

Implements org.eclipse.jetty.session.SessionManager.newSession.

Create a new Session, using the requested session id if possible.
public SessionInactivityTimer
newSessionInactivityTimer(ManagedSession
the session to time
session
)

Implements org.eclipse.jetty.session.SessionManager.newSessionInactivityTimer.

Make a new timer for the session.
public void
public void
public void
public void
recordSessionTime(ManagedSession
the session whose time to record
session
)

Implements org.eclipse.jetty.session.SessionManager.recordSessionTime.

Record length of time session has been active.
public void
renewSessionId(String
the old session id
oldId
,
String
the session id including worker suffix
oldExtendedId
,
String
the new session id
newId
,
String
the new session id including worker suffix
newExtendedId
)

Implements org.eclipse.jetty.session.SessionManager.renewSessionId.

Change the existing session id.
protected AbstractSessionManager.RequestedSession
resolveRequestedSessionId(Request
The request from which to obtain the ID
request
)

Find any Session associated with the Request.

public void
scavenge()

Implements org.eclipse.jetty.session.SessionManager.scavenge.

Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.
private void
public void
sessionTimerExpired(ManagedSession
the session
session
,
long
the time at which to check for expiry
now
)

Implements org.eclipse.jetty.session.SessionManager.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.
public void
setCheckingRemoteSessionIdEncoding(boolean
True if absolute URLs are check for remoteness before being session encoded.
remote
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setCheckingRemoteSessionIdEncoding.

public void
setHttpOnly(boolean
True if cookies should be HttpOnly.
httpOnly
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setHttpOnly.

Set if Session cookies should use HTTP Only
public void
public void
setMaxInactiveInterval(int
the max inactivity period, in seconds. If less than or equal to zero, then the session is immortal
seconds
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setMaxInactiveInterval.

Sets the max period of inactivity, after which the session is invalidated, in seconds.
public void
setPartitioned(boolean
whether session cookies should have the Partitioned attribute
partitioned
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setPartitioned.

Sets whether session cookies should have the Partitioned attribute
public void
public void
public void
public void
setSecureRequestOnly(boolean
true to set Session Cookie Config as secure
secureRequestOnly
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setSecureRequestOnly.

HTTPS request.
public void
public void
public void
public void
public void
public void
setSessionIdManager(SessionIdManager
The sessionIdManager used for cross context session management.
sessionIdManager
)

Implements org.eclipse.jetty.session.SessionManager.setSessionIdManager, org.eclipse.jetty.session.SessionConfig.Mutable.setSessionIdManager.

Set up the SessionIdManager.
public void
setSessionIdPathParameterName(String
the URL path parameter name for session id URL rewriting (null or "none" for no rewriting).
param
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setSessionIdPathParameterName.

Sets the session id URL path parameter name.
public void
public void
setUsingCookies(boolean
true if cookies are used to track sessions
usingCookies
)

Implements org.eclipse.jetty.session.SessionConfig.Mutable.setUsingCookies.

public void
public void
setUsingURLs(boolean usingURLs)

Deprecated for removal since 12.0.1. use setUsingUriParameters(boolean) instead, will be removed in Jetty 12.1.0
private void
shutdownSessions()

Prepare sessions for session manager shutdown

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans