Class RequestOneTimeCodeUseCase
The request is enumeration-safe: for an unknown identifier, a disabled account or an account without a verified
address for the channel nothing is stored or sent, yet the same result is returned and a code is still generated
and hashed, so the work done is alike. The code is never delivered inside this transaction: an e-mail is requested
through an EmailCodeRequested event and an SMS through SendSmsOneTimeCodeUseCase, which records its
cost and publishes an SmsRequested event; both are handled after the transaction commits and off the request
thread, so no remote call holds a database connection and the latency of the mail server or the SMS gateway cannot
tell an existing account from an unknown one. A refused SMS (country, budget) is not reported to the caller.
A new code replaces the previous one of the same binding and user (the repository saves one active code per binding and username). Magic links are not handled here: they use the framework's token service.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClockSource of the current time.private final org.springframework.context.ApplicationEventPublisherPublishes the request of an e-mail delivery.private final OneTimeCodeGeneratorGenerator of codes.private final OneTimeCodeHasherHasher of codes.private final OneTimeCodeRepositoryPort that stores the codes.private final OttPolicyPolicy of the codes.private final ResolveOttDestinationUseCaseUse case that finds where the code is delivered.private final SendSmsOneTimeCodeUseCaseUse case that records the cost of an SMS and requests its delivery. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecute(String identifier, OttChannel channel, OttPurpose purpose, String bindingId) Requests a code.private voidrequestDelivery(OttDestination destination, String code, Duration ttl) Requests the delivery of a code, swallowing an SMS refusal so that it cannot be told apart from success.
-
Field Details
-
resolveOttDestinationUseCase
Use case that finds where the code is delivered. -
oneTimeCodeGenerator
Generator of codes. -
oneTimeCodeHasher
Hasher of codes. -
oneTimeCodeRepository
Port that stores the codes. -
eventPublisher
private final org.springframework.context.ApplicationEventPublisher eventPublisherPublishes the request of an e-mail delivery. -
sendSmsOneTimeCodeUseCase
Use case that records the cost of an SMS and requests its delivery. -
ottPolicy
Policy of the codes. -
clock
Source of the current time.
-
-
Constructor Details
-
RequestOneTimeCodeUseCase
public RequestOneTimeCodeUseCase()
-
-
Method Details
-
execute
public OneTimeCodeRequestResult execute(String identifier, OttChannel channel, OttPurpose purpose, String bindingId) Requests a code.- Parameters:
identifier- the name the user signs in with, as typed.channel- the channel to deliver the code through.purpose- what the code is for.bindingId- identifier of the sign-in attempt the code is bound to (for example the session id).- Returns:
- the same result for every identifier.
-
requestDelivery
Requests the delivery of a code, swallowing an SMS refusal so that it cannot be told apart from success.- Parameters:
destination- where to deliver it.code- the clear-text code.ttl- how long it is valid.
-