Class PasswordService
- All Implemented Interfaces:
AbstractPasswordService
This class implements password authentication.
Like all service classes, this class holds only configuration state. Thus, once configured, it can be safely shared between multiple sessions since its state (the configuration) is read-only.
Passwords are (usually) saved in the database using salted hash functions. The process of
computing new hashes, and verifying them is delegated to an PasswordService.AbstractVerifier.
The authentication class may be configured to enable password attempt throttling. This provides protection against brute force guessing of passwords. When throttling is enabled, new password attempts are refused until the throttling period is finished.
Password strength validation of a new user-chosen password may be implemented by setting an AbstractStrengthValidator.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAbstract password hash computation and verification class.Nested classes/interfaces inherited from interface eu.webtoolkit.jwt.auth.AbstractPasswordService
AbstractPasswordService.AbstractStrengthValidator, AbstractPasswordService.StrengthValidatorResult -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdelayForNextAttempt(User user) Returns the delay for this user for a next authentication attempt.protected intgetAuthenticationThrottle(int failedAttempts) Returns how much throttle should be given considering a number of failed authentication attempts.Returns the basic authentication service.Returns the class instance managing the throttling delay.Returns the password strength validator.Returns the password verifier.booleanReturns whether password attempt throttling is enabled.voidsetAttemptThrottlingEnabled(boolean enabled) Configures password attempt throttling.voidsetPasswordThrottle(AuthThrottle delayer) Sets the class instance managing the throttling delay.voidSets a validator which computes password strength.voidsetVerifier(PasswordService.AbstractVerifier verifier) Sets a password verifier which computes authorization checks.voidupdatePassword(User user, String password) Sets a new password for the given user.verifyPassword(User user, String password) Verifies a password for a given user.
-
Constructor Details
-
PasswordService
Constructor.Creates a new password authentication service, which depends on the passed basic authentication service.
-
-
Method Details
-
getBaseAuth
Description copied from interface:AbstractPasswordServiceReturns the basic authentication service.- Specified by:
getBaseAuthin interfaceAbstractPasswordService
-
setVerifier
Sets a password verifier which computes authorization checks.The password verifier has as task to verify an entered password against a password hash stored in the database, and also to create or update a user's password hash.
The default password verifier is
null. -
getVerifier
Returns the password verifier. -
setStrengthValidator
Sets a validator which computes password strength.The default password strength validator is
null. -
getStrengthValidator
Returns the password strength validator.- Specified by:
getStrengthValidatorin interfaceAbstractPasswordService- See Also:
-
setPasswordThrottle
Sets the class instance managing the throttling delay. -
getPasswordThrottle
Returns the class instance managing the throttling delay.- Specified by:
getPasswordThrottlein interfaceAbstractPasswordService- See Also:
-
setAttemptThrottlingEnabled
public void setAttemptThrottlingEnabled(boolean enabled) Configures password attempt throttling.When password throttling is enabled, new password verification attempts will be refused when the user has had too many unsuccessful authentication attempts in a row.
The exact back-off schema can be customized by specializing
AuthThrottle#getAuthenticationThrottle(). -
isAttemptThrottlingEnabled
public boolean isAttemptThrottlingEnabled()Returns whether password attempt throttling is enabled.- Specified by:
isAttemptThrottlingEnabledin interfaceAbstractPasswordService- See Also:
-
delayForNextAttempt
Returns the delay for this user for a next authentication attempt.The implementation of this functionality is managed by
AuthThrottle.- Specified by:
delayForNextAttemptin interfaceAbstractPasswordService- See Also:
-
verifyPassword
Verifies a password for a given user.The supplied password is verified against the user's credentials stored in the database. If password account throttling is enabled, it may also refuse an authentication attempt.
-
updatePassword
Description copied from interface:AbstractPasswordServiceSets a new password for the given user.This stores a new password for the user in the database.
- Specified by:
updatePasswordin interfaceAbstractPasswordService
-
getAuthenticationThrottle
protected int getAuthenticationThrottle(int failedAttempts) Returns how much throttle should be given considering a number of failed authentication attempts.
-