Class ConfirmPhoneUseCase

java.lang.Object
com.irurueta.authserver.authorization.application.sms.ConfirmPhoneUseCase

@Service @Transactional public class ConfirmPhoneUseCase extends Object
Confirms a phone with the code that was sent to it. Every way of failing returns the same false: no pending verification, an expired or burnt code, a wrong code and a number that another user verified meanwhile.

Confirming a number other than the verified one replaces a second factor: the replacement is audited as the removal of the old phone, and every trusted device of the user is revoked, as disabling TOTP does, because those browsers were remembered in place of a factor the user no longer has.

  • Field Details

    • REPLACED_DETAIL

      static final String REPLACED_DETAIL
      Start of the detail of the audit event of a replaced phone, followed by the number of revoked devices.
      See Also:
    • userPhoneRepository

      private final UserPhoneRepository userPhoneRepository
      Port that stores the verified phones.
    • phoneVerificationRepository

      private final PhoneVerificationRepository phoneVerificationRepository
      Port that stores the pending verification.
    • oneTimeCodeHasher

      private final OneTimeCodeHasher oneTimeCodeHasher
      Hasher of the verification code.
    • trustedDeviceRepository

      private final TrustedDeviceRepository trustedDeviceRepository
      Port that stores the trusted devices.
    • recordSecurityEventUseCase

      private final RecordSecurityEventUseCase recordSecurityEventUseCase
      Use case that records the audit events.
    • smsProperties

      private final SmsProperties smsProperties
      SMS settings.
    • clock

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

    • ConfirmPhoneUseCase

      public ConfirmPhoneUseCase()
  • Method Details

    • execute

      public boolean execute(UUID userId, String username, String code)
      Confirms the phone of a user.
      Parameters:
      userId - identifier of the user.
      username - name of the user, for the audit log.
      code - the code as typed.
      Returns:
      true when the code was right and the phone is now verified.
    • verify

      private boolean verify(UUID userId, String username, PhoneVerification pending, Instant now)
      Stores the verified phone, clears the pending verification and handles the replacement of another number.
      Parameters:
      userId - identifier of the user.
      username - name of the user, for the audit log.
      pending - the verification that was confirmed.
      now - the current instant.
      Returns:
      true when the phone was stored, false when another user owns the number.