Class StorageServiceStateManager

All Implemented Interfaces:
Component, DestructableComponent, IdentifiableComponent, IdentifiedComponent, InitializableComponent, StateManager

public class StorageServiceStateManager extends AbstractStateManager
StateManager implemented with a StorageService and an optional CSRF-mitigation cookie.
  • Field Details

    • DEFAULT_PREFIX

      @Nonnull @NotEmpty public static String DEFAULT_PREFIX
      Default cookie prefix.
    • log

      @Nonnull private org.slf4j.Logger log
      Class logger.
    • storageService

      @NonnullAfterInit private StorageService storageService
      Storage back-end.
    • cookieManager

      @Nullable private CookieManager cookieManager
      Cookie manager.
    • cookiePrefix

      @Nonnull @NotEmpty private String cookiePrefix
      Fixed prefix for cookie names.
  • Constructor Details

    • StorageServiceStateManager

      public StorageServiceStateManager()
      Constructor.
  • Method Details

    • setStorageService

      public void setStorageService(@Nonnull StorageService storage)
      Set StorageService to use.
      Parameters:
      storage - storage service
    • setCookiePrefix

      public void setCookiePrefix(@Nonnull @NotEmpty String prefix)
      Set the fixed prefix to use for the cookies.

      Defaults to "_shibsp_state".

      Parameters:
      prefix - cookie prefix
    • setCookieManager

      public void setCookieManager(@Nonnull CookieManager manager)
      Set the CookieManager to use.

      If set, the implementation produces a second random key that points to a cookie that carries the actual storage key to retrieve. If unset, the original storage key is used by itself and no additional cookie is created.

      Parameters:
      manager - instance to use
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      Overrides:
      doInitialize in class AbstractStateManager
      Throws:
      ComponentInitializationException
    • doPreserve

      @Nonnull protected String doPreserve(@Nonnull Agent agent, @Nonnull Application application, @Nonnull String data, boolean sealed) throws IOException
      Subclasses implement this method to preserve the transformed data in whatever way is necessary and return a token.
      Specified by:
      doPreserve in class AbstractStateManager
      Parameters:
      agent - agent owning the state
      application - application owning the state
      data - data to preserve
      sealed - whether the data was sealed (and thus base64-encoded)
      Returns:
      the state token
      Throws:
      IOException - if an error occurs
    • doRecover

      @Nullable protected String doRecover(@Nonnull Agent agent, @Nonnull Application application, @Nonnull @NotEmpty String stateToken, boolean sealed) throws IOException
      Subclasses implement this method to recover the stored data in whatever way is necessary and return the supplied data string as a successful result.

      The implementation should ensure when possible that this method works only once for a given state token.

      Subclasses may assume that the state token inputs they receive will have been returned by them via the AbstractStateManager.doPreserve(Agent, Application, String, boolean) method.

      Specified by:
      doRecover in class AbstractStateManager
      Parameters:
      agent - agent owning the state
      application - application owning the state
      stateToken - the state token to map from/clear
      sealed - whether the data was sealed (and thus base64-encoded)
      Returns:
      the recovered data, or null if unable to recover without underlying cause
      Throws:
      IOException - if an error occurs
    • getContext

      @Nonnull private String getContext(@Nonnull Agent agent, @Nonnull Application application)
      Compute the storage context to use.
      Parameters:
      agent - calling agent
      application - calling application
      Returns:
      storage context for request
    • getCookieName

      @Nonnull public String getCookieName(@Nonnull Application application, @Nonnull String uniquePortion)
      Computes the name of a new state cookie.
      Parameters:
      application - the application
      uniquePortion - unique portion of name
      Returns:
      cookie name