Class SessionIdGeneratorBase
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.SessionIdGeneratorBase
- All Implemented Interfaces:
Lifecycle, SessionIdGenerator
- Direct Known Subclasses:
StandardSessionIdGenerator
Base implementation of
SessionIdGenerator that manages a pool of
SecureRandom instances for generating session identifiers.-
Nested Class Summary
Nested classes/interfaces inherited from interface Lifecycle
Lifecycle.SingleUse -
Field Summary
FieldsFields inherited from interface Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstruct a new SessionIdGeneratorBase instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSubclasses implement this method to perform any instance destruction required.Generate a new session ID using the configured jvmRoute.Returns the node identifier associated with this node which will be included in the generated session ID.protected voidgetRandomBytes(byte[] bytes) Fill the given byte array with random bytes using a pooledSecureRandominstance.Get the name of the algorithm used to create theSecureRandominstances which generate new session IDs.Get the class name of theSecureRandomimplementation used to generate session IDs.Get the name of the provider used to create theSecureRandominstances which generate new session IDs.intReturns the number of bytes for a session ID.protected voidSubclasses implement this method to perform any instance initialisation required.voidsetJvmRoute(String jvmRoute) Set the node identifier used when generating session IDs in a clustered environment.voidsetSecureRandomAlgorithm(String secureRandomAlgorithm) Specify a non-default algorithm to use to create instances ofSecureRandomwhich are used to generate session IDs.voidsetSecureRandomClass(String secureRandomClass) Specify a non-defaultSecureRandomimplementation to use.voidsetSecureRandomProvider(String secureRandomProvider) Specify a non-default provider to use to create instances ofSecureRandomwhich are used to generate session IDs.voidsetSessionIdLength(int sessionIdLength) Set the number of bytes used for a session ID.protected voidSubclasses must ensure that the state is changed toLifecycleState.STARTINGduring the execution of this method.protected voidSubclasses must ensure that the state is changed toLifecycleState.STOPPINGduring the execution of this method.Methods inherited from class LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SessionIdGenerator
generateSessionId
-
Field Details
-
DEFAULT_SECURE_RANDOM_ALGORITHM
The default SecureRandom algorithm. SHA1PRNG if available, otherwise the platform default.
-
-
Constructor Details
-
SessionIdGeneratorBase
protected SessionIdGeneratorBase()Construct a new SessionIdGeneratorBase instance.
-
-
Method Details
-
getSecureRandomClass
Get the class name of theSecureRandomimplementation used to generate session IDs.- Returns:
- The fully qualified class name.
nullindicates that the JRE providedSecureRandomimplementation will be used
-
setSecureRandomClass
Specify a non-defaultSecureRandomimplementation to use. The implementation must be self-seeding and have a zero-argument constructor. If not specified, an instance ofSecureRandomwill be generated.- Parameters:
secureRandomClass- The fully-qualified class name
-
getSecureRandomAlgorithm
Get the name of the algorithm used to create theSecureRandominstances which generate new session IDs.- Returns:
- The name of the algorithm.
nullor the empty string means that platform default will be used
-
setSecureRandomAlgorithm
Specify a non-default algorithm to use to create instances ofSecureRandomwhich are used to generate session IDs. If no algorithm is specified, SHA1PRNG will be used. If SHA1PRNG is not available, the platform default will be used. To use the platform default (which may be SHA1PRNG), specifynullor the empty string. If an invalid algorithm and/or provider is specified theSecureRandominstances will be created using the defaults for thisSessionIdGeneratorimplementation. If that fails, theSecureRandominstances will be created using platform defaults.- Parameters:
secureRandomAlgorithm- The name of the algorithm
-
getSecureRandomProvider
Get the name of the provider used to create theSecureRandominstances which generate new session IDs.- Returns:
- The name of the provider.
nullor the empty string means that platform default will be used
-
setSecureRandomProvider
Specify a non-default provider to use to create instances ofSecureRandomwhich are used to generate session IDs. If no provider is specified, the platform default is used. To use the platform default specifynullor the empty string. If an invalid algorithm and/or provider is specified theSecureRandominstances will be created using the defaults for thisSessionIdGeneratorimplementation. If that fails, theSecureRandominstances will be created using platform defaults.- Parameters:
secureRandomProvider- The name of the provider
-
getJvmRoute
Description copied from interface:SessionIdGeneratorReturns the node identifier associated with this node which will be included in the generated session ID.- Specified by:
getJvmRoutein interfaceSessionIdGenerator- Returns:
- the node identifier used when generating session IDs in a clustered environment
-
setJvmRoute
Set the node identifier used when generating session IDs in a clustered environment.- Specified by:
setJvmRoutein interfaceSessionIdGenerator- Parameters:
jvmRoute- the node identifier
-
getSessionIdLength
public int getSessionIdLength()Description copied from interface:SessionIdGeneratorReturns the number of bytes for a session ID.- Specified by:
getSessionIdLengthin interfaceSessionIdGenerator- Returns:
- the number of bytes used for a session ID
-
setSessionIdLength
public void setSessionIdLength(int sessionIdLength) Set the number of bytes used for a session ID.- Specified by:
setSessionIdLengthin interfaceSessionIdGenerator- Parameters:
sessionIdLength- the number of bytes
-
generateSessionId
Generate a new session ID using the configured jvmRoute.- Specified by:
generateSessionIdin interfaceSessionIdGenerator- Returns:
- the newly generated session ID
-
getRandomBytes
protected void getRandomBytes(byte[] bytes) Fill the given byte array with random bytes using a pooledSecureRandominstance.- Parameters:
bytes- the byte array to fill with random data
-
initInternal
Description copied from class:LifecycleBaseSubclasses implement this method to perform any instance initialisation required.- Specified by:
initInternalin classLifecycleBase- Throws:
LifecycleException- If the initialisation fails
-
startInternal
Description copied from class:LifecycleBaseSubclasses must ensure that the state is changed toLifecycleState.STARTINGduring the execution of this method. Changing state will trigger theLifecycle.START_EVENTevent. If a component fails to start it may either throw aLifecycleExceptionwhich will cause it's parent to fail to start, or it can place itself in the error state in which caseLifecycleBase.stop()will be called on the failed component but the parent component will continue to start normally.- Specified by:
startInternalin classLifecycleBase- Throws:
LifecycleException- Start error occurred
-
stopInternal
Description copied from class:LifecycleBaseSubclasses must ensure that the state is changed toLifecycleState.STOPPINGduring the execution of this method. Changing state will trigger theLifecycle.STOP_EVENTevent.- Specified by:
stopInternalin classLifecycleBase- Throws:
LifecycleException- Stop error occurred
-
destroyInternal
Description copied from class:LifecycleBaseSubclasses implement this method to perform any instance destruction required.- Specified by:
destroyInternalin classLifecycleBase- Throws:
LifecycleException- If the destruction fails
-