Class JdbcFederatedIdentityRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.social.JdbcFederatedIdentityRepository
- All Implemented Interfaces:
FederatedIdentityRepository
@Repository
public class JdbcFederatedIdentityRepository
extends Object
implements FederatedIdentityRepository
FederatedIdentityRepository over the federated_identities table. It joins the transaction of its
caller, in which lockSubject(com.irurueta.authserver.authorization.domain.social.IdentityProvider, java.lang.String) takes a PostgreSQL transaction-level advisory lock on the provider's identity,
so two first sign-ins of the same person are serialized and the unique constraint on (provider, subject) is never
hit (a violation would abort the caller's transaction).-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringColumns selected for every query.private final FederatedIdentityRowMapperMaps a row to an identity.private static final StringQuery returning one link of an account.private static final StringQuery returning the link of a provider's subject.private static final StringQuery returning the links of an account, oldest first.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private static final StringStatement taking the advisory lock of an identity, released when the caller's transaction ends.(package private) static final intFirst key of the advisory locks of the identities, which keeps them apart from every other advisory lock.private static final StringStatement inserting a link, or updating the e-mail address and last sign-in of the one with the same id. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongcountByUser(UUID userId) Counts the identities linked to an account.booleanDeletes a link of an account.findByIdAndUser(UUID id, UUID userId) Finds one link of an account.findByProviderAndSubject(IdentityProvider provider, String subject) Finds the link of a provider's subject.findByUser(UUID userId) Lists the identities linked to an account, oldest link first.voidlockSubject(IdentityProvider provider, String subject) Serializes, until the caller's transaction ends, every caller that links or resolves the same identity of a provider, so that two first sign-ins of the same person never both try to link it: the second one waits and then finds the link of the first.save(FederatedIdentity identity) Stores a link, inserting it or updating the e-mail address and last sign-in instant of an existing one.
-
Field Details
-
SUBJECT_LOCK_NAMESPACE
static final int SUBJECT_LOCK_NAMESPACEFirst key of the advisory locks of the identities, which keeps them apart from every other advisory lock.- See Also:
-
LOCK_SUBJECT
Statement taking the advisory lock of an identity, released when the caller's transaction ends.- See Also:
-
COLUMNS
Columns selected for every query.- See Also:
-
FIND_BY_SUBJECT
Query returning the link of a provider's subject.- See Also:
-
FIND_BY_USER
Query returning the links of an account, oldest first.- See Also:
-
FIND_BY_ID_AND_USER
Query returning one link of an account.- See Also:
-
UPSERT
Statement inserting a link, or updating the e-mail address and last sign-in of the one with the same id.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
federatedIdentityRowMapper
Maps a row to an identity.
-
-
Constructor Details
-
JdbcFederatedIdentityRepository
public JdbcFederatedIdentityRepository()
-
-
Method Details
-
lockSubject
Description copied from interface:FederatedIdentityRepositorySerializes, until the caller's transaction ends, every caller that links or resolves the same identity of a provider, so that two first sign-ins of the same person never both try to link it: the second one waits and then finds the link of the first.- Specified by:
lockSubjectin interfaceFederatedIdentityRepository- Parameters:
provider- provider that holds the identity.subject- stable identifier the provider assigned to the user.
-
findByProviderAndSubject
public Optional<FederatedIdentity> findByProviderAndSubject(IdentityProvider provider, String subject) Description copied from interface:FederatedIdentityRepositoryFinds the link of a provider's subject.- Specified by:
findByProviderAndSubjectin interfaceFederatedIdentityRepository- Parameters:
provider- provider that holds the identity.subject- stable identifier the provider assigned to the user.- Returns:
- the link, or an empty optional when that identity is not linked to any account.
-
findByUser
Description copied from interface:FederatedIdentityRepositoryLists the identities linked to an account, oldest link first.- Specified by:
findByUserin interfaceFederatedIdentityRepository- Parameters:
userId- identifier of the account.- Returns:
- the links, possibly empty.
-
findByIdAndUser
Description copied from interface:FederatedIdentityRepositoryFinds one link of an account.- Specified by:
findByIdAndUserin interfaceFederatedIdentityRepository- Parameters:
id- identifier of the link.userId- identifier of the account, so nobody can reach another account's link.- Returns:
- the link, or an empty optional when the account has no such link.
-
save
Description copied from interface:FederatedIdentityRepositoryStores a link, inserting it or updating the e-mail address and last sign-in instant of an existing one.- Specified by:
savein interfaceFederatedIdentityRepository- Parameters:
identity- link to store.- Returns:
- the stored link.
-
delete
Description copied from interface:FederatedIdentityRepositoryDeletes a link of an account.- Specified by:
deletein interfaceFederatedIdentityRepository- Parameters:
id- identifier of the link.userId- identifier of the account.- Returns:
truewhen a link was deleted.
-
countByUser
Description copied from interface:FederatedIdentityRepositoryCounts the identities linked to an account.- Specified by:
countByUserin interfaceFederatedIdentityRepository- Parameters:
userId- identifier of the account.- Returns:
- the number of links.
-