Class ClientStorageService
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
-
- org.opensaml.storage.AbstractStorageService
-
- org.opensaml.storage.AbstractMapBackedStorageService
-
- org.opensaml.storage.impl.client.ClientStorageService
-
- All Implemented Interfaces:
javax.servlet.Filter,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,StorageCapabilities,StorageCapabilitiesEx,StorageService
public class ClientStorageService extends AbstractMapBackedStorageService implements javax.servlet.Filter, StorageCapabilitiesEx
Implementation ofStorageServicethat stores data in-memory in a shared session attribute.The data for this service is managed in a
ClientStorageServiceStoreobject, 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 Classes Modifier and Type Class Description static classClientStorageService.ClientStorageSourceEnumeration of possible sources for the data.
-
Field Summary
Fields Modifier and Type Field Description private Map<ClientStorageService.ClientStorageSource,Integer>capabilityMapSizes to report for context, key, and value limits when particular sources are used.private CookieManagercookieManagerManages creation of cookies.private DataSealerdataSealerDataSealer instance to secure data.private static StringDEFAULT_STORAGE_NAMEDefault label for storage tracking.private NonnullSupplier<javax.servlet.http.HttpServletRequest>httpServletRequestSupplierServlet request Supplier.private DataSealerKeyStrategykeyStrategyKeyStrategy enabling us to detect whether data has been sealed with an older key.protected static StringLOCK_ATTRIBUTEName of session attribute for session lock.private org.slf4j.LoggerlogClass logger.protected static StringSTORAGE_ATTRIBUTEName of session attribute for storage object.private StringstorageNameLabel used to track storage.private ClientStorageServiceStore.FactorystoreFactoryFactory for backing store.
-
Constructor Summary
Constructors Constructor Description ClientStorageService()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)protected voiddoInitialize()protected TimerTaskgetCleanupTask()Returns a cleanup task function to schedule for background cleanup.protected Map<String,Map<String,MutableStorageRecord<?>>>getContextMap()Get the map of contexts to manipulate during operations.intgetContextSize()Gets max size of context labels in characters.CookieManagergetCookieManager()Get theCookieManagerto use.DataSealergetDataSealer()Get theDataSealerto use for data security.private javax.servlet.http.HttpServletRequestgetHttpServletRequest()Get the current HTTP request if available.intgetKeySize()Gets max size of keys in characters.protected ReadWriteLockgetLock()Get the shared lock to synchronize access.(package private) StringgetLogPrefix()Get a prefix for log messages.(package private) ClientStorageService.ClientStorageSourcegetSource()Get the backing source of the loaded data.StringgetStorageName()Get the label to use for storage tracking.longgetValueSize()Gets max size of values in characters.voidinit(javax.servlet.FilterConfig filterConfig)booleanisClustered()Returns 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.booleanisServerSide()Returns 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.voidsetCapabilityMap(Map<ClientStorageService.ClientStorageSource,Integer> map)Set the map of storage sources to capability/size limits.voidsetCleanupInterval(Duration interval)Sets the time between one cleanup and another.voidsetClientStorageServiceStoreFactory(ClientStorageServiceStore.Factory factory)Set 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<javax.servlet.http.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, 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.utilities.java.support.component.AbstractIdentifiableInitializableComponent
setId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
getId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
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.utilities.java.support.component.IdentifiedComponent
getId
-
-
-
-
Field Detail
-
LOCK_ATTRIBUTE
@Nonnull protected static final String LOCK_ATTRIBUTE
Name of session attribute for session lock.- See Also:
- Constant Field Values
-
STORAGE_ATTRIBUTE
@Nonnull protected static final String STORAGE_ATTRIBUTE
Name of session attribute for storage object.- See Also:
- Constant Field Values
-
DEFAULT_STORAGE_NAME
@Nonnull @NotEmpty private static final String DEFAULT_STORAGE_NAME
Default label for storage tracking.- See Also:
- Constant Field Values
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
capabilityMap
@Nonnull @NotEmpty private Map<ClientStorageService.ClientStorageSource,Integer> capabilityMap
Sizes to report for context, key, and value limits when particular sources are used.
-
httpServletRequestSupplier
@NonnullAfterInit private NonnullSupplier<javax.servlet.http.HttpServletRequest> httpServletRequestSupplier
Servlet request Supplier.
-
cookieManager
@NonnullAfterInit private CookieManager cookieManager
Manages creation of cookies.
-
dataSealer
@NonnullAfterInit private DataSealer dataSealer
DataSealer instance to secure data.
-
keyStrategy
@Nullable private DataSealerKeyStrategy keyStrategy
KeyStrategy enabling us to detect whether data has been sealed with an older key.
-
storeFactory
@Nonnull private ClientStorageServiceStore.Factory storeFactory
Factory for backing store.
-
-
Method Detail
-
setCleanupInterval
public void setCleanupInterval(@Nullable Duration interval)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
public void setCapabilityMap(@Nonnull @NonnullElements Map<ClientStorageService.ClientStorageSource,Integer> map)
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 interfaceStorageCapabilitiesEx- 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 interfaceStorageCapabilitiesEx- Returns:
- true iff the storage implementation manages data independent of a single server node
-
setHttpServletRequestSupplier
public void setHttpServletRequestSupplier(@Nonnull NonnullSupplier<javax.servlet.http.HttpServletRequest> requestSupplier)Set the Supplier for the servlet request in which to manage per-request data.- Parameters:
requestSupplier- supplier for the servlet request in which to manage data
-
getHttpServletRequest
@Nonnull private javax.servlet.http.HttpServletRequest getHttpServletRequest()
Get the current HTTP request if available.- Returns:
- current HTTP request
-
getCookieManager
@NonnullAfterInit public CookieManager getCookieManager()
Get theCookieManagerto use.- Returns:
- the CookieManager to use
-
setCookieManager
public void setCookieManager(@Nonnull CookieManager manager)Set theCookieManagerto use.- Parameters:
manager- the CookieManager to use.
-
getStorageName
@Nonnull @NotEmpty public String getStorageName()
Get the label to use for storage tracking.- Returns:
- label to use
-
setStorageName
public void setStorageName(@Nonnull @NotEmpty String name)
Set the label to use for storage tracking.- Parameters:
name- label to use
-
getDataSealer
@NonnullAfterInit public DataSealer getDataSealer()
Get theDataSealerto use for data security.- Returns:
DataSealerto use for data security
-
setDataSealer
public void setDataSealer(@Nonnull DataSealer sealer)Set theDataSealerto use for data security.- Parameters:
sealer-DataSealerto use for data security
-
setKeyStrategy
public void setKeyStrategy(@Nullable DataSealerKeyStrategy strategy)Set theDataSealerKeyStrategyto use for stale key detection.- Parameters:
strategy-DataSealerKeyStrategyto use for stale key detection
-
setClientStorageServiceStoreFactory
public void setClientStorageServiceStoreFactory(@Nonnull ClientStorageServiceStore.Factory factory)Set the backing storeClientStorageServiceStore.Factoryto use.- Parameters:
factory- factory to use
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
IOExceptionjavax.servlet.ServletException
-
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
protected void doInitialize() throws ComponentInitializationException- Overrides:
doInitializein classAbstractStorageService- Throws:
ComponentInitializationException
-
getCleanupTask
@Nullable protected TimerTask 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
@Nonnull protected ReadWriteLock getLock()
Get the shared lock to synchronize access.- Specified by:
getLockin classAbstractMapBackedStorageService- Returns:
- shared lock
-
getContextMap
@Nonnull @NonnullElements @Live protected Map<String,Map<String,MutableStorageRecord<?>>> getContextMap() throws IOException
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
protected void setDirty() throws IOExceptionA 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
@Nonnull ClientStorageService.ClientStorageSource getSource() throws IOException
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
boolean isLoaded() throws IOExceptionCheck 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
void load(@Nullable @NotEmpty String raw, @Nonnull ClientStorageService.ClientStorageSource source)
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
@Nullable ClientStorageServiceOperation 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
-
-