Class DefaultUserLockoutService
java.lang.Object
com.broadleafcommerce.auth.user.service.DefaultUserLockoutService
- All Implemented Interfaces:
UserLockoutService
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultUserLockoutService
(UserService<User> userService, UserLoginAttemptService<UserLoginAttempt> userLoginAttemptService, AuthorizedClientService<AuthorizedClient> clientService, AuthorizationServerService<AuthorizationServer> serverService, UserLockoutProperties userLockoutProperties) -
Method Summary
Modifier and TypeMethodDescriptionboolean
canResetPassword
(User user) Return true if this user can reset their password.protected int
countChangePasswordAttempts
(String username, AuthorizationServer server) Returns the total count of failed change password attempts for the username and server.protected int
countLoginAttempts
(String username, AuthorizationServer server) protected int
countResetPasswordAttempts
(String username, AuthorizationServer server) Returns the total count of failed reset password attempts for the username and server.void
createChangePasswordAttempt
(String username, String userId, String changePasswordAttemptResult, String authServerId) Creates aUserChangePasswordAttempt
.void
createLoginAttempt
(User user, String loginAttemptResult) Create a user login attempt.void
createLoginAttempt
(String username, String loginAttemptResult, String clientId) Create a user login attemptprotected void
createLoginAttempt
(String username, String userId, String loginAttemptResult, String authServerId) void
createResetPasswordAttempt
(String username, String userId, String resetPasswordAttemptResult, String authServerId) Creates aUserResetPasswordAttempt
.protected int
Returns the configuration value of maximum change password attempts before a user is locked out.protected Long
Returns the configuration value of the fail decay minutes for change password attempts.protected AuthorizedClientService<AuthorizedClient>
protected Duration
protected Long
protected int
protected Long
protected int
Returns the configuration value of maximum reset password attempts before a user is locked out.protected Long
Returns the configuration value of the fail decay minutes for reset password attempts.protected AuthorizationServerService<AuthorizationServer>
protected UserLockoutProperties
protected UserLoginAttemptService<UserLoginAttempt>
protected UserService<User>
protected boolean
protected boolean
Manually lock a userprotected AuthorizationServer
readAuthServer
(String authServerId) void
setUserChangePasswordAttemptService
(UserChangePasswordAttemptService<UserChangePasswordAttempt> userChangePasswordAttemptService) void
setUserResetPasswordAttemptService
(UserResetPasswordAttemptService<UserResetPasswordAttempt> userResetPasswordAttemptService) protected void
throwIfLocked
(int attempts, int attemptsAllowed, String username, AuthorizationServer server, User user) protected void
unlockOrValidateAttemptsLessThanMaximum
(String username, User user, AuthorizationServer server, int attemptCount, int maximumAttemptsAllowed) unlockUser
(User user) Manually unlock a userunlockUserIfEligible
(String username, String clientId) If a user is eligible for unlocking, unlock them.After a password reset, unlock the user if they're eligible.protected boolean
userShouldBeUnlocked
(User user, AuthorizationServer server) void
validateMaximumChangePasswordAttempts
(String username, String userId, String authServerId) Validates whether current number of change password attempts for a user have exceeded the maximum attempt limit.void
validateMaximumResetPasswordAttempts
(String username, String userId, String authServerId) Validates whether current number of reset password attempts for a user have exceeded the maximum attempt limit.
-
Constructor Details
-
DefaultUserLockoutService
public DefaultUserLockoutService(UserService<User> userService, UserLoginAttemptService<UserLoginAttempt> userLoginAttemptService, AuthorizedClientService<AuthorizedClient> clientService, AuthorizationServerService<AuthorizationServer> serverService, UserLockoutProperties userLockoutProperties)
-
-
Method Details
-
createLoginAttempt
Description copied from interface:UserLockoutService
Create a user login attempt.- Specified by:
createLoginAttempt
in interfaceUserLockoutService
- Parameters:
user
- The user to create a login attempt forloginAttemptResult
- The login attempt result.
-
createLoginAttempt
Description copied from interface:UserLockoutService
Create a user login attempt- Specified by:
createLoginAttempt
in interfaceUserLockoutService
- Parameters:
username
- The username to create an attempt forloginAttemptResult
- The login attempt resultclientId
- The client ID
-
createResetPasswordAttempt
public void createResetPasswordAttempt(String username, @Nullable String userId, String resetPasswordAttemptResult, String authServerId) Description copied from interface:UserLockoutService
Creates aUserResetPasswordAttempt
.- Specified by:
createResetPasswordAttempt
in interfaceUserLockoutService
- Parameters:
username
- The username to create an attempt foruserId
- The user ID of the user who attempted to reset their password. This is nullable, as an attempt could be made to reset the password using a specific username, but no user exists for that username.resetPasswordAttemptResult
- The reset password attempt resultauthServerId
- The authentication server ID that contains the property configurations to be applied to this attempt- See Also:
-
validateMaximumResetPasswordAttempts
public void validateMaximumResetPasswordAttempts(String username, @Nullable String userId, String authServerId) Description copied from interface:UserLockoutService
Validates whether current number of reset password attempts for a user have exceeded the maximum attempt limit. This method can be used in conjunction withUserLockoutService.createResetPasswordAttempt(String, String, String, String)
to pre-validate the current state before performing outside actions that require attempt to be valid, such as resetting the password on the user or consuming a one-time token.- Specified by:
validateMaximumResetPasswordAttempts
in interfaceUserLockoutService
- Parameters:
username
- Username of the user to validateuserId
- User ID of the user to validate reset password attempts forauthServerId
- Authentication server ID containing property configurations to be referenced for this attempt
-
createChangePasswordAttempt
public void createChangePasswordAttempt(String username, String userId, String changePasswordAttemptResult, String authServerId) Description copied from interface:UserLockoutService
Creates aUserChangePasswordAttempt
.- Specified by:
createChangePasswordAttempt
in interfaceUserLockoutService
- Parameters:
username
- The username to create an attempt foruserId
- The user ID of the user who attempted to change their password. This should be non-null since a user can only change a password when they are logged in.changePasswordAttemptResult
- The change password attempt resultauthServerId
- The authentication server ID that contains the property configurations to be applied to this attempt- See Also:
-
validateMaximumChangePasswordAttempts
public void validateMaximumChangePasswordAttempts(String username, String userId, String authServerId) Description copied from interface:UserLockoutService
Validates whether current number of change password attempts for a user have exceeded the maximum attempt limit. This method can be used in conjunction withUserLockoutService.createChangePasswordAttempt(String, String, String, String)
to pre-validate the current state before performing outside actions that require attempt to be valid, such as changing the password on the user.- Specified by:
validateMaximumChangePasswordAttempts
in interfaceUserLockoutService
- Parameters:
username
- Username of the user to validateuserId
- User ID of the user to validate change password attempts onauthServerId
- Authentication server ID containing property configurations to be referenced for this attempt
-
unlockUser
Description copied from interface:UserLockoutService
Manually unlock a user- Specified by:
unlockUser
in interfaceUserLockoutService
- Parameters:
user
- The user to unlock
-
lockUser
Description copied from interface:UserLockoutService
Manually lock a user- Specified by:
lockUser
in interfaceUserLockoutService
- Parameters:
user
- The user to lock
-
unlockUserIfEligible
Description copied from interface:UserLockoutService
If a user is eligible for unlocking, unlock them.- Specified by:
unlockUserIfEligible
in interfaceUserLockoutService
- Parameters:
username
- The usernameclientId
- The client ID- Returns:
- The user, if they exist
-
canResetPassword
Description copied from interface:UserLockoutService
Return true if this user can reset their password.See
AuthorizationServer.getLockedUserCanResetPassword()
andUserLockoutProperties.isLockedUserCanResetPassword()
- Specified by:
canResetPassword
in interfaceUserLockoutService
- Parameters:
user
- The user to check- Returns:
- true if the user can reset their password, otherwise false.
-
unlockUserOnPasswordResetIfEligible
Description copied from interface:UserLockoutService
After a password reset, unlock the user if they're eligible.See
AuthorizationServer.getResetPasswordUnlocksUser()
andUserLockoutProperties.isResetPasswordUnlocksUser()
- Specified by:
unlockUserOnPasswordResetIfEligible
in interfaceUserLockoutService
- Parameters:
user
- The user to unlock, if eligible- Returns:
- true if the user has been unlocked, false if the user is still locked, or null if no action was taken
-
createLoginAttempt
-
unlockOrValidateAttemptsLessThanMaximum
protected void unlockOrValidateAttemptsLessThanMaximum(String username, @Nullable User user, AuthorizationServer server, int attemptCount, int maximumAttemptsAllowed) -
userShouldBeUnlocked
-
countLoginAttempts
-
countResetPasswordAttempts
Returns the total count of failed reset password attempts for the username and server.- Parameters:
username
- The username to count the attempts fromserver
- The server where the attempts occurred- Returns:
- the total count of failed reset password attempts for a username in a server
- Since:
- 2.1.3
-
countChangePasswordAttempts
Returns the total count of failed change password attempts for the username and server.- Parameters:
username
- The username to count the attempts fromserver
- The server where the attempts occurred- Returns:
- the total count of failed change password attempts for a username in a server
- Since:
- 2.1.3
-
getLockoutDuration
-
readAuthServer
-
getLockoutDurationMinutes
-
getLoginFailDecayMinutes
-
getChangePasswordFailDecayMinutes
Returns the configuration value of the fail decay minutes for change password attempts. If not set inAuthorizationServer
, it will be gotten fromUserLockoutProperties
instead. Otherwise, it returns null. SeeAuthorizationServer.changePasswordFailDecayMinutes
orUserLockoutProperties.changePasswordFailDecayMinutes
for more information.- Parameters:
server
- The server to initially fetch the configuration value from- Returns:
- the configuration value of the fail decay minutes for change password attempts
- Since:
- 2.1.3
-
getResetPasswordFailDecayMinutes
Returns the configuration value of the fail decay minutes for reset password attempts. If not set inAuthorizationServer
, it will be gotten fromUserLockoutProperties
instead. Otherwise, it returns null. SeeAuthorizationServer.resetPasswordFailDecayMinutes
orUserLockoutProperties.resetPasswordFailDecayMinutes
for more information.- Parameters:
server
- The server to initially fetch the configuration value from- Returns:
- the configuration value of the fail decay minutes for reset password attempts
- Since:
- 2.1.3
-
getLoginAttemptsAllowed
-
getResetPasswordAttemptsAllowed
Returns the configuration value of maximum reset password attempts before a user is locked out. If not set inAuthorizationServer
, it will be gotten fromUserLockoutProperties
instead. Otherwise, it returns the maximum Integer value. SeeAuthorizationServer.failedResetPasswordAttemptsAllowed
orUserLockoutProperties.failedResetPasswordAttemptsAllowed
for more information.- Parameters:
server
- The server to initially fetch the configuration value from- Returns:
- the configuration value of maximum reset password attempts before a user is locked out
- Since:
- 2.1.3
-
getChangePasswordAttemptsAllowed
Returns the configuration value of maximum change password attempts before a user is locked out. If not set inAuthorizationServer
, it will be gotten fromUserLockoutProperties
instead. Otherwise, it returns the maximum Integer value. SeeAuthorizationServer.failedChangePasswordAttemptsAllowed
orUserLockoutProperties.failedChangePasswordAttemptsAllowed
for more information.- Parameters:
server
- The server to initially fetch the configuration value from- Returns:
- the configuration value of maximum change password attempts before a user is locked out
- Since:
- 2.1.3
-
throwIfLocked
protected void throwIfLocked(int attempts, int attemptsAllowed, String username, AuthorizationServer server, @Nullable User user) -
isResetPasswordUnlocksUser
-
isLockedUserCanResetPassword
-
getUserService
-
getUserLoginAttemptService
-
getUserResetPasswordAttemptService
protected UserResetPasswordAttemptService<UserResetPasswordAttempt> getUserResetPasswordAttemptService() -
setUserResetPasswordAttemptService
@Autowired public void setUserResetPasswordAttemptService(UserResetPasswordAttemptService<UserResetPasswordAttempt> userResetPasswordAttemptService) -
getUserChangePasswordAttemptService
protected UserChangePasswordAttemptService<UserChangePasswordAttempt> getUserChangePasswordAttemptService() -
setUserChangePasswordAttemptService
@Autowired public void setUserChangePasswordAttemptService(UserChangePasswordAttemptService<UserChangePasswordAttempt> userChangePasswordAttemptService) -
getClientService
-
getServerService
-
getUserLockoutProperties
-