Class ClientStorageService
- All Implemented Interfaces:
Filter,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,EnumeratableStorageService,StorageCapabilities,StorageService
StorageService that stores data in-memory in a
shared session attribute.
The data for this service is managed in a ClientStorageServiceStore object, which must
be created by some operation within the container for this implementation to function. Actual
load/store of the data to/from that object is driven via companion classes. The serialization
of data is inside the storage object class, but the encryption/decryption is here.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of possible sources for the data. -
Field Summary
FieldsModifier and TypeFieldDescriptionSizes to report for context, key, and value limits when particular sources are used.private CookieManagerManages creation of cookies.private DataSealerDataSealer instance to secure data.private static final StringDefault label for storage tracking.private NonnullSupplier<HttpServletRequest>Servlet request Supplier.private DataSealerKeyStrategyKeyStrategy enabling us to detect whether data has been sealed with an older key.protected static final StringName of session attribute for session lock.private final org.slf4j.LoggerClass logger.protected static final StringName of session attribute for storage object.private StringLabel used to track storage.Factory for backing store. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddoFilter(ServletRequest request, ServletResponse response, FilterChain chain) protected voidprotected TimerTaskReturns a cleanup task function to schedule for background cleanup.protected Map<String,Map<String, MutableStorageRecord<?>>> Get the map of contexts to manipulate during operations.intGets max size of context labels in characters.Get theCookieManagerto use.Get theDataSealerto use for data security.private HttpServletRequestGet the current HTTP request if available.intGets max size of keys in characters.protected ReadWriteLockgetLock()Get the shared lock to synchronize access.(package private) StringGet a prefix for log messages.(package private) ClientStorageService.ClientStorageSourceGet the backing source of the loaded data.Get the label to use for storage tracking.longGets max size of values in characters.voidinit(FilterConfig filterConfig) booleanReturns true iff the storage implementation manages data independent of a single server node.(package private) booleanisLoaded()Check whether data from the client has been loaded into the current session.booleanReturns true iff the storage implementation manages data independent of the client.(package private) voidload(String raw, ClientStorageService.ClientStorageSource source) Reconstitute stored data and inject it into the session.(package private) ClientStorageServiceOperationsave()Serialize the stored data if it's in a "modified/dirty" state.voidSet the map of storage sources to capability/size limits.voidsetCleanupInterval(Duration interval) Sets the time between one cleanup and another.voidSet the backing storeClientStorageServiceStore.Factoryto use.voidsetCookieManager(CookieManager manager) Set theCookieManagerto use.voidsetDataSealer(DataSealer sealer) Set theDataSealerto use for data security.protected voidsetDirty()A callback to indicate that data has been modified.voidsetHttpServletRequestSupplier(NonnullSupplier<HttpServletRequest> requestSupplier) Set the Supplier for the servlet request in which to manage per-request data.voidsetKeyStrategy(DataSealerKeyStrategy strategy) Set theDataSealerKeyStrategyto use for stale key detection.voidsetStorageName(String name) Set the label to use for storage tracking.Methods inherited from class org.opensaml.storage.AbstractMapBackedStorageService
create, delete, deleteContext, deleteImpl, deleteWithVersion, getContextKeys, read, read, readImpl, reap, reapWithLock, update, updateContextExpiration, updateExpiration, updateImpl, updateWithVersionMethods inherited from class org.opensaml.storage.AbstractStorageService
create, create, delete, deleteWithVersion, doDestroy, getCapabilities, getCleanupInterval, getCleanupTaskTimer, read, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersionMethods 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, 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
getIdMethods inherited from interface org.opensaml.storage.StorageService
create, create, delete, deleteWithVersion, getCapabilities, read, update, update, updateExpiration, updateWithVersion, updateWithVersion
-
Field Details
-
LOCK_ATTRIBUTE
Name of session attribute for session lock.- See Also:
-
STORAGE_ATTRIBUTE
Name of session attribute for storage object.- See Also:
-
DEFAULT_STORAGE_NAME
Default label for storage tracking.- See Also:
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
capabilityMap
Sizes to report for context, key, and value limits when particular sources are used. -
httpServletRequestSupplier
Servlet request Supplier. -
cookieManager
Manages creation of cookies. -
storageName
Label used to track storage. -
dataSealer
DataSealer instance to secure data. -
keyStrategy
KeyStrategy enabling us to detect whether data has been sealed with an older key. -
storeFactory
Factory for backing store.
-
-
Constructor Details
-
ClientStorageService
public ClientStorageService()Constructor.
-
-
Method Details
-
setCleanupInterval
Sets the time between one cleanup and another. A value of 0 indicates that no cleanup will be performed. This setting cannot be changed after the service has been initialized.- Overrides:
setCleanupIntervalin classAbstractStorageService- Parameters:
interval- time between one cleanup and another
-
setCapabilityMap
Set the map of storage sources to capability/size limits.The defaults include 4192 characters for cookies and 1024^2 characters for local storage.
- Parameters:
map- capability map
-
isServerSide
public boolean isServerSide()Returns true iff the storage implementation manages data independent of the client.- Specified by:
isServerSidein interfaceStorageCapabilities- Returns:
- true iff the storage implementation manages data independent of the client
-
isClustered
public boolean isClustered()Returns true iff the storage implementation manages data independent of a single server node.- Specified by:
isClusteredin interfaceStorageCapabilities- Returns:
- true iff the storage implementation manages data independent of a single server node
-
getHttpServletRequest
Get the current HTTP request if available.- Returns:
- current HTTP request
-
getCookieManager
Get theCookieManagerto use.- Returns:
- the CookieManager to use
-
getStorageName
Get the label to use for storage tracking.- Returns:
- label to use
-
setStorageName
Set the label to use for storage tracking.- Parameters:
name- label to use
-
getDataSealer
Get theDataSealerto use for data security.- Returns:
DataSealerto use for data security
-
setClientStorageServiceStoreFactory
Set the backing storeClientStorageServiceStore.Factoryto use.- Parameters:
factory- factory to use
-
init
- Specified by:
initin interfaceFilter- Throws:
ServletException
-
doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - Specified by:
doFilterin interfaceFilter- Throws:
IOExceptionServletException
-
getContextSize
public int getContextSize()Gets max size of context labels in characters.- Specified by:
getContextSizein interfaceStorageCapabilities- Overrides:
getContextSizein classAbstractStorageService- Returns:
- max size of context labels in characters
-
getKeySize
public int getKeySize()Gets max size of keys in characters.- Specified by:
getKeySizein interfaceStorageCapabilities- Overrides:
getKeySizein classAbstractStorageService- Returns:
- max size of keys in characters
-
getValueSize
public long getValueSize()Gets max size of values in characters.- Specified by:
getValueSizein interfaceStorageCapabilities- Overrides:
getValueSizein classAbstractStorageService- Returns:
- max size of values in characters
-
doInitialize
- Overrides:
doInitializein classAbstractStorageService- Throws:
ComponentInitializationException
-
getCleanupTask
Returns a cleanup task function to schedule for background cleanup.The default implementation does not supply one.
- Overrides:
getCleanupTaskin classAbstractStorageService- Returns:
- a task object, or null
-
getLock
Get the shared lock to synchronize access.- Specified by:
getLockin classAbstractMapBackedStorageService- Returns:
- shared lock
-
getContextMap
@Nonnull @Live protected Map<String,Map<String, getContextMap() throws IOExceptionMutableStorageRecord<?>>> Get the map of contexts to manipulate during operations.This method is guaranteed to be called under cover the lock returned by {
AbstractMapBackedStorageService.getLock().- Specified by:
getContextMapin classAbstractMapBackedStorageService- Returns:
- map of contexts to manipulate
- Throws:
IOException- to signal errors
-
setDirty
A callback to indicate that data has been modified.This method is guaranteed to be called under cover the lock returned by {
AbstractMapBackedStorageService.getLock().- Overrides:
setDirtyin classAbstractMapBackedStorageService- Throws:
IOException- to signal an error
-
getSource
Get the backing source of the loaded data.This method should not be called while holding the session lock returned by
getLock().- Returns:
- the source of the loaded data
- Throws:
IOException- to signal an error
-
isLoaded
Check whether data from the client has been loaded into the current session.This method should not be called while holding the session lock returned by
getLock().- Returns:
- true iff the
HttpSessioncontains a storage object - Throws:
IOException- to signal an error
-
load
Reconstitute stored data and inject it into the session.This method should not be called while holding the session lock returned by
getLock().- Parameters:
raw- encrypted data to load as storage contents, or null if nonesource- indicates source of the data for later use
-
save
Serialize the stored data if it's in a "modified/dirty" state.This method should not be called while holding the session lock returned by
getLock().- Returns:
- if dirty, the operation to perform, if not dirty, a null value
-
getLogPrefix
Get a prefix for log messages.- Returns:
- logging prefix
-