Class CookieStateManager

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

public class CookieStateManager extends AbstractStateManager
StateManager implemented by storing the data directly into a cookie.
  • Field Details

    • DEFAULT_PREFIX

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

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

      @NonnullAfterInit private CookieManager cookieManager
      Cookie manager.
    • cookiePrefix

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

    • CookieStateManager

      public CookieStateManager()
      Constructor.
  • Method Details

    • 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.
      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
    • 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