Class RequestPasswordResetUseCase

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

@Service public class RequestPasswordResetUseCase extends Object
Use case that starts a password reset. It always succeeds from the caller's point of view: an unknown address is never mailed (so the endpoint cannot be used to send mail to arbitrary addresses) and costs the same token work (a token is generated and hashed either way), so the response never reveals whether an address is registered. The token is stored and mailed in one transaction: if the mail cannot be sent, no usable token is left behind.
  • Field Details

    • RESET_TTL

      public static final Duration RESET_TTL
      How long a reset token stays valid.
    • 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.
    • accountMailer

      private final AccountMailer accountMailer
      Port that sends the e-mails.
    • clock

      private final Clock clock
      Source of the current time.
  • Constructor Details

    • RequestPasswordResetUseCase

      public RequestPasswordResetUseCase()
  • Method Details

    • execute

      @Transactional public void execute(String email)
      Requests a password reset.
      Parameters:
      email - e-mail address of the user.
    • sendReset

      private void sendReset(UserAccount account, String email, String token, String hashedToken)
      Stores the reset token and mails it.
      Parameters:
      account - the account to reset.
      email - address to send the message to.
      token - the reset token.
      hashedToken - hash of the reset token.