Class InMemoryLoginAttemptStore
java.lang.Object
com.svenruppert.jsentinel.bruteforce.InMemoryLoginAttemptStore
- All Implemented Interfaces:
LoginAttemptStore
@ExperimentalJSentinelApi
public final class InMemoryLoginAttemptStore
extends Object
implements LoginAttemptStore
In-memory
LoginAttemptStore backed by a single
ConcurrentHashMap. Suitable for tests, demos, and
single-process applications.
Counters and last-failure instants are kept in a private
package-local Ledger record, mutated atomically through
compute/merge-style map operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of failures currently held againstkey.Returns the timestamp of the most recent failure onkey, if any.voidrecordFailure(LoginAttemptKey key, Instant at) Increments the failure counter forkeyby one and updates its last-failure instant toat.voidreset(LoginAttemptKey key) Clears any state associated withkey— used after a successful login to start the counter from zero again.
-
Constructor Details
-
InMemoryLoginAttemptStore
public InMemoryLoginAttemptStore()Creates an empty store.
-
-
Method Details
-
recordFailure
Description copied from interface:LoginAttemptStoreIncrements the failure counter forkeyby one and updates its last-failure instant toat.- Specified by:
recordFailurein interfaceLoginAttemptStore- Parameters:
key- failure dimension; must not benullat- instant the failure occurred; must not benull
-
failureCount
Description copied from interface:LoginAttemptStoreReturns the number of failures currently held againstkey. Zero when the key has never failed or has beenLoginAttemptStore.reset(LoginAttemptKey).- Specified by:
failureCountin interfaceLoginAttemptStore- Parameters:
key- failure dimension; must not benull- Returns:
- non-negative failure count
-
lastFailureAt
Description copied from interface:LoginAttemptStoreReturns the timestamp of the most recent failure onkey, if any.- Specified by:
lastFailureAtin interfaceLoginAttemptStore- Parameters:
key- failure dimension; must not benull- Returns:
- last failure instant, or empty when never failed
-
reset
Description copied from interface:LoginAttemptStoreClears any state associated withkey— used after a successful login to start the counter from zero again.- Specified by:
resetin interfaceLoginAttemptStore- Parameters:
key- failure dimension; must not benull
-