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,org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject public class DefaultSessionIdManager extends org.eclipse.jetty.util.component.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:
HouseKeeper
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
-
Field Summary
Fields Modifier and Type Field Description protected HouseKeeper_houseKeeperprotected boolean_ownHouseKeeperprotected Random_randomprotected long_reseedprotected Server_serverprotected boolean_weakRandomprotected String_workerAttrprotected String_workerNameprotected static AtomicLongCOUNTER
-
Constructor Summary
Constructors Constructor Description DefaultSessionIdManager(Server server)DefaultSessionIdManager(Server server, Random random)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoStart()protected voiddoStop()voidexpireAll(String id)Remove an id from use by telling all contexts to remove a session with this id.StringgetExtendedId(String clusterId, HttpServletRequest request)Get the session ID with any worker ID.StringgetId(String extendedId)Get the session ID without any worker ID.RandomgetRandom()longgetReseed()ServergetServer()Set<SessionHandler>getSessionHandlers()Get SessionManager for every context.HouseKeepergetSessionHouseKeeper()StringgetWorkerName()Get the workname.voidinitRandom()Set up a random number generator for the sessionids.voidinvalidateAll(String id)Invalidate all sessions on all contexts that share the same id.booleanisIdInUse(String id)StringnewSessionId(long seedTerm)StringnewSessionId(HttpServletRequest request, long created)Create a new session id if necessary.StringrenewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request)Generate a new id for a session and update across all SessionManagers.voidsetRandom(Random random)voidsetReseed(long reseed)Set the reseed probability.voidsetServer(Server server)voidsetSessionHouseKeeper(HouseKeeper houseKeeper)voidsetWorkerName(String workerName)Set the workername.StringtoString()-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
COUNTER
protected static final AtomicLong COUNTER
-
_random
protected Random _random
-
_weakRandom
protected boolean _weakRandom
-
_workerName
protected String _workerName
-
_workerAttr
protected String _workerAttr
-
_reseed
protected long _reseed
-
_server
protected Server _server
-
_houseKeeper
protected HouseKeeper _houseKeeper
-
_ownHouseKeeper
protected boolean _ownHouseKeeper
-
-
Constructor Detail
-
DefaultSessionIdManager
public DefaultSessionIdManager(Server server)
- Parameters:
server- the server associated with the id manager
-
-
Method Detail
-
setServer
public void setServer(Server server)
- Parameters:
server- the server associated with this id manager
-
getServer
public Server getServer()
- Returns:
- the server associated with this id manager
-
setSessionHouseKeeper
public void setSessionHouseKeeper(HouseKeeper houseKeeper)
- Specified by:
setSessionHouseKeeperin interfaceSessionIdManager- Parameters:
houseKeeper- the housekeeper
-
getSessionHouseKeeper
public HouseKeeper getSessionHouseKeeper()
- Specified by:
getSessionHouseKeeperin interfaceSessionIdManager- Returns:
- the housekeeper
-
getWorkerName
@ManagedAttribute(value="unique name for this node", readonly=true) public String 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
public void setWorkerName(String workerName)
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
public Random getRandom()
- Returns:
- the random number generator
-
setRandom
public void setRandom(Random random)
- 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
public String newSessionId(HttpServletRequest request, long created)
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
- See Also:
SessionIdManager.newSessionId(javax.servlet.http.HttpServletRequest, long)
-
newSessionId
public String newSessionId(long seedTerm)
- Parameters:
seedTerm- the seed for RNG- Returns:
- a new unique session id
-
isIdInUse
public boolean isIdInUse(String id)
- 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.
- See Also:
SessionIdManager.isIdInUse(java.lang.String)
-
doStart
protected void doStart() throws Exception- Overrides:
doStartin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
Exception- See Also:
AbstractLifeCycle.doStart()
-
doStop
protected void doStop() throws Exception- Overrides:
doStopin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
Exception- See Also:
AbstractLifeCycle.doStop()
-
initRandom
public void initRandom()
Set up a random number generator for the sessionids. By preference, use a SecureRandom but allow to be injected.
-
getExtendedId
public String getExtendedId(String clusterId, HttpServletRequest request)
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
public String getId(String extendedId)
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
public void expireAll(String id)
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:
SessionIdManager.expireAll(java.lang.String)
-
invalidateAll
public void invalidateAll(String id)
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, 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
- See Also:
SessionIdManager.renewSessionId(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
-
getSessionHandlers
public Set<SessionHandler> getSessionHandlers()
Get SessionManager for every context.- Specified by:
getSessionHandlersin interfaceSessionIdManager- Returns:
- all session managers
-
toString
public String toString()
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle- See Also:
Object.toString()
-
-