Package org.eclipse.jetty.server.session
Class DefaultSessionIdManager
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.session.DefaultSessionIdManager
- All Implemented Interfaces:
SessionIdManager
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
@ManagedObject
public class DefaultSessionIdManager
extends ContainerLifeCycle
implements SessionIdManager
DefaultSessionIdManager
Manages session ids to ensure each session id within a context is unique, and that
session ids can be shared across contexts (but not session contents).
There is only 1 session id manager per Server instance.
Runs a HouseKeeper thread to periodically check for expired Sessions.
- See Also:
-
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
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected HouseKeeper
protected boolean
protected Random
protected long
protected Server
protected boolean
protected String
protected String
protected static final AtomicLong
-
Constructor Summary
ConstructorDescriptionDefaultSessionIdManager
(Server server) DefaultSessionIdManager
(Server server, Random random) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.void
Remove an id from use by telling all contexts to remove a session with this id.getExtendedId
(String clusterId, jakarta.servlet.http.HttpServletRequest request) Get the session ID with any worker ID.Get the session ID without any worker ID.long
Get SessionHandler for every context.Get the workname.void
Set up a random number generator for the sessionids.void
invalidateAll
(String id) Invalidate all sessions on all contexts that share the same id.boolean
newSessionId
(long seedTerm) newSessionId
(jakarta.servlet.http.HttpServletRequest request, long created) Create a new session id if necessary.renewSessionId
(String oldClusterId, String oldNodeId, jakarta.servlet.http.HttpServletRequest request) Generate a new id for a session and update across all SessionManagers.void
void
setReseed
(long reseed) Set the reseed probability.void
void
setSessionHouseKeeper
(HouseKeeper houseKeeper) void
setWorkerName
(String workerName) Set the workername.toString()
Methods 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, 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
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
-
Field Details
-
__NEW_SESSION_ID
- See Also:
-
COUNTER
-
_random
-
_weakRandom
protected boolean _weakRandom -
_workerName
-
_workerAttr
-
_reseed
protected long _reseed -
_server
-
_houseKeeper
-
_ownHouseKeeper
protected boolean _ownHouseKeeper
-
-
Constructor Details
-
DefaultSessionIdManager
- Parameters:
server
- the server associated with the id manager
-
DefaultSessionIdManager
- Parameters:
server
- the server associated with the id managerrandom
- a random number generator to use for ids
-
-
Method Details
-
setServer
- Parameters:
server
- the server associated with this id manager
-
getServer
- Returns:
- the server associated with this id manager
-
setSessionHouseKeeper
- Specified by:
setSessionHouseKeeper
in interfaceSessionIdManager
- Parameters:
houseKeeper
- the housekeeper
-
getSessionHouseKeeper
- Specified by:
getSessionHouseKeeper
in interfaceSessionIdManager
- Returns:
- the housekeeper
-
getWorkerName
Get the workname. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer.- Specified by:
getWorkerName
in interfaceSessionIdManager
- Returns:
- name or null
-
setWorkerName
Set the workername. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer. A worker name starting with $ is used as a request attribute name to lookup the worker name that can be dynamically set by a request Customizer.- Parameters:
workerName
- the name of the worker, if null it is coerced to empty string
-
getRandom
- Returns:
- the random number generator
-
setRandom
- Parameters:
random
- a random number generator for generating ids
-
getReseed
public long getReseed()- Returns:
- the reseed probability
-
setReseed
public void setReseed(long reseed) Set the reseed probability.- Parameters:
reseed
- If non zero then when a random long modulo the reseed value == 1, theSecureRandom
will be reseeded.
-
newSessionId
Create a new session id if necessary.- Specified by:
newSessionId
in interfaceSessionIdManager
- Parameters:
request
- the request with the sesioncreated
- the timestamp for when the session was created- Returns:
- the new session id
-
newSessionId
- Parameters:
seedTerm
- the seed for RNG- Returns:
- a new unique session id
-
isIdInUse
- Specified by:
isIdInUse
in interfaceSessionIdManager
- Parameters:
id
- The plain session ID (ie no workername extension)- Returns:
- True if the session ID is in use by at least one context.
-
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
-
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
-
initRandom
public void initRandom()Set up a random number generator for the sessionids. By preference, use a SecureRandom but allow to be injected. -
getExtendedId
Get the session ID with any worker ID.- Specified by:
getExtendedId
in interfaceSessionIdManager
- Parameters:
clusterId
- the cluster idrequest
- the request- Returns:
- sessionId plus any worker ID.
-
getId
Get the session ID without any worker ID.- Specified by:
getId
in interfaceSessionIdManager
- Parameters:
extendedId
- the session id with the worker extension- Returns:
- sessionId without any worker ID.
-
expireAll
Remove an id from use by telling all contexts to remove a session with this id.- Specified by:
expireAll
in interfaceSessionIdManager
- Parameters:
id
- The session ID without any cluster node extension- See Also:
-
invalidateAll
Description copied from interface:SessionIdManager
Invalidate all sessions on all contexts that share the same id.- Specified by:
invalidateAll
in interfaceSessionIdManager
- Parameters:
id
- the session id
-
renewSessionId
public String renewSessionId(String oldClusterId, String oldNodeId, jakarta.servlet.http.HttpServletRequest request) Generate a new id for a session and update across all SessionManagers.- Specified by:
renewSessionId
in interfaceSessionIdManager
- Parameters:
oldClusterId
- the old plain session idoldNodeId
- the old fully qualified idrequest
- the request containing the session- Returns:
- the new session id
-
getSessionHandlers
Get SessionHandler for every context.- Specified by:
getSessionHandlers
in interfaceSessionIdManager
- Returns:
- all SessionHandlers that are running
-
toString
- Overrides:
toString
in classAbstractLifeCycle
-