Interface LoginAttemptPolicy
- All Known Implementing Classes:
InMemoryLoginAttemptPolicy, NoopLoginAttemptPolicy, StoreBackedLoginAttemptPolicy
public interface LoginAttemptPolicy
Policy that throttles repeated failed login attempts.
The expected call sequence inside an authentication flow is:
beforeAttempt(LoginAttemptContext)— before the password check. If the decision is notallowed, skip the check and return the user a generic "try again later" error.recordSuccess(LoginAttemptContext)— after the password check succeeds. Resets the failure counter.recordFailure(LoginAttemptContext)— after the password check rejects the credentials. Increments the failure counter and may escalate the throttling decision for subsequent attempts.
Implementations decide which key to track by — typically a
combination of username and clientAddress. The default
InMemoryLoginAttemptPolicy tracks the combined key plus the
raw username so an attacker cannot cycle clients to escape the
counter.
-
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.
-
Method Details
-
beforeAttempt
Decides whether the attempt described bycontextmay proceed. Implementations must not mutate the failure counter here — that is the responsibility ofrecordSuccess(LoginAttemptContext)/recordFailure(LoginAttemptContext)after the actual check.- Parameters:
context- attempt context- Returns:
- decision; never
null
-
recordSuccess
Records a successful attempt. Implementations typically reset the per-key failure counter so a successful login lifts a partial lockout immediately.- Parameters:
context- attempt context
-
recordFailure
Records a failed attempt. Implementations typically increment a per-key counter and may escalate the throttling decision.- Parameters:
context- attempt context
-