Class StartPhoneEnrolmentUseCase

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

@Service @Transactional public class StartPhoneEnrolmentUseCase extends Object
Starts the enrolment of a phone: normalises the number and sends it a verification code.

What may be visible and what may not: an invalid number (InvalidPhoneNumberException) and a country that is not served (SmsCountryNotAllowedException) depend on the input alone and reveal nothing about any account, so they fail visibly. Everything that depends on the state of other accounts or of the system is indistinguishable from success: a number already verified by another user (no message is sent, no state is stored, but the same work is done), an exhausted SMS budget and a provider failure (the message is sent after the transaction commits, off the request thread, by the delivery of SmsRequested, which records a failure without the number or the code). Otherwise an attacker could learn which numbers belong to accounts.

  • Field Details

    • phoneNormalizer

      private final PhoneNormalizer phoneNormalizer
      Port that normalises the typed number.
    • phoneCountryResolver

      private final PhoneCountryResolver phoneCountryResolver
      Port that finds the country of a number.
    • userPhoneRepository

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

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

      private final OneTimeCodeGenerator oneTimeCodeGenerator
      Generator of the verification code.
    • oneTimeCodeHasher

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

      private final SendSmsOneTimeCodeUseCase sendSmsOneTimeCodeUseCase
      Use case that records the cost of the message and requests it.
    • smsProperties

      private final SmsProperties smsProperties
      SMS settings.
    • clock

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

    • StartPhoneEnrolmentUseCase

      public StartPhoneEnrolmentUseCase()
  • Method Details

    • execute

      public PhoneEnrolmentStarted execute(UUID userId, String phone)
      Starts the enrolment.
      Parameters:
      userId - identifier of the user.
      phone - the number as typed, with or without country code.
      Returns:
      the validity of the code; the same whether or not a message was sent.
      Throws:
      InvalidPhoneNumberException - if the text is not a valid number.
      SmsCountryNotAllowedException - if the country of the number is unknown or not served.
    • send

      private void send(PhoneNumber number, String code)
      Requests the code, swallowing a refusal so that it cannot be told apart from success.
      Parameters:
      number - the destination.
      code - the clear-text code.