Class InMemorySamlReplayCache

java.lang.Object
com.revetsec.saml.InMemorySamlReplayCache
All Implemented Interfaces:
SamlReplayCache

@ThreadSafe public final class InMemorySamlReplayCache extends Object implements SamlReplayCache
Bounded, process-local SAML assertion replay cache. A restart loses its records; use a shared SamlReplayCache for more than one node. Live entries are never evicted. Expired records are removed only when a subsequent write observes a clock at least as late as every prior write. A clock rollback refuses new admissions until time catches up.
Since:
1.0.0
  • Method Details

    • fromLimit

      public static @NonNull InMemorySamlReplayCache fromLimit(@NonNull Clock clock, @NonNull Integer maximumEntries)
      Creates a volatile cache with an explicit entry limit. New namespaced admissions are limited to one quarter of the total capacity (at least one). Legacy three-argument admissions retain the full configured capacity. This shared-pool heuristic does not reserve capacity for mutually untrusted connections; use fromConnectionLimits(Clock, Map) for fixed independent reservations.
      Parameters:
      clock - the time source used for admission and expiry
      maximumEntries - maximum number of live replay records, from 1 to 1000000
      Returns:
      a new empty cache
      Since:
      1.0.0
    • fromConnectionLimits

      Creates fixed independent replay reservations for application-approved IdP connections. Each connection can use its entire configured quota even after all others fill theirs. Unknown connection IDs and the namespace-free admission overload cannot consume reserved capacity. Live replay marks are never evicted.

      Configuration is snapshotted without reading the clock. There is no borrowing or live reconfiguration; replacing a populated cache requires an application transition preserving every still-live replay mark. This remains a volatile, single-process cache; restart loses replay protection.

      Parameters:
      clock - admission and expiry clock
      connectionLimits - 1–1024 trusted connection IDs, each nonempty and at most 256 characters, with positive quotas totaling at most 1000000 live records
      Returns:
      an empty cache with immutable reservations
      Throws:
      NullPointerException - if the clock, map, a connection ID or quota is null
      IllegalArgumentException - if a configuration bound is exceeded
      Since:
      1.0.0
    • fromDefaults

      Creates a volatile cache with 65536 slots and the system UTC clock.
      Returns:
      a new cache
      Since:
      1.0.0
    • markIfAbsent

      Description copied from interface: SamlReplayCache
      Atomically admit a previously unseen key until its final possible acceptance time across supported request bindings and time policies. A backend must retain the key through the supplied absolute expiry without rounding that expiry down.
      Specified by:
      markIfAbsent in interface SamlReplayCache
      Parameters:
      key - the Revetsec-generated replay key
      expiresAt - the final possible acceptance time across supported completion contexts
      remaining - positive time budget for this operation
      Returns:
      an explicit outcome; only MARKED permits identity release
    • markIfAbsent

      Description copied from interface: SamlReplayCache
      Atomically admit a replay key within a connection's capacity namespace. The key itself already binds the connection, SP and IdP identifiers. Implementations shared by mutually untrusted IdP connections should override this method and reserve capacity per connection. The default preserves source compatibility for existing stores but supplies no such capacity isolation.
      Specified by:
      markIfAbsent in interface SamlReplayCache
      Parameters:
      connectionId - application-approved IdP connection namespace
      key - the Revetsec-generated replay key
      expiresAt - the final possible acceptance time
      remaining - positive time budget
      Returns:
      an explicit atomic outcome
    • toString

      Redacts replay keys. @since 1.0.0
      Overrides:
      toString in class Object