Class StartPhoneEnrolmentUseCase
java.lang.Object
com.irurueta.authserver.authorization.application.sms.StartPhoneEnrolmentUseCase
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final ClockSource of the current time.private final OneTimeCodeGeneratorGenerator of the verification code.private final OneTimeCodeHasherHasher of the verification code.private final PhoneCountryResolverPort that finds the country of a number.private final PhoneNormalizerPort that normalises the typed number.private final PhoneVerificationRepositoryPort that stores the pending verification.private final SendSmsOneTimeCodeUseCaseUse case that records the cost of the message and requests it.private final SmsPropertiesSMS settings.private final UserPhoneRepositoryPort that reads the verified phones. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionStarts the enrolment.private voidsend(PhoneNumber number, String code) Requests the code, swallowing a refusal so that it cannot be told apart from success.
-
Field Details
-
phoneNormalizer
Port that normalises the typed number. -
phoneCountryResolver
Port that finds the country of a number. -
userPhoneRepository
Port that reads the verified phones. -
phoneVerificationRepository
Port that stores the pending verification. -
oneTimeCodeGenerator
Generator of the verification code. -
oneTimeCodeHasher
Hasher of the verification code. -
sendSmsOneTimeCodeUseCase
Use case that records the cost of the message and requests it. -
smsProperties
SMS settings. -
clock
Source of the current time.
-
-
Constructor Details
-
StartPhoneEnrolmentUseCase
public StartPhoneEnrolmentUseCase()
-
-
Method Details
-
execute
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
Requests the code, swallowing a refusal so that it cannot be told apart from success.- Parameters:
number- the destination.code- the clear-text code.
-