Class ResolveFederatedLoginUseCase
java.lang.Object
com.irurueta.authserver.authorization.application.social.ResolveFederatedLoginUseCase
Use case that resolves a sign-in with an external provider to a local account. The provider's stable subject, never
its e-mail address, finds the account. The identity is locked first
(
FederatedIdentityRepository.lockSubject(com.irurueta.authserver.authorization.domain.social.IdentityProvider, java.lang.String)), so two concurrent first sign-ins of the same person are
serialized and the second one finds the link of the first instead of failing on the unique constraint. In order:
- an identity that is already linked signs in its account, unless the account is disabled;
- otherwise the provider must vouch for the e-mail address: an unverified address never links and never provisions;
- an account that has that address and has verified it too is linked to the identity, unless it is disabled: a disabled account is refused before anything is linked or audited;
- an address that belongs to an account that never verified it is refused, so a pre-registered account cannot capture the victim's sign-in;
- otherwise a new, enabled account is provisioned, whose password is a random one nobody knows.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClockSource of the current time.private final FederatedIdentityRepositoryPort that stores the links.private final FederatedLinkingPolicyRules of linking and provisioning.private final GeneratedPasswordRepositoryPort that remembers the accounts that only hold a generated password.(package private) static final intLongest username theuserstable accepts.private final PasswordHasherPort that hashes the generated password.private final RecordSecurityEventUseCaseUse case that records the audit events.private final TokenGeneratorPort that generates the unguessable secret the generated password is made of.private final UserAccountRepositoryPort that stores the accounts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecute(IdentityProvider provider, String subject, String email, boolean emailVerified) Resolves a sign-in.private FederatedIdentitylink(UserAccount account, IdentityProvider provider, String subject, String email, Instant now) Links an identity to an account and audits it.private UserAccountprovision(IdentityProvider provider, String email) Creates an enabled account from the provider's verified e-mail address.private voidrequireMaySignIn(UserAccount account) Refuses an account that may not sign in, before anything is linked, updated or audited.private FederatedLoginsignIn(FederatedIdentity identity, String email, Instant now) Signs in the account of an identity that is already linked, remembering the sign-in.
-
Field Details
-
MAX_USERNAME_LENGTH
static final int MAX_USERNAME_LENGTHLongest username theuserstable accepts.- See Also:
-
federatedIdentityRepository
Port that stores the links. -
userAccountRepository
Port that stores the accounts. -
generatedPasswordRepository
Port that remembers the accounts that only hold a generated password. -
passwordHasher
Port that hashes the generated password. -
tokenGenerator
Port that generates the unguessable secret the generated password is made of. -
federatedLinkingPolicy
Rules of linking and provisioning. -
recordSecurityEventUseCase
Use case that records the audit events. -
clock
Source of the current time.
-
-
Constructor Details
-
ResolveFederatedLoginUseCase
public ResolveFederatedLoginUseCase()
-
-
Method Details
-
execute
public FederatedLogin execute(IdentityProvider provider, String subject, String email, boolean emailVerified) Resolves a sign-in.- Parameters:
provider- provider that authenticated the user.subject- stable identifier the provider assigned to the user.email- e-mail address the provider reported, ornull.emailVerified- whether the provider says it verified the address.- Returns:
- the account the sign-in resolved to and how it was found.
- Throws:
FederatedLoginRefusedException- if the identity is not linked and the provider does not vouch for a usable e-mail address, the address belongs to an unverified account, or the account is disabled.
-
signIn
Signs in the account of an identity that is already linked, remembering the sign-in.- Parameters:
identity- the stored link.email- e-mail address the provider reported now, ornull.now- current instant.- Returns:
- the resolution.
-
requireMaySignIn
Refuses an account that may not sign in, before anything is linked, updated or audited.- Parameters:
account- the account the sign-in resolved to.- Throws:
FederatedLoginRefusedException- if the account is disabled.
-
link
private FederatedIdentity link(UserAccount account, IdentityProvider provider, String subject, String email, Instant now) Links an identity to an account and audits it.- Parameters:
account- the account.provider- provider of the identity.subject- subject of the identity.email- e-mail address the provider reported.now- current instant.- Returns:
- the stored link.
-
provision
Creates an enabled account from the provider's verified e-mail address. Its password is the hash of a random secret that is discarded, and the account is marked as having no password of its own.- Parameters:
provider- provider that vouched for the address.email- verified e-mail address.- Returns:
- the new account.
-