Class PreservePostData

All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, ProfileAction, Aware, MessageSource, MessageSourceAware, Action

public class PreservePostData extends AbstractApplicationAction
Action that detects submitted form data, and when permitted, stores it in a StorageService and issues a cookie associated with the active state token to preserve a pointer to the data for recovery.

The state token to bind to is collected from a StateDataContext accessed via lookup strategy.

The action also has support for detecting data previously preserved by this action by checking for a SPConstants.STATE member in the input message and using that to recover the data and clean up that record so it can be re-associated with the new state token found in the context.

Event:
EventIds.PROCEED_EVENT_ID, EventIds.INVALID_MESSAGE, EventIds.INVALID_PROFILE_CTX, EventIds.IO_ERROR
  • Field Details

  • Constructor Details

    • PreservePostData

      public PreservePostData()
      Constructor.
  • Method Details

    • setStateDataContextLookupStrategy

      public void setStateDataContextLookupStrategy(@Nonnull Function<ProfileRequestContext,StateDataContext> strategy)
      Sets the strategy used to lookup the StateDataContext.
      Parameters:
      strategy - lookup strategy
    • setIdentifierGenerationStrategy

      public void setIdentifierGenerationStrategy(@Nonnull IdentifierGenerationStrategy strategy)
      Set IdentifierGenerationStrategy to use.

      Defaults to a secure random source that produces 16 byte values.

      Parameters:
      strategy - identifier generator strategy
    • setLifetime

      public void setLifetime(@Positive @Nonnull Duration dur)
      Set the lifetime for data in storage.

      Defaults to PT5M.

      Parameters:
      dur - data lifetime
    • setStorageService

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

      public void setCookieManager(@Nonnull CookieManager manager)
      Sets the CookieManager to use.
      Parameters:
      manager - cookie manager instance
    • setCookiePrefix

      public void setCookiePrefix(@Nonnull @NotEmpty String prefix)
      Sets the cookie prefix.

      Defaults to DEFAULT_COOKIE_PREFIX.

      Parameters:
      prefix - cookie prefix
    • setErrorFatal

      public void setErrorFatal(boolean flag)
      Sets whether an error computing a state token should result in a fatal event.

      Defaults to false.

      Parameters:
      flag - flag to set
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      Overrides:
      doInitialize in class AbstractInitializableComponent
      Throws:
      ComponentInitializationException
    • doPreExecute

      protected boolean doPreExecute(@Nonnull ProfileRequestContext profileRequestContext)
      Overrides:
      doPreExecute in class AbstractApplicationAction
    • doExecute

      protected void doExecute(@Nonnull ProfileRequestContext profileRequestContext)
      Overrides:
      doExecute in class AbstractProfileAction
    • getSubmittedData

      @Nullable private String getSubmittedData()
      Gets data submitted with this request, if any.
      Returns:
      submitted data or null
    • getPreviousData

      @Nullable private String getPreviousData(@Nonnull ProfileRequestContext profileRequestContext)
      Checks for previously preserved data tracked against a state token submitted by the agent.

      This case is triggered by use of discovery, which would have preserved the data against the state token issued at that time, which we have since recovered and disposed of.

      Parameters:
      profileRequestContext - profile request context
      Returns:
      previous data or null
    • getCookieName

      @Nonnull String getCookieName(@Nonnull String stateToken)
      Computes the cookie name based on the configured prefix and state token.

      Package private access for unit tests.

      Parameters:
      stateToken - the state token
      Returns:
      the cookie name