Class ConfirmTotpUseCase

java.lang.Object
com.irurueta.authserver.authorization.application.totp.ConfirmTotpUseCase

@Service @Transactional public class ConfirmTotpUseCase extends Object
Use case that finishes the enrolment of an authenticator app with the first code it shows. The step of that code is stored so it cannot be replayed, the credential is confirmed and the recovery codes are generated.
  • Field Details

    • totpCredentialRepository

      private final TotpCredentialRepository totpCredentialRepository
      Port that stores the TOTP credentials.
    • totpSecretCipher

      private final TotpSecretCipher totpSecretCipher
      Port that decrypts the secrets.
    • totpAlgorithm

      private final TotpAlgorithm totpAlgorithm
      The TOTP algorithm.
    • generateRecoveryCodesUseCase

      private final GenerateRecoveryCodesUseCase generateRecoveryCodesUseCase
      Use case that creates the recovery codes.
    • clock

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

    • ConfirmTotpUseCase

      public ConfirmTotpUseCase()
  • Method Details

    • execute

      public List<String> execute(UUID userId, String code)
      Confirms the enrolment.
      Parameters:
      userId - identifier of the user.
      code - the code shown by the authenticator app.
      Returns:
      the clear-text recovery codes, to be shown once.
      Throws:
      TotpNotEnrolledException - if no enrolment was started.
      TotpAlreadyEnabledException - if the enrolment was already confirmed.
      InvalidTotpCodeException - if the code is wrong.
    • tryConfirm

      public Optional<List<String>> tryConfirm(UUID userId, String code)
      Confirms the enrolment, answering a wrong code with an empty result instead of an exception, so that a caller running in the same transaction can still count the failure (an exception leaving a transactional method marks the whole transaction for rollback).
      Parameters:
      userId - identifier of the user.
      code - the code shown by the authenticator app.
      Returns:
      the clear-text recovery codes, to be shown once; empty when the code is wrong.
      Throws:
      TotpNotEnrolledException - if no enrolment was started.
      TotpAlreadyEnabledException - if the enrolment was already confirmed.