Class LoginAttemptManagerImpl
java.lang.Object
org.craftercms.studio.impl.v2.security.LoginAttemptManagerImpl
- All Implemented Interfaces:
LoginAttemptManager
LoginAttemptManager implementation that keeps track of login failures in memory. - On login success, username is removed from the loginFailures map
- On login failure:
- If user is already locked, no action is performed
- If user is not locked, the login attempt count is incremented (or initialized to 1, if missing)
- Then the user is locked for the period calculated as
min( baseTimeSeconds ^ (failedAttempts - 1), maxTimeSeconds)
isUserLocked() is implemented by checking if the user is present in the loginFailures map and if the lock time has not expired.This implementation relies on
LRUMap to limit the number of tracked usernames. When adding new items to a full LRUMap(maxTrackedUsernames is reached),
it will delete the least recently used items (based on calls to put and get methods). In order to prevent leaking information about user existence (Enumeration attacks), this implementation is agnostic to whether the user exists or not.
- Since:
- 4.1.2
-
Constructor Summary
ConstructorsConstructorDescriptionLoginAttemptManagerImpl(int maxTrackedUsernames, int baseTimeSeconds, long maxTimeSeconds, boolean enabled) Creates a new instance ofLoginAttemptManagerImpl. -
Method Summary
Modifier and TypeMethodDescriptionlonggetUserLockTimeLeftSeconds(String username) Get the number of seconds left for the user to be unlocked, or 0 if the user is not locked.booleanisUserLocked(String username) Indicates if a user is currently locked.voidloginFailed(String username) Notify this manager that a login attempt has failed for the given user.voidloginSucceeded(String username) Notify this manager that a login attempt has succeeded for the given user.
-
Constructor Details
-
LoginAttemptManagerImpl
public LoginAttemptManagerImpl(int maxTrackedUsernames, int baseTimeSeconds, long maxTimeSeconds, boolean enabled) Creates a new instance ofLoginAttemptManagerImpl.- Parameters:
maxTrackedUsernames- The maximum number of usernames to track. When this number is reached, the least recently used usernames will be removed from the map.baseTimeSeconds- The base time in seconds to use for exponential backoff.maxTimeSeconds- The maximum time in seconds to use for exponential backoff.enabled- Whether this manager is enabled or not.
-
-
Method Details
-
isUserLocked
Description copied from interface:LoginAttemptManagerIndicates if a user is currently locked.
A locked user is not allowed to log in- Specified by:
isUserLockedin interfaceLoginAttemptManager- Parameters:
username- the username- Returns:
- true if the user is locked, false otherwise
-
getUserLockTimeLeftSeconds
Description copied from interface:LoginAttemptManagerGet the number of seconds left for the user to be unlocked, or 0 if the user is not locked.- Specified by:
getUserLockTimeLeftSecondsin interfaceLoginAttemptManager- Parameters:
username- the username- Returns:
- the number of seconds left for the user to be unlocked, or 0 if the user is not locked.
-
loginSucceeded
Description copied from interface:LoginAttemptManagerNotify this manager that a login attempt has succeeded for the given user.- Specified by:
loginSucceededin interfaceLoginAttemptManager- Parameters:
username- the username
-
loginFailed
Description copied from interface:LoginAttemptManagerNotify this manager that a login attempt has failed for the given user.- Specified by:
loginFailedin interfaceLoginAttemptManager- Parameters:
username- the username
-