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.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected HouseKeeperprotected booleanprotected Randomprotected longprotected Serverprotected booleanprotected Stringprotected Stringprotected static final AtomicLong -
Constructor Summary
ConstructorsConstructorDescriptionDefaultSessionIdManager(Server server) DefaultSessionIdManager(Server server, Random random) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.voidRemove 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.longGet SessionHandler for every context.Get the workname.voidSet up a random number generator for the sessionids.voidinvalidateAll(String id) Invalidate all sessions on all contexts that share the same id.booleannewSessionId(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.voidvoidsetReseed(long reseed) Set the reseed probability.voidvoidsetSessionHouseKeeper(HouseKeeper houseKeeper) voidsetWorkerName(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, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpableMethods 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:
setSessionHouseKeeperin interfaceSessionIdManager- Parameters:
houseKeeper- the housekeeper
-
getSessionHouseKeeper
- Specified by:
getSessionHouseKeeperin 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:
getWorkerNamein 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, theSecureRandomwill be reseeded.
-
newSessionId
Create a new session id if necessary.- Specified by:
newSessionIdin 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:
isIdInUsein 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:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin 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: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
-
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:
getExtendedIdin 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:
getIdin 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:
expireAllin interfaceSessionIdManager- Parameters:
id- The session ID without any cluster node extension- See Also:
-
invalidateAll
Description copied from interface:SessionIdManagerInvalidate all sessions on all contexts that share the same id.- Specified by:
invalidateAllin 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:
renewSessionIdin 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:
getSessionHandlersin interfaceSessionIdManager- Returns:
- all SessionHandlers that are running
-
toString
- Overrides:
toStringin classAbstractLifeCycle
-