Interface LoginAttemptStore

All Known Implementing Classes:
InMemoryLoginAttemptStore

@ExperimentalJSentinelApi public interface LoginAttemptStore
Persistent counter store for the LoginAttemptPolicy family.

The existing default InMemoryLoginAttemptPolicy keeps its counters in process memory — fine for a single-instance demo, but unsuited for clustered deployments or for tracking lockouts across restarts. A store-backed policy (planned for Phase 4) delegates counter mutation and lookup to a LoginAttemptStore, so the lockout state survives the process and is shared across nodes.

The API is behaviour-flavoured rather than pure CRUD because the data shape is so narrow (counter + timestamp): callers either record an additional failure, ask how many failures the key has accumulated, or reset it on a successful login.

Implementations must be thread-safe; concurrent recordFailure calls happen on every failed login.

  • Method Details

    • recordFailure

      void recordFailure(LoginAttemptKey key, Instant at)
      Increments the failure counter for key by one and updates its last-failure instant to at.
      Parameters:
      key - failure dimension; must not be null
      at - instant the failure occurred; must not be null
    • failureCount

      int failureCount(LoginAttemptKey key)
      Returns the number of failures currently held against key. Zero when the key has never failed or has been reset(LoginAttemptKey).
      Parameters:
      key - failure dimension; must not be null
      Returns:
      non-negative failure count
    • lastFailureAt

      Optional<Instant> lastFailureAt(LoginAttemptKey key)
      Returns the timestamp of the most recent failure on key, if any.
      Parameters:
      key - failure dimension; must not be null
      Returns:
      last failure instant, or empty when never failed
    • reset

      void reset(LoginAttemptKey key)
      Clears any state associated with key — used after a successful login to start the counter from zero again.
      Parameters:
      key - failure dimension; must not be null