Class ResetPasswordUseCase

java.lang.Object
com.irurueta.authserver.authorization.application.account.ResetPasswordUseCase

@Service public class ResetPasswordUseCase extends Object
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 Details

    • userAccountRepository

      private final UserAccountRepository userAccountRepository
      Port that stores the accounts.
    • accountTokenRepository

      private final AccountTokenRepository accountTokenRepository
      Port that stores the reset tokens.
    • tokenGenerator

      private final TokenGenerator tokenGenerator
      Port that creates and hashes tokens.
    • passwordHasher

      private final PasswordHasher passwordHasher
      Port that hashes passwords.
    • compromisedPasswordCheck

      private final CompromisedPasswordCheck compromisedPasswordCheck
      Port that checks passwords against leaked ones.
    • revokeUserAuthorizationsUseCase

      private final RevokeUserAuthorizationsUseCase revokeUserAuthorizationsUseCase
      Use case that revokes the tokens of the user.
    • clock

      private final Clock clock
      Source of the current time.
    • passwordPolicy

      private final PasswordPolicy passwordPolicy
      Rules a new password must follow.
  • Constructor Details

    • ResetPasswordUseCase

      public ResetPasswordUseCase()
  • Method Details

    • execute

      @Transactional public void execute(String token, String newPassword)
      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

      private void requirePolicy(String username, String password)
      Rejects a password that breaks the policy.
      Parameters:
      username - name of the account the password is for.
      password - the clear-text password.
    • requireNotCompromised

      private void requireNotCompromised(String password)
      Rejects a compromised password.
      Parameters:
      password - the clear-text password.