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 TypeMethodDescriptionbooleancanResetPassword(User user) Return true if this user can reset their password.protected intcountChangePasswordAttempts(String username, AuthorizationServer server) Returns the total count of failed change password attempts for the username and server.protected intcountLoginAttempts(String username, AuthorizationServer server) protected intcountResetPasswordAttempts(String username, AuthorizationServer server) Returns the total count of failed reset password attempts for the username and server.voidcreateChangePasswordAttempt(String username, String userId, String changePasswordAttemptResult, String authServerId) Creates aUserChangePasswordAttempt.voidcreateLoginAttempt(User user, String loginAttemptResult) Create a user login attempt.voidcreateLoginAttempt(String username, String loginAttemptResult, String clientId) Create a user login attemptprotected voidcreateLoginAttempt(String username, String userId, String loginAttemptResult, String authServerId) voidcreateResetPasswordAttempt(String username, String userId, String resetPasswordAttemptResult, String authServerId) Creates aUserResetPasswordAttempt.protected intReturns the configuration value of maximum change password attempts before a user is locked out.protected LongReturns the configuration value of the fail decay minutes for change password attempts.protected AuthorizedClientService<AuthorizedClient>protected Durationprotected Longprotected intprotected Longprotected intReturns the configuration value of maximum reset password attempts before a user is locked out.protected LongReturns the configuration value of the fail decay minutes for reset password attempts.protected AuthorizationServerService<AuthorizationServer>protected UserLockoutPropertiesprotected UserLoginAttemptService<UserLoginAttempt>protected UserService<User>protected booleanprotected booleanManually lock a userprotected AuthorizationServerreadAuthServer(String authServerId) voidsetUserChangePasswordAttemptService(UserChangePasswordAttemptService<UserChangePasswordAttempt> userChangePasswordAttemptService) voidsetUserResetPasswordAttemptService(UserResetPasswordAttemptService<UserResetPasswordAttempt> userResetPasswordAttemptService) protected voidthrowIfLocked(int attempts, int attemptsAllowed, String username, AuthorizationServer server, User user) protected voidunlockOrValidateAttemptsLessThanMaximum(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 booleanuserShouldBeUnlocked(User user, AuthorizationServer server) voidvalidateMaximumChangePasswordAttempts(String username, String userId, String authServerId) Validates whether current number of change password attempts for a user have exceeded the maximum attempt limit.voidvalidateMaximumResetPasswordAttempts(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:UserLockoutServiceCreate a user login attempt.- Specified by:
createLoginAttemptin interfaceUserLockoutService- Parameters:
user- The user to create a login attempt forloginAttemptResult- The login attempt result.
-
createLoginAttempt
Description copied from interface:UserLockoutServiceCreate a user login attempt- Specified by:
createLoginAttemptin 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:UserLockoutServiceCreates aUserResetPasswordAttempt.- Specified by:
createResetPasswordAttemptin 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:UserLockoutServiceValidates 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:
validateMaximumResetPasswordAttemptsin 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:UserLockoutServiceCreates aUserChangePasswordAttempt.- Specified by:
createChangePasswordAttemptin 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:UserLockoutServiceValidates 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:
validateMaximumChangePasswordAttemptsin 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:UserLockoutServiceManually unlock a user- Specified by:
unlockUserin interfaceUserLockoutService- Parameters:
user- The user to unlock
-
lockUser
Description copied from interface:UserLockoutServiceManually lock a user- Specified by:
lockUserin interfaceUserLockoutService- Parameters:
user- The user to lock
-
unlockUserIfEligible
Description copied from interface:UserLockoutServiceIf a user is eligible for unlocking, unlock them.- Specified by:
unlockUserIfEligiblein interfaceUserLockoutService- Parameters:
username- The usernameclientId- The client ID- Returns:
- The user, if they exist
-
canResetPassword
Description copied from interface:UserLockoutServiceReturn true if this user can reset their password.See
AuthorizationServer.getLockedUserCanResetPassword()andUserLockoutProperties.isLockedUserCanResetPassword()- Specified by:
canResetPasswordin interfaceUserLockoutService- Parameters:
user- The user to check- Returns:
- true if the user can reset their password, otherwise false.
-
unlockUserOnPasswordResetIfEligible
Description copied from interface:UserLockoutServiceAfter a password reset, unlock the user if they're eligible.See
AuthorizationServer.getResetPasswordUnlocksUser()andUserLockoutProperties.isResetPasswordUnlocksUser()- Specified by:
unlockUserOnPasswordResetIfEligiblein 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 fromUserLockoutPropertiesinstead. Otherwise, it returns null. SeeAuthorizationServer.changePasswordFailDecayMinutesorUserLockoutProperties.changePasswordFailDecayMinutesfor 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 fromUserLockoutPropertiesinstead. Otherwise, it returns null. SeeAuthorizationServer.resetPasswordFailDecayMinutesorUserLockoutProperties.resetPasswordFailDecayMinutesfor 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 fromUserLockoutPropertiesinstead. Otherwise, it returns the maximum Integer value. SeeAuthorizationServer.failedResetPasswordAttemptsAllowedorUserLockoutProperties.failedResetPasswordAttemptsAllowedfor 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 fromUserLockoutPropertiesinstead. Otherwise, it returns the maximum Integer value. SeeAuthorizationServer.failedChangePasswordAttemptsAllowedorUserLockoutProperties.failedChangePasswordAttemptsAllowedfor 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
-