public class ServletRequestScopedStorageService extends AbstractMapBackedStorageService implements RequestScopedStorageService, javax.servlet.Filter
RequestScopedStorageService that stores data in-memory in a servlet request attribute,
and reads and writes the data with a secured string form using JSON as the underlying format.| Modifier and Type | Class and Description |
|---|---|
private static class |
ServletRequestScopedStorageService.DummyReadWriteLock
Dummy shared lock that no-ops.
|
private class |
ServletRequestScopedStorageService.OutputInterceptingHttpServletResponseProxy
An implementation of
HttpServletResponse which detects a response going out
from a servlet and executes a save operation. |
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
CONTEXT_MAP_ATTRIBUTE
Name of request attribute for context map.
|
private net.shibboleth.utilities.java.support.net.CookieManager |
cookieManager
Manages creation of cookies.
|
private java.lang.String |
cookieName
Name of cookie used to track storage.
|
private net.shibboleth.utilities.java.support.security.DataSealer |
dataSealer
DataSealer instance to secure data.
|
private static java.lang.String |
DEFAULT_COOKIE_NAME
Default cookie name for storage tracking.
|
protected static java.lang.String |
DIRTY_BIT_ATTRIBUTE
Name of request attribute used as a dirty bit.
|
private static java.util.concurrent.locks.ReadWriteLock |
DUMMY_LOCK
A dummy lock implementation.
|
private javax.servlet.http.HttpServletRequest |
httpServletRequest
Servlet request.
|
private javax.servlet.http.HttpServletResponse |
httpServletResponse
Servlet response.
|
private net.shibboleth.utilities.java.support.security.DataSealerKeyStrategy |
keyStrategy
KeyStrategy enabling us to detect whether data has been sealed with an older key.
|
private org.slf4j.Logger |
log
Class logger.
|
| Constructor and Description |
|---|
ServletRequestScopedStorageService()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
create(java.lang.String context,
java.lang.String key,
java.lang.String value,
java.lang.Long expiration)
Creates a new record in the store with an expiration.
|
void |
deleteContext(java.lang.String context)
Forcibly removes all records in a given context along with any
associated resources devoted to maintaining the context.
|
protected boolean |
deleteImpl(java.lang.Long version,
java.lang.String context,
java.lang.String key)
Internal method to implement delete functions.
|
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain) |
protected void |
doInitialize() |
protected java.util.TimerTask |
getCleanupTask()
Returns a cleanup task function to schedule for background cleanup.
|
protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,MutableStorageRecord>> |
getContextMap()
Get the map of contexts to manipulate during operations.
|
java.lang.String |
getCookieName()
Get the cookie name to use for storage tracking.
|
protected java.util.concurrent.locks.ReadWriteLock |
getLock()
Get the shared lock to synchronize access.
|
void |
init(javax.servlet.FilterConfig filterConfig) |
private boolean |
isDirty()
Get the dirty bit for the current request.
|
protected void |
load()
Reconstitute stored data.
|
void |
reap(java.lang.String context)
Manually trigger a cleanup of expired records.
|
protected void |
save()
Write/preserve stored data for subsequent requests.
|
void |
setCleanupInterval(long interval)
Sets the number of milliseconds between one cleanup and another.
|
void |
setCookieManager(net.shibboleth.utilities.java.support.net.CookieManager manager)
Set the
CookieManager to use. |
void |
setCookieName(java.lang.String name)
Set the cookie name to use for storage tracking.
|
void |
setDataSealer(net.shibboleth.utilities.java.support.security.DataSealer sealer)
Set the
DataSealer to use for data security. |
private void |
setDirty(boolean flag)
Set the dirty bit for the current request.
|
void |
setHttpServletRequest(javax.servlet.http.HttpServletRequest request)
Set the servlet request in which to manage per-request data.
|
void |
setHttpServletResponse(javax.servlet.http.HttpServletResponse response)
Set the servlet response in which to manage per-request data.
|
void |
setKeyStrategy(net.shibboleth.utilities.java.support.security.DataSealerKeyStrategy strategy)
Set the
DataSealerKeyStrategy to use for stale key detection. |
void |
updateContextExpiration(java.lang.String context,
java.lang.Long expiration)
Updates the expiration time of all records in the context.
|
protected java.lang.Long |
updateImpl(java.lang.Long version,
java.lang.String context,
java.lang.String key,
java.lang.String value,
java.lang.Long expiration)
Internal method to implement update functions.
|
delete, deleteWithVersion, read, read, readImpl, reapWithLock, update, updateExpiration, updateWithVersioncreate, create, delete, deleteWithVersion, doDestroy, getCapabilities, getCleanupInterval, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersionsetIdgetIddestroy, initialize, isDestroyed, isInitializedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreate, create, delete, delete, deleteWithVersion, deleteWithVersion, getCapabilities, read, read, read, update, update, update, updateExpiration, updateExpiration, updateWithVersion, updateWithVersion, updateWithVersion@Nonnull protected static final java.lang.String CONTEXT_MAP_ATTRIBUTE
@Nonnull protected static final java.lang.String DIRTY_BIT_ATTRIBUTE
@Nonnull @NotEmpty private static final java.lang.String DEFAULT_COOKIE_NAME
@Nonnull private static final java.util.concurrent.locks.ReadWriteLock DUMMY_LOCK
@Nonnull private final org.slf4j.Logger log
@NonnullAfterInit private javax.servlet.http.HttpServletRequest httpServletRequest
@NonnullAfterInit private javax.servlet.http.HttpServletResponse httpServletResponse
@NonnullAfterInit private net.shibboleth.utilities.java.support.net.CookieManager cookieManager
@Nonnull @NotEmpty private java.lang.String cookieName
@NonnullAfterInit private net.shibboleth.utilities.java.support.security.DataSealer dataSealer
@Nullable private net.shibboleth.utilities.java.support.security.DataSealerKeyStrategy keyStrategy
public ServletRequestScopedStorageService()
public void setCleanupInterval(long interval)
setCleanupInterval in class AbstractStorageServiceinterval - number of milliseconds between one cleanup and anotherpublic void setHttpServletRequest(@Nonnull
javax.servlet.http.HttpServletRequest request)
request - servlet request in which to manage datapublic void setHttpServletResponse(@Nonnull
javax.servlet.http.HttpServletResponse response)
response - servlet response in which to manage datapublic void setCookieManager(@Nonnull
net.shibboleth.utilities.java.support.net.CookieManager manager)
CookieManager to use.manager - the CookieManager to use.@Nonnull @NotEmpty public java.lang.String getCookieName()
public void setCookieName(@Nonnull @NotEmpty
java.lang.String name)
name - cookie name to usepublic void setDataSealer(@Nonnull
net.shibboleth.utilities.java.support.security.DataSealer sealer)
DataSealer to use for data security.sealer - DataSealer to use for data securitypublic void setKeyStrategy(@Nonnull
net.shibboleth.utilities.java.support.security.DataSealerKeyStrategy strategy)
DataSealerKeyStrategy to use for stale key detection.strategy - DataSealerKeyStrategy to use for stale key detectionprotected void doInitialize()
throws net.shibboleth.utilities.java.support.component.ComponentInitializationException
doInitialize in class AbstractStorageServicenet.shibboleth.utilities.java.support.component.ComponentInitializationExceptionpublic boolean create(@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nonnull @NotEmpty
java.lang.String value,
@Nullable
java.lang.Long expiration)
throws java.io.IOException
create in interface StorageServicecreate in class AbstractMapBackedStorageServicecontext - a storage context labelkey - a key unique to contextvalue - value to storeexpiration - expiration for record, or nulljava.io.IOException - if fatal errors occur in the insertion processpublic void updateContextExpiration(@Nonnull @NotEmpty
java.lang.String context,
@Nullable
java.lang.Long expiration)
throws java.io.IOException
updateContextExpiration in interface StorageServiceupdateContextExpiration in class AbstractMapBackedStorageServicecontext - a storage context labelexpiration - a new expiration timestamp, or nulljava.io.IOException - if errors occur in the cleanup processpublic void deleteContext(@Nonnull @NotEmpty
java.lang.String context)
throws java.io.IOException
deleteContext in interface StorageServicedeleteContext in class AbstractMapBackedStorageServicecontext - a storage context labeljava.io.IOException - if errors occur in the cleanup processpublic void reap(@Nonnull @NotEmpty
java.lang.String context)
throws java.io.IOException
reap in interface StorageServicereap in class AbstractMapBackedStorageServicecontext - a storage context labeljava.io.IOException - if errors occur in the cleanup processpublic void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
init in interface javax.servlet.Filterjavax.servlet.ServletExceptionpublic void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws java.io.IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.Filterjava.io.IOExceptionjavax.servlet.ServletExceptionprotected void load()
throws java.io.IOException
java.io.IOException - if an error occurs reconstituting the data@Nullable
protected void save()
throws java.io.IOException
java.io.IOException - if an error occurs preserving the data@Nullable
protected java.lang.Long updateImpl(@Nullable
java.lang.Long version,
@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nullable
java.lang.String value,
@Nullable
java.lang.Long expiration)
throws java.io.IOException,
VersionMismatchException
updateImpl in class AbstractMapBackedStorageServiceversion - only update if the current version matches this valuecontext - a storage context labelkey - a key unique to contextvalue - updated valueexpiration - expiration for record. or nulljava.io.IOException - if errors occur in the update processVersionMismatchException - if the record has already been updated to a newer versionprotected boolean deleteImpl(@Nullable @Positive
java.lang.Long version,
@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key)
throws java.io.IOException,
VersionMismatchException
deleteImpl in class AbstractMapBackedStorageServiceversion - only update if the current version matches this valuecontext - a storage context labelkey - a key unique to contextjava.io.IOException - if errors occur in the update processVersionMismatchException - if the record has already been updated to a newer version@Nullable protected java.util.TimerTask getCleanupTask()
The default implementation does not supply one.
getCleanupTask in class AbstractStorageService@Nonnull @NonnullElements @Live protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,MutableStorageRecord>> getContextMap()
getContextMap in class AbstractMapBackedStorageService@Nonnull protected java.util.concurrent.locks.ReadWriteLock getLock()
getLock in class AbstractMapBackedStorageServiceprivate void setDirty(boolean flag)
flag - dirty bit to setprivate boolean isDirty()