Class StoreBackedLoginAttemptPolicy
- All Implemented Interfaces:
LoginAttemptPolicy
LoginAttemptPolicy that stores its failure counters in a
LoginAttemptStore.
Counter and last-failure timestamp survive a process restart — a
lockout earned on Monday is still in effect on Tuesday. Unlike the
InMemoryLoginAttemptPolicy default, this implementation
runs a flat lockout: once
LoginAttemptConfiguration.failureThreshold() failures
accumulate within the configured
LoginAttemptConfiguration.window(), the key locks for
LoginAttemptConfiguration.initialLockout() starting at the
last failure. The progressive backoff that the in-memory policy
offers requires per-key history (lockout level, "just locked"
flag) that the narrower LoginAttemptStore contract does
not carry — applications that need progressive backoff stay on
the in-memory policy or wrap this one with a richer key store.
Bound to one TenantId at construction. Multi-tenant
deployments instantiate one policy per tenant or wrap with a
resolver.
-
Constructor Summary
ConstructorsConstructorDescriptionBuilds a policy withLoginAttemptConfiguration.defaults()andTenantId.DEFAULT.StoreBackedLoginAttemptPolicy(LoginAttemptStore store, LoginAttemptConfiguration config, TenantId tenant, Clock clock) Full constructor. -
Method Summary
Modifier and TypeMethodDescriptionbeforeAttempt(LoginAttemptContext context) Decides whether the attempt described bycontextmay proceed.voidrecordFailure(LoginAttemptContext context) Records a failed attempt.voidrecordSuccess(LoginAttemptContext context) Records a successful attempt.
-
Constructor Details
-
StoreBackedLoginAttemptPolicy
Builds a policy withLoginAttemptConfiguration.defaults()andTenantId.DEFAULT.- Parameters:
store- backing store; non-null
-
StoreBackedLoginAttemptPolicy
public StoreBackedLoginAttemptPolicy(LoginAttemptStore store, LoginAttemptConfiguration config, TenantId tenant, Clock clock) Full constructor.- Parameters:
store- backing store; non-nullconfig- thresholds; non-nulltenant- tenant scope;nullbecomesTenantId.DEFAULTclock- time source; non-null. Pass a fixed clock to make tests deterministic.
-
-
Method Details
-
beforeAttempt
Description copied from interface:LoginAttemptPolicyDecides whether the attempt described bycontextmay proceed. Implementations must not mutate the failure counter here — that is the responsibility ofLoginAttemptPolicy.recordSuccess(LoginAttemptContext)/LoginAttemptPolicy.recordFailure(LoginAttemptContext)after the actual check.- Specified by:
beforeAttemptin interfaceLoginAttemptPolicy- Parameters:
context- attempt context- Returns:
- decision; never
null
-
recordSuccess
Description copied from interface:LoginAttemptPolicyRecords a successful attempt. Implementations typically reset the per-key failure counter so a successful login lifts a partial lockout immediately.- Specified by:
recordSuccessin interfaceLoginAttemptPolicy- Parameters:
context- attempt context
-
recordFailure
Description copied from interface:LoginAttemptPolicyRecords a failed attempt. Implementations typically increment a per-key counter and may escalate the throttling decision.- Specified by:
recordFailurein interfaceLoginAttemptPolicy- Parameters:
context- attempt context
-