Class ResetPasswordUseCase
java.lang.Object
com.irurueta.authserver.authorization.application.account.ResetPasswordUseCase
Use case that chooses a new password with the single-use token received by e-mail. Every check (token, account,
password policy including the username rule, compromised-password check) runs before the token is consumed, so a
rejected password never burns the token; consuming it, storing the new hash and revoking every token of the user
then happen in one transaction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AccountTokenRepositoryPort that stores the reset tokens.private final ClockSource of the current time.private final CompromisedPasswordCheckPort that checks passwords against leaked ones.private final PasswordHasherPort that hashes passwords.private final PasswordPolicyRules a new password must follow.private final RevokeUserAuthorizationsUseCaseUse case that revokes the tokens of the user.private final TokenGeneratorPort that creates and hashes tokens.private final UserAccountRepositoryPort that stores the accounts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidResets the password of the user the token was issued to.private voidrequireNotCompromised(String password) Rejects a compromised password.private voidrequirePolicy(String username, String password) Rejects a password that breaks the policy.
-
Field Details
-
userAccountRepository
Port that stores the accounts. -
accountTokenRepository
Port that stores the reset tokens. -
tokenGenerator
Port that creates and hashes tokens. -
passwordHasher
Port that hashes passwords. -
compromisedPasswordCheck
Port that checks passwords against leaked ones. -
revokeUserAuthorizationsUseCase
Use case that revokes the tokens of the user. -
clock
Source of the current time. -
passwordPolicy
Rules a new password must follow.
-
-
Constructor Details
-
ResetPasswordUseCase
public ResetPasswordUseCase()
-
-
Method Details
-
execute
Resets the password of the user the token was issued to. The token is looked up without being consumed, every check runs, and only then is the token consumed; the consumption is atomic, so of two concurrent resets with the same token only one succeeds.- Parameters:
token- the reset token received by e-mail.newPassword- the clear-text new password.- Throws:
InvalidPasswordException- if the password breaks the policy.CompromisedPasswordException- if the password is known to be compromised.InvalidAccountTokenException- if the token is unknown, expired, used or its account is gone.
-
requirePolicy
Rejects a password that breaks the policy.- Parameters:
username- name of the account the password is for.password- the clear-text password.
-
requireNotCompromised
Rejects a compromised password.- Parameters:
password- the clear-text password.
-