Class RolloverSignerSecretProvider
java.lang.Object
org.apache.hadoop.security.authentication.util.SignerSecretProvider
org.apache.hadoop.security.authentication.util.RolloverSignerSecretProvider
- Direct Known Subclasses:
RandomSignerSecretProvider,ZKSignerSecretProvider
An abstract SignerSecretProvider that can be use used as the base for a
rolling secret. The secret will roll over at the same interval as the token
validity, so there are only ever a maximum of two valid secrets at any
given time. This class handles storing and returning the secrets, as well
as the rolling over. At a minimum, subclasses simply need to implement the
generateNewSecret() method. More advanced implementations can override
other methods to provide more advanced behavior, but should be careful when
doing so.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Will be called on shutdown; subclasses should perform any cleanup here.protected abstract byte[]Subclasses should implement this to return a new secret.byte[][]Returns all secrets that a cookie could have been signed with and are still valid; this should include the secret returned by getCurrentSecret().byte[]Returns the current secret to be used by the Signer for signing new cookies.voidinit(Properties config, javax.servlet.ServletContext servletContext, long tokenValidity) Initialize the SignerSecretProvider.protected voidinitSecrets(byte[] currentSecret, byte[] previousSecret) Initializes the secrets array.protected voidRolls the secret.protected voidstartScheduler(long initialDelay, long period) Starts the scheduler for the rollover to run at an interval.
-
Constructor Details
-
RolloverSignerSecretProvider
public RolloverSignerSecretProvider()
-
-
Method Details
-
init
public void init(Properties config, javax.servlet.ServletContext servletContext, long tokenValidity) throws Exception Initialize the SignerSecretProvider. It initializes the current secret and starts the scheduler for the rollover to run at an interval of tokenValidity.- Specified by:
initin classSignerSecretProvider- Parameters:
config- configuration propertiesservletContext- servlet contexttokenValidity- The amount of time a token is valid for- Throws:
Exception- thrown if an error occurred
-
initSecrets
protected void initSecrets(byte[] currentSecret, byte[] previousSecret) Initializes the secrets array. This should typically be called only once, during init but some implementations may wish to call it other times. previousSecret can be null if there isn't a previous secret, but currentSecret should never be null.- Parameters:
currentSecret- The current secretpreviousSecret- The previous secret
-
startScheduler
protected void startScheduler(long initialDelay, long period) Starts the scheduler for the rollover to run at an interval.- Parameters:
initialDelay- The initial delay in the rollover in millisecondsperiod- The interval for the rollover in milliseconds
-
destroy
public void destroy()Description copied from class:SignerSecretProviderWill be called on shutdown; subclasses should perform any cleanup here.- Overrides:
destroyin classSignerSecretProvider
-
rollSecret
protected void rollSecret()Rolls the secret. It is called automatically at the rollover interval. -
generateNewSecret
protected abstract byte[] generateNewSecret()Subclasses should implement this to return a new secret. It will be called automatically at the secret rollover interval. It should never return null.- Returns:
- a new secret
-
getCurrentSecret
public byte[] getCurrentSecret()Description copied from class:SignerSecretProviderReturns the current secret to be used by the Signer for signing new cookies. This should never return null.Callers should be careful not to modify the returned value.
- Specified by:
getCurrentSecretin classSignerSecretProvider- Returns:
- the current secret
-
getAllSecrets
public byte[][] getAllSecrets()Description copied from class:SignerSecretProviderReturns all secrets that a cookie could have been signed with and are still valid; this should include the secret returned by getCurrentSecret().Callers should be careful not to modify the returned value.
- Specified by:
getAllSecretsin classSignerSecretProvider- Returns:
- the secrets
-