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 enum
Enumeration 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 CookieManager
Manages creation of cookies.private DataSealer
DataSealer instance to secure data.private static final String
Default label for storage tracking.private NonnullSupplier<HttpServletRequest>
Servlet request Supplier.private DataSealerKeyStrategy
KeyStrategy enabling us to detect whether data has been sealed with an older key.protected static final String
Name of session attribute for session lock.private final org.slf4j.Logger
Class logger.protected static final String
Name of session attribute for storage object.private String
Label used to track storage.Factory for backing store. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
doFilter
(ServletRequest request, ServletResponse response, FilterChain chain) protected void
protected TimerTask
Returns a cleanup task function to schedule for background cleanup.protected Map<String,
Map<String, MutableStorageRecord<?>>> Get the map of contexts to manipulate during operations.int
Gets max size of context labels in characters.Get theCookieManager
to use.Get theDataSealer
to use for data security.private HttpServletRequest
Get the current HTTP request if available.int
Gets max size of keys in characters.protected ReadWriteLock
getLock()
Get the shared lock to synchronize access.(package private) String
Get a prefix for log messages.(package private) ClientStorageService.ClientStorageSource
Get the backing source of the loaded data.Get the label to use for storage tracking.long
Gets max size of values in characters.void
init
(FilterConfig filterConfig) boolean
Returns true iff the storage implementation manages data independent of a single server node.(package private) boolean
isLoaded()
Check whether data from the client has been loaded into the current session.boolean
Returns true iff the storage implementation manages data independent of the client.(package private) void
load
(String raw, ClientStorageService.ClientStorageSource source) Reconstitute stored data and inject it into the session.(package private) ClientStorageServiceOperation
save()
Serialize the stored data if it's in a "modified/dirty" state.void
Set the map of storage sources to capability/size limits.void
setCleanupInterval
(Duration interval) Sets the time between one cleanup and another.void
Set the backing storeClientStorageServiceStore.Factory
to use.void
setCookieManager
(CookieManager manager) Set theCookieManager
to use.void
setDataSealer
(DataSealer sealer) Set theDataSealer
to use for data security.protected void
setDirty()
A callback to indicate that data has been modified.void
setHttpServletRequestSupplier
(NonnullSupplier<HttpServletRequest> requestSupplier) Set the Supplier for the servlet request in which to manage per-request data.void
setKeyStrategy
(DataSealerKeyStrategy strategy) Set theDataSealerKeyStrategy
to use for stale key detection.void
setStorageName
(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, updateWithVersion
Methods inherited from class org.opensaml.storage.AbstractStorageService
create, create, delete, deleteWithVersion, doDestroy, getCapabilities, getCleanupInterval, getCleanupTaskTimer, read, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersion
Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setId
Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException
Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, initialize, isDestroyed, isInitialized
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getId
Methods 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:
setCleanupInterval
in 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:
isServerSide
in 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:
isClustered
in 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 theCookieManager
to 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 theDataSealer
to use for data security.- Returns:
DataSealer
to use for data security
-
setClientStorageServiceStoreFactory
Set the backing storeClientStorageServiceStore.Factory
to use.- Parameters:
factory
- factory to use
-
init
- Specified by:
init
in interfaceFilter
- Throws:
ServletException
-
doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - Specified by:
doFilter
in interfaceFilter
- Throws:
IOException
ServletException
-
getContextSize
public int getContextSize()Gets max size of context labels in characters.- Specified by:
getContextSize
in interfaceStorageCapabilities
- Overrides:
getContextSize
in classAbstractStorageService
- Returns:
- max size of context labels in characters
-
getKeySize
public int getKeySize()Gets max size of keys in characters.- Specified by:
getKeySize
in interfaceStorageCapabilities
- Overrides:
getKeySize
in classAbstractStorageService
- Returns:
- max size of keys in characters
-
getValueSize
public long getValueSize()Gets max size of values in characters.- Specified by:
getValueSize
in interfaceStorageCapabilities
- Overrides:
getValueSize
in classAbstractStorageService
- Returns:
- max size of values in characters
-
doInitialize
- Overrides:
doInitialize
in classAbstractStorageService
- Throws:
ComponentInitializationException
-
getCleanupTask
Returns a cleanup task function to schedule for background cleanup.The default implementation does not supply one.
- Overrides:
getCleanupTask
in classAbstractStorageService
- Returns:
- a task object, or null
-
getLock
Get the shared lock to synchronize access.- Specified by:
getLock
in 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:
getContextMap
in 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:
setDirty
in 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
HttpSession
contains 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
-