Class ReplayCache

  • All Implemented Interfaces:
    net.shibboleth.utilities.java.support.component.Component, net.shibboleth.utilities.java.support.component.DestructableComponent, net.shibboleth.utilities.java.support.component.IdentifiableComponent, net.shibboleth.utilities.java.support.component.IdentifiedComponent, net.shibboleth.utilities.java.support.component.InitializableComponent

    @ThreadSafeAfterInit
    public class ReplayCache
    extends net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
    Tracks non-replayable values in order to detect replays of the values, commonly used to track message identifiers.

    This class is thread-safe and uses a synchronized method to prevent race conditions within the underlying store (lacking an atomic "check and insert" operation).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private net.shibboleth.utilities.java.support.codec.StringDigester digester
      Digester if key is too long.
      private Logger log
      Logger.
      private StorageService storage
      Backing storage for the replay cache.
      private boolean strict
      Flag controlling behavior on storage failure.
    • Constructor Summary

      Constructors 
      Constructor Description
      ReplayCache()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean check​(String context, String s, Instant expires)
      Returns true iff the check value is not found in the cache, and stores it.
      void doInitialize()
      StorageService getStorage()
      Get the backing store for the cache.
      boolean isStrict()
      Get the strictness flag.
      void setStorage​(StorageService storageService)
      Set the backing store for the cache.
      void setStrict​(boolean flag)
      Set the strictness flag.
      • Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent

        setId
      • Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent

        getId
      • Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent

        destroy, doDestroy, initialize, isDestroyed, isInitialized
      • Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiedComponent

        getId
    • Field Detail

      • log

        private final Logger log
        Logger.
      • storage

        @NonnullAfterInit
        private StorageService storage
        Backing storage for the replay cache.
      • digester

        @NonnullAfterInit
        private net.shibboleth.utilities.java.support.codec.StringDigester digester
        Digester if key is too long.
      • strict

        private boolean strict
        Flag controlling behavior on storage failure.
    • Constructor Detail

      • ReplayCache

        public ReplayCache()
    • Method Detail

      • getStorage

        @NonnullAfterInit
        public StorageService getStorage()
        Get the backing store for the cache.
        Returns:
        the backing store.
      • setStorage

        public void setStorage​(@Nonnull
                               StorageService storageService)
        Set the backing store for the cache.
        Parameters:
        storageService - backing store to use
      • isStrict

        public boolean isStrict()
        Get the strictness flag.
        Returns:
        true iff we should treat storage failures as a replay
      • setStrict

        public void setStrict​(boolean flag)
        Set the strictness flag.
        Parameters:
        flag - true iff we should treat storage failures as a replay
      • doInitialize

        public void doInitialize()
                          throws net.shibboleth.utilities.java.support.component.ComponentInitializationException
        Overrides:
        doInitialize in class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
        Throws:
        net.shibboleth.utilities.java.support.component.ComponentInitializationException
      • check

        public boolean check​(@Nonnull @NotEmpty
                             String context,
                             @Nonnull @NotEmpty
                             String s,
                             @Nonnull
                             Instant expires)
        Returns true iff the check value is not found in the cache, and stores it.
        Parameters:
        context - a context label to subdivide the cache
        s - value to check
        expires - time for disposal of value from cache
        Returns:
        true iff the check value is not found in the cache