Class 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 of 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.

  • Field Details

  • Constructor Details

    • ClientStorageService

      public ClientStorageService()
      Constructor.
  • Method Details

    • 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:
      setCleanupInterval in class AbstractStorageService
      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:
      isServerSide in interface StorageCapabilitiesEx
      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 interface StorageCapabilitiesEx
      Returns:
      true iff the storage implementation manages data independent of a single server node
    • 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 the CookieManager to use.
      Returns:
      the CookieManager to use
    • setCookieManager

      public void setCookieManager(@Nonnull CookieManager manager)
      Set the CookieManager to 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 the DataSealer to use for data security.
      Returns:
      DataSealer to use for data security
    • setDataSealer

      public void setDataSealer(@Nonnull DataSealer sealer)
      Set the DataSealer to use for data security.
      Parameters:
      sealer - DataSealer to use for data security
    • setKeyStrategy

      public void setKeyStrategy(@Nullable DataSealerKeyStrategy strategy)
      Set the DataSealerKeyStrategy to use for stale key detection.
      Parameters:
      strategy - DataSealerKeyStrategy to use for stale key detection
    • setClientStorageServiceStoreFactory

      public void setClientStorageServiceStoreFactory(@Nonnull ClientStorageServiceStore.Factory factory)
      Set the backing store ClientStorageServiceStore.Factory to use.
      Parameters:
      factory - factory to use
    • init

      public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
      Specified by:
      init in interface javax.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:
      doFilter in interface javax.servlet.Filter
      Throws:
      IOException
      javax.servlet.ServletException
    • getContextSize

      public int getContextSize()
      Gets max size of context labels in characters.
      Specified by:
      getContextSize in interface StorageCapabilities
      Overrides:
      getContextSize in class AbstractStorageService
      Returns:
      max size of context labels in characters
    • getKeySize

      public int getKeySize()
      Gets max size of keys in characters.
      Specified by:
      getKeySize in interface StorageCapabilities
      Overrides:
      getKeySize in class AbstractStorageService
      Returns:
      max size of keys in characters
    • getValueSize

      public long getValueSize()
      Gets max size of values in characters.
      Specified by:
      getValueSize in interface StorageCapabilities
      Overrides:
      getValueSize in class AbstractStorageService
      Returns:
      max size of values in characters
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      Overrides:
      doInitialize in class AbstractStorageService
      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:
      getCleanupTask in class AbstractStorageService
      Returns:
      a task object, or null
    • getLock

      @Nonnull protected ReadWriteLock getLock()
      Get the shared lock to synchronize access.
      Specified by:
      getLock in class AbstractMapBackedStorageService
      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:
      getContextMap in class AbstractMapBackedStorageService
      Returns:
      map of contexts to manipulate
      Throws:
      IOException - to signal errors
    • setDirty

      protected void setDirty() throws IOException
      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 class AbstractMapBackedStorageService
      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

      boolean isLoaded() throws IOException
      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

      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 none
      source - 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

      @Nonnull @NotEmpty String getLogPrefix()
      Get a prefix for log messages.
      Returns:
      logging prefix