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 javax.servlet.http.HttpServletRequesthttpServletRequestServlet request.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()protected Map<String,Map<String,MutableStorageRecord<?>>>getContextMap()intgetContextSize()CookieManagergetCookieManager()Get theCookieManagerto use.DataSealergetDataSealer()Get theDataSealerto use for data security.intgetKeySize()protected ReadWriteLockgetLock()(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()voidinit(javax.servlet.FilterConfig filterConfig)booleanisClustered()(package private) booleanisLoaded()Check whether data from the client has been loaded into the current session.booleanisServerSide()(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)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()voidsetHttpServletRequest(javax.servlet.http.HttpServletRequest request)Set 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.
-
httpServletRequest
@NonnullAfterInit private javax.servlet.http.HttpServletRequest httpServletRequest
Servlet request.
-
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)- Overrides:
setCleanupIntervalin classAbstractStorageService
-
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()
- Specified by:
isServerSidein interfaceStorageCapabilitiesEx
-
isClustered
public boolean isClustered()
- Specified by:
isClusteredin interfaceStorageCapabilitiesEx
-
setHttpServletRequest
public void setHttpServletRequest(@Nonnull javax.servlet.http.HttpServletRequest request)Set the servlet request in which to manage per-request data.- Parameters:
request- servlet request in which to manage data
-
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()
- Specified by:
getContextSizein interfaceStorageCapabilities- Overrides:
getContextSizein classAbstractStorageService
-
getKeySize
public int getKeySize()
- Specified by:
getKeySizein interfaceStorageCapabilities- Overrides:
getKeySizein classAbstractStorageService
-
getValueSize
public long getValueSize()
- Specified by:
getValueSizein interfaceStorageCapabilities- Overrides:
getValueSizein classAbstractStorageService
-
doInitialize
protected void doInitialize() throws ComponentInitializationException- Overrides:
doInitializein classAbstractStorageService- Throws:
ComponentInitializationException
-
getCleanupTask
@Nullable protected TimerTask getCleanupTask()
- Overrides:
getCleanupTaskin classAbstractStorageService
-
getLock
@Nonnull protected ReadWriteLock getLock()
- Specified by:
getLockin classAbstractMapBackedStorageService
-
getContextMap
@Nonnull @NonnullElements @Live protected Map<String,Map<String,MutableStorageRecord<?>>> getContextMap() throws IOException
- Specified by:
getContextMapin classAbstractMapBackedStorageService- Throws:
IOException
-
setDirty
protected void setDirty() throws IOException- Overrides:
setDirtyin classAbstractMapBackedStorageService- Throws:
IOException
-
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
-
-