Class InMemoryLoginAttemptPolicy
- All Implemented Interfaces:
LoginAttemptPolicy
LoginAttemptPolicy suitable for single-node demos
and small deployments.
Counts failures per (username, clientAddress) pair plus an additional username-only counter so an attacker cannot cycle clients to evade the combined counter. Username and clientAddress are normalised (lower-cased + trimmed) before use as map keys.
After LoginAttemptConfiguration.failureThreshold() failures
inside LoginAttemptConfiguration.window() the key is locked
for LoginAttemptConfiguration.initialLockout(). Repeated
breaches double the lockout up to
LoginAttemptConfiguration.maxLockout() (progressive backoff).
A successful recordSuccess
resets the combined counter; the username-only counter is reset on
the next successful login by the same user even from a different
client.
Audit
The policy emits audit events through the
resolved
JSentinelAuditService:
LoginFailedon everyrecordFailureBruteForceLimitReachedthe first time a key crosses the failure threshold
Audit-sink failures are swallowed — they must never break the security flow that emitted them.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaults — suitable for single-node demos.InMemoryLoginAttemptPolicy(LoginAttemptConfiguration config, Clock clock, JSentinelAuditService auditService) -
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
-
InMemoryLoginAttemptPolicy
public InMemoryLoginAttemptPolicy()Defaults — suitable for single-node demos. -
InMemoryLoginAttemptPolicy
public InMemoryLoginAttemptPolicy(LoginAttemptConfiguration config, Clock clock, JSentinelAuditService auditService) - Parameters:
config- throttling thresholdsclock- time source — fixed clocks make testing deterministicauditService- audit sink, ornullto resolve fromJSentinelServiceResolveron each event
-
-
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
-