Class RegisterAccountUseCase

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

@Service public class RegisterAccountUseCase extends Object
Use case that registers an account. The account starts disabled and unverified; a signed verification token is e-mailed to the address. The answer is always the same and the password is always hashed, so neither the answer nor its timing reveals whether the address or the username is taken. What the address receives differs only where its owner learns nothing new:
  • a registered address gets a neutral "already registered" message: its owner already knows it has an account;
  • a new address with a taken username gets the usual verification message, whose token names no account, so following it fails exactly like an expired link. The username is never confirmed to whoever controls the address, so the endpoint cannot be used to find out which usernames exist.
The account is saved and the message sent in one transaction: if the mail cannot be sent, nothing is registered.
  • Field Details

    • DEFAULT_AUTHORITY

      public static final String DEFAULT_AUTHORITY
      Authority granted to registered accounts.
      See Also:
    • VERIFICATION_TTL

      public static final Duration VERIFICATION_TTL
      How long the e-mailed verification token stays valid.
    • userAccountRepository

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

      private final PasswordHasher passwordHasher
      Port that hashes passwords.
    • compromisedPasswordCheck

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

      private final SignedTokenService signedTokenService
      Port that issues the verification token.
    • accountMailer

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

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

    • RegisterAccountUseCase

      public RegisterAccountUseCase()
  • Method Details

    • execute

      @Transactional public void execute(String username, String email, String password)
      Registers an account.
      Parameters:
      username - name the user will sign in with.
      email - e-mail address of the user.
      password - the chosen clear-text password.
      Throws:
      InvalidPasswordException - if the password breaks the policy.
      CompromisedPasswordException - if the password is known to be compromised.