Class AbstractAssertionIDReplayValidator

java.lang.Object
org.opensaml.saml.saml2.assertion.impl.AbstractAssertionIDReplayValidator
Direct Known Subclasses:
AssertionReplayValidator, OneTimeUseConditionValidator

@ThreadSafe public abstract class AbstractAssertionIDReplayValidator extends Object
An abstract class for validators that enforce that an Assertion ID is not replayed/reused.
  • Field Details

    • log

      @Nonnull private org.slf4j.Logger log
      Logger.
    • replayCache

      @Nonnull private final ReplayCache replayCache
      Replay cache used to track which assertions have been used.
    • replayCacheExpires

      @Nonnull private final Duration replayCacheExpires
      Time for disposal of value from cache.
  • Constructor Details

    • AbstractAssertionIDReplayValidator

      public AbstractAssertionIDReplayValidator(@Nonnull ReplayCache replay, @Nullable Duration expires)
      Constructor.
      Parameters:
      replay - reply cache used to track which assertions have been used
      expires - time for disposal of tracked assertion from the replay cache. May be null, then defaults to 8 hours
  • Method Details

    • getReplayCacheExpires

      @Nonnull protected Duration getReplayCacheExpires()
      Get the configured validator cache expiration interval.
      Returns:
      the configured cache expiration interval
    • getCacheContext

      @Nonnull protected abstract String getCacheContext()
      Get the cache context used with the replay cache.
      Returns:
      the cache context
    • getExpirationParameterName

      @Nullable protected abstract String getExpirationParameterName()
      Get the optional validation context param name to use for the per-validation expiration

      This is the name of the parameter in the supplied ValidationContext which holds an optional Duration value.

      Returns:
      param name, or null
    • doValidate

      protected boolean doValidate(@Nonnull Assertion assertion, @Nonnull ValidationContext context) throws AssertionValidationException
      Evaluate an Assertion for replay.
      Parameters:
      assertion - the assertion to evaluate
      context - the current validation contexxt
      Returns:
      false if replay detected, true if not
      Throws:
      AssertionValidationException - if there is a fatal error evaluating the Assertion
    • getExpires

      @Nonnull protected Instant getExpires(@Nonnull Assertion assertion, @Nonnull ValidationContext context)
      Get the replay cache expiration time for the assertion being evaluated.

      Defaults to Instant.now().plus(getReplayCacheExpires()).

      A subclass might override this to base expiration on data from the assertion or the validation context.

      Parameters:
      assertion - the SAML 2 Assertion being evaluated
      context - the current validation context
      Returns:
      the effective expiration for the assertion being evaluated
    • getCacheValue

      @Nonnull protected String getCacheValue(@Nonnull Assertion assertion) throws AssertionValidationException
      Get the string value which will be tracked in the cache for purposes of replay detection.
      Parameters:
      assertion - the SAML 2 Assertion to evaluate
      Returns:
      the cache value
      Throws:
      AssertionValidationException - thrown if there is a problem calculating the cached value