Package net.shibboleth.sp.state
Class AbstractStateManager
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,StateManager
- Direct Known Subclasses:
CookieStateManager,PassthroughStateManager,StorageServiceStateManager
public abstract class AbstractStateManager
extends AbstractIdentifiableInitializableComponent
implements StateManager
Base class for
StateManager implementations.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DataSealerOptional component to protect the data from tampering/visibility.private DurationExpiration for state tokens.private NonnullSupplier<HttpServletRequest>Supplier for the servlet request to read from.private IdentifierGenerationStrategyIdentifier generation.private final org.slf4j.LoggerClass logger.private com.fasterxml.jackson.databind.ObjectMapperJSON object mapper.private StringOptional prefix to attach to token.private ReplayCacheOptional component to prevent replay of state. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected abstract StringdoPreserve(Agent agent, Application application, String data, boolean sealed) Subclasses implement this method to preserve the transformed data in whatever way is necessary and return a token.protected abstract StringdoRecover(Agent agent, Application application, String stateToken, boolean sealed) Subclasses implement this method to recover the stored data in whatever way is necessary and return the supplied data string as a successful result.protected StringGenerate a state token.protected StringGet the current client address if available.Gets theDataSealerto use to protect data from tampering/visbility.Get the expiration limit for state tokens.GetIdentifierGenerationStrategyto use.Gets theReplayCacheto use to prevent replay of state.preserveToStateToken(Agent agent, Application application, StateData data) Preserves data while transforming it into a state token.<T extends StateData>
TrecoverFromStateToken(Agent agent, Application application, String token, Class<T> type) Recovers stored data from a state token.voidsetDataSealer(DataSealer sealer) Sets theDataSealerto use to protect data from tampering/visbility.voidsetExpiration(Duration exp) Set the expiration limit for state tokens.voidsetHttpServletRequestSupplier(NonnullSupplier<HttpServletRequest> requestSupplier) Set the Supplier for the servlet request to read from.voidSetIdentifierGenerationStrategyto use.voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Set the JSONObjectMapperto use for serialization.voidSets optional prefix to apply to the token.voidsetReplayCache(ReplayCache cache) Sets theReplayCacheto use to prevent replay of state.Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getId
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
httpRequestSupplier
Supplier for the servlet request to read from. -
identifierStrategy
Identifier generation. -
prefix
Optional prefix to attach to token. -
objectMapper
JSON object mapper. -
dataSealer
Optional component to protect the data from tampering/visibility. -
replayCache
Optional component to prevent replay of state. -
expiration
Expiration for state tokens.
-
-
Constructor Details
-
AbstractStateManager
public AbstractStateManager()Constructor.
-
-
Method Details
-
getIdentifierGenerationStrategy
GetIdentifierGenerationStrategyto use.- Returns:
- identifier generator strategy
-
setPrefix
Sets optional prefix to apply to the token.- Parameters:
s- prefix string
-
setObjectMapper
public void setObjectMapper(@Nonnull com.fasterxml.jackson.databind.ObjectMapper mapper) Set the JSONObjectMapperto use for serialization.- Parameters:
mapper- object mapper
-
getDataSealer
Gets theDataSealerto use to protect data from tampering/visbility.- Returns:
- data sealer or null
-
getReplayCache
Gets theReplayCacheto use to prevent replay of state.- Returns:
- replay cache or null
-
setReplayCache
Sets theReplayCacheto use to prevent replay of state.This is an additional layer of protection over and above the clearing of state that takes place routinely.
- Parameters:
cache- replay cache
-
getExpiration
Get the expiration limit for state tokens.- Returns:
- expiration limit
-
setExpiration
Set the expiration limit for state tokens.Defaults to PT30M.
- Parameters:
exp- expiration limit
-
doInitialize
- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException
-
preserveToStateToken
@Nonnull public String preserveToStateToken(@Nonnull Agent agent, @Nonnull Application application, @Nonnull StateData data) throws IOException Preserves data while transforming it into a state token.- Specified by:
preserveToStateTokenin interfaceStateManager- Parameters:
agent- agent owning the stateapplication- application owning the statedata- data to preserve- Returns:
- state token representing value
- Throws:
IOException- if creation of token fails
-
recoverFromStateToken
@Nullable public <T extends StateData> T recoverFromStateToken(@Nonnull Agent agent, @Nonnull Application application, @Nonnull @NotEmpty String token, @Nonnull Class<T> type) throws IOException Recovers stored data from a state token.In most implementations, the state token mapping should be cleared on successful use of this method.
- Specified by:
recoverFromStateTokenin interfaceStateManager- Type Parameters:
T- type of state- Parameters:
agent- agent owning the stateapplication- application owning the statetoken- state tokentype- specific subtype ofStateDatato recover- Returns:
- the recovered data, or null if unable to recover without underlying cause
- Throws:
IOException- if recovery from token fails
-
doPreserve
@Nonnull protected abstract String doPreserve(@Nonnull Agent agent, @Nonnull Application application, @Nonnull String data, boolean sealed) throws IOException Subclasses implement this method to preserve the transformed data in whatever way is necessary and return a token.- Parameters:
agent- agent owning the stateapplication- application owning the statedata- data to preservesealed- whether the data was sealed (and thus base64-encoded)- Returns:
- the state token
- Throws:
IOException- if an error occurs
-
doRecover
@Nullable protected abstract String doRecover(@Nonnull Agent agent, @Nonnull Application application, @Nonnull @NotEmpty String stateToken, boolean sealed) throws IOException Subclasses implement this method to recover the stored data in whatever way is necessary and return the supplied data string as a successful result.The implementation should ensure when possible that this method works only once for a given state token.
Subclasses may assume that the state token inputs they receive will have been returned by them via the
doPreserve(Agent, Application, String, boolean)method.- Parameters:
agent- agent owning the stateapplication- application owning the statestateToken- the state token to map from/clearsealed- whether the data was sealed (and thus base64-encoded)- Returns:
- the recovered data, or null if unable to recover without underlying cause
- Throws:
IOException- if an error occurs
-
generateToken
Generate a state token.- Returns:
- a new state token
-
getClientAddress
Get the current client address if available.- Returns:
- client address or null