Package org.keycloak.storage.jpa
Class JpaUserFederatedStorageProvider
java.lang.Object
org.keycloak.storage.jpa.JpaUserFederatedStorageProvider
- All Implemented Interfaces:
UserCredentialStore
,Provider
,UserAttributeFederatedStorage
,UserBrokerLinkFederatedStorage
,UserConsentFederatedStorage
,UserFederatedStorageProvider
,UserFederatedUserCredentialStore
,UserGroupMembershipFederatedStorage
,UserNotBeforeFederatedStorage
,UserRequiredActionsFederatedStorage
,UserRoleMappingsFederatedStorage
public class JpaUserFederatedStorageProvider
extends Object
implements UserFederatedStorageProvider, UserCredentialStore
- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.keycloak.storage.federated.UserFederatedStorageProvider
UserFederatedStorageProvider.Streams
-
Field Summary
-
Constructor Summary
ConstructorDescriptionJpaUserFederatedStorageProvider
(KeycloakSession session, jakarta.persistence.EntityManager em) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConsent
(RealmModel realm, String userId, UserConsentModel consent) void
addFederatedIdentity
(RealmModel realm, String userId, FederatedIdentityModel link) void
addRequiredAction
(RealmModel realm, String userId, String action) void
close()
createCredential
(RealmModel realm, String userId, CredentialModel cred) createCredential
(RealmModel realm, UserModel user, CredentialModel cred) protected void
createIndex
(RealmModel realm, String userId) We create an entry so that its easy to iterate over all things in the database.void
deleteRoleMapping
(RealmModel realm, String userId, RoleModel role) getAttributes
(RealmModel realm, String userId) getConsentByClient
(RealmModel realm, String userId, String clientInternalId) getConsentsStream
(RealmModel realm, String userId) Obtains the consents associated with the federated user identified byuserId
.getFederatedIdentitiesStream
(String userId, RealmModel realm) Obtains the identities of the federated user identified byuserId
.getFederatedIdentity
(String userId, String socialProvider, RealmModel realm) getGroupsStream
(RealmModel realm, String userId) Obtains the groups associated with the federated user.getMembershipStream
(RealmModel realm, GroupModel group, Integer firstResult, Integer max) Obtains the federated users that are members of the givengroup
in the specifiedrealm
.int
getNotBeforeOfUser
(RealmModel realm, String userId) getRequiredActionsStream
(RealmModel realm, String userId) Obtains the names of required actions associated with the federated user identified byuserId
.getRoleMappingsStream
(RealmModel realm, String userId) Obtains the roles associated with the federated user identified byuserId
.getRoleMembersStream
(RealmModel realm, RoleModel role, Integer firstResult, Integer max) Obtains the federated users that are members of the givenrole
in the specifiedrealm
.getStoredCredentialById
(RealmModel realm, String userId, String id) getStoredCredentialById
(RealmModel realm, UserModel user, String id) getStoredCredentialByNameAndType
(RealmModel realm, String userId, String name, String type) getStoredCredentialByNameAndType
(RealmModel realm, UserModel user, String name, String type) getStoredCredentialsByTypeStream
(RealmModel realm, String userId, String type) Obtains the credentials of typetype
that are associated with the federated user identified byuserId
.getStoredCredentialsByTypeStream
(RealmModel realm, UserModel user, String type) Obtains the stored credentials associated with the specified user that match the specified type.getStoredCredentialsStream
(RealmModel realm, String userId) Obtains the credentials associated with the federated user identified byuserId
.getStoredCredentialsStream
(RealmModel realm, UserModel user) Obtains the stored credentials associated with the specified user.int
getStoredUsersCount
(RealmModel realm) getStoredUsersStream
(RealmModel realm, Integer first, Integer max) Obtains the ids of all federated users in the realm.getUserByFederatedIdentity
(FederatedIdentityModel link, RealmModel realm) getUsersByUserAttributeStream
(RealmModel realm, String name, String value) Searches for federated users that have an attribute with the specifiedname
andvalue
.void
grantRole
(RealmModel realm, String userId, RoleModel role) void
joinGroup
(RealmModel realm, String userId, GroupModel group) void
leaveGroup
(RealmModel realm, String userId, GroupModel group) boolean
moveCredentialTo
(RealmModel realm, UserModel user, String id, String newPreviousCredentialId) void
preRemove
(ClientScopeModel clientScope) void
preRemove
(ProtocolMapperModel protocolMapper) void
preRemove
(RealmModel realm) void
preRemove
(RealmModel realm, ComponentModel model) void
preRemove
(RealmModel realm, ClientModel client) void
preRemove
(RealmModel realm, GroupModel group) void
preRemove
(RealmModel realm, IdentityProviderModel provider) void
preRemove
(RealmModel realm, RoleModel role) void
preRemove
(RealmModel realm, UserModel user) void
removeAttribute
(RealmModel realm, String userId, String name) boolean
removeFederatedIdentity
(RealmModel realm, String userId, String socialProvider) void
removeRequiredAction
(RealmModel realm, String userId, String action) boolean
removeStoredCredential
(RealmModel realm, String userId, String id) boolean
removeStoredCredential
(RealmModel realm, UserModel user, String id) Removes credential with theid
for theuser
.boolean
revokeConsentForClient
(RealmModel realm, String userId, String clientInternalId) void
setAttribute
(RealmModel realm, String userId, String name, List<String> values) void
setNotBeforeForUser
(RealmModel realm, String userId, int notBefore) void
setSingleAttribute
(RealmModel realm, String userId, String name, String value) protected CredentialModel
toModel
(FederatedUserCredentialEntity entity) void
updateConsent
(RealmModel realm, String userId, UserConsentModel consent) void
updateCredential
(RealmModel realm, String userId, CredentialModel cred) void
updateCredential
(RealmModel realm, UserModel user, CredentialModel cred) void
updateFederatedIdentity
(RealmModel realm, String userId, FederatedIdentityModel model)
-
Field Details
-
logger
protected static final org.jboss.logging.Logger logger -
em
protected jakarta.persistence.EntityManager em
-
-
Constructor Details
-
JpaUserFederatedStorageProvider
public JpaUserFederatedStorageProvider(KeycloakSession session, jakarta.persistence.EntityManager em)
-
-
Method Details
-
close
public void close() -
createIndex
We create an entry so that its easy to iterate over all things in the database. Specifically useful for export -
setAttribute
- Specified by:
setAttribute
in interfaceUserAttributeFederatedStorage
-
setSingleAttribute
- Specified by:
setSingleAttribute
in interfaceUserAttributeFederatedStorage
-
removeAttribute
- Specified by:
removeAttribute
in interfaceUserAttributeFederatedStorage
-
getAttributes
- Specified by:
getAttributes
in interfaceUserAttributeFederatedStorage
-
getUsersByUserAttributeStream
Description copied from interface:UserAttributeFederatedStorage
Searches for federated users that have an attribute with the specifiedname
andvalue
.- Specified by:
getUsersByUserAttributeStream
in interfaceUserAttributeFederatedStorage
- Parameters:
realm
- a reference to the realm.name
- the attribute name.value
- the attribute value.- Returns:
- a non-null
Stream
of users that match the search criteria.
-
getUserByFederatedIdentity
- Specified by:
getUserByFederatedIdentity
in interfaceUserBrokerLinkFederatedStorage
-
addFederatedIdentity
- Specified by:
addFederatedIdentity
in interfaceUserBrokerLinkFederatedStorage
-
removeFederatedIdentity
- Specified by:
removeFederatedIdentity
in interfaceUserBrokerLinkFederatedStorage
-
preRemove
- Specified by:
preRemove
in interfaceUserBrokerLinkFederatedStorage
-
updateFederatedIdentity
- Specified by:
updateFederatedIdentity
in interfaceUserBrokerLinkFederatedStorage
-
getFederatedIdentitiesStream
Description copied from interface:UserBrokerLinkFederatedStorage
Obtains the identities of the federated user identified byuserId
.- Specified by:
getFederatedIdentitiesStream
in interfaceUserBrokerLinkFederatedStorage
- Parameters:
userId
- the user identifier.realm
- a reference to the realm.- Returns:
- a non-null
Stream
of federated identities associated with the user.
-
getFederatedIdentity
public FederatedIdentityModel getFederatedIdentity(String userId, String socialProvider, RealmModel realm) - Specified by:
getFederatedIdentity
in interfaceUserBrokerLinkFederatedStorage
-
addConsent
- Specified by:
addConsent
in interfaceUserConsentFederatedStorage
-
getConsentByClient
public UserConsentModel getConsentByClient(RealmModel realm, String userId, String clientInternalId) - Specified by:
getConsentByClient
in interfaceUserConsentFederatedStorage
-
getConsentsStream
Description copied from interface:UserConsentFederatedStorage
Obtains the consents associated with the federated user identified byuserId
.- Specified by:
getConsentsStream
in interfaceUserConsentFederatedStorage
- Parameters:
realm
- a reference to the realm.userId
- the user identifier.- Returns:
- a non-null
Stream
of consents associated with the user.
-
updateConsent
- Specified by:
updateConsent
in interfaceUserConsentFederatedStorage
-
revokeConsentForClient
- Specified by:
revokeConsentForClient
in interfaceUserConsentFederatedStorage
-
setNotBeforeForUser
- Specified by:
setNotBeforeForUser
in interfaceUserNotBeforeFederatedStorage
-
getNotBeforeOfUser
- Specified by:
getNotBeforeOfUser
in interfaceUserNotBeforeFederatedStorage
-
getGroupsStream
Description copied from interface:UserGroupMembershipFederatedStorage
Obtains the groups associated with the federated user.- Specified by:
getGroupsStream
in interfaceUserGroupMembershipFederatedStorage
- Parameters:
realm
- a reference to the realm.userId
- the user identifier.- Returns:
- a non-null
Stream
of groups.
-
joinGroup
- Specified by:
joinGroup
in interfaceUserGroupMembershipFederatedStorage
-
leaveGroup
- Specified by:
leaveGroup
in interfaceUserGroupMembershipFederatedStorage
-
getMembershipStream
public Stream<String> getMembershipStream(RealmModel realm, GroupModel group, Integer firstResult, Integer max) Description copied from interface:UserGroupMembershipFederatedStorage
Obtains the federated users that are members of the givengroup
in the specifiedrealm
.- Specified by:
getMembershipStream
in interfaceUserGroupMembershipFederatedStorage
- Parameters:
realm
- a reference to the realm.group
- a reference to the group whose federated members are being searched.firstResult
- first result to return. Ignored if negative ornull
.max
- maximum number of results to return. Ignored if negative ornull
.- Returns:
- a non-null
Stream
of federated user ids that are members of the group in the realm.
-
getRoleMembersStream
public Stream<String> getRoleMembersStream(RealmModel realm, RoleModel role, Integer firstResult, Integer max) Description copied from interface:UserRoleMappingsFederatedStorage
Obtains the federated users that are members of the givenrole
in the specifiedrealm
.- Specified by:
getRoleMembersStream
in interfaceUserRoleMappingsFederatedStorage
- Parameters:
realm
- a reference to the realm.role
- a reference to the role whose federated members are being searched.firstResult
- first result to return. Ignored if negative ornull
.max
- maximum number of results to return. Ignored if negative ornull
.- Returns:
- a non-null
Stream
of federated user ids that are members of the role in the realm.
-
getRequiredActionsStream
Description copied from interface:UserRequiredActionsFederatedStorage
Obtains the names of required actions associated with the federated user identified byuserId
.- Specified by:
getRequiredActionsStream
in interfaceUserRequiredActionsFederatedStorage
- Parameters:
realm
- a reference to the realm.userId
- the user identifier.- Returns:
- a non-null
Stream
of required action names.
-
addRequiredAction
- Specified by:
addRequiredAction
in interfaceUserRequiredActionsFederatedStorage
-
removeRequiredAction
- Specified by:
removeRequiredAction
in interfaceUserRequiredActionsFederatedStorage
-
grantRole
- Specified by:
grantRole
in interfaceUserRoleMappingsFederatedStorage
-
getRoleMappingsStream
Description copied from interface:UserRoleMappingsFederatedStorage
Obtains the roles associated with the federated user identified byuserId
.- Specified by:
getRoleMappingsStream
in interfaceUserRoleMappingsFederatedStorage
- Parameters:
realm
- a reference to the realm.userId
- the user identifier.- Returns:
- a non-null
Stream
of roles.
-
deleteRoleMapping
- Specified by:
deleteRoleMapping
in interfaceUserRoleMappingsFederatedStorage
-
updateCredential
- Specified by:
updateCredential
in interfaceUserFederatedUserCredentialStore
-
createCredential
- Specified by:
createCredential
in interfaceUserFederatedUserCredentialStore
-
removeStoredCredential
- Specified by:
removeStoredCredential
in interfaceUserFederatedUserCredentialStore
-
getStoredCredentialById
- Specified by:
getStoredCredentialById
in interfaceUserFederatedUserCredentialStore
-
toModel
-
getStoredCredentialsStream
Description copied from interface:UserFederatedUserCredentialStore
Obtains the credentials associated with the federated user identified byuserId
.- Specified by:
getStoredCredentialsStream
in interfaceUserFederatedUserCredentialStore
- Parameters:
realm
- a reference to the realm.userId
- the user identifier.- Returns:
- a non-null
Stream
of credentials.
-
getStoredCredentialsByTypeStream
public Stream<CredentialModel> getStoredCredentialsByTypeStream(RealmModel realm, String userId, String type) Description copied from interface:UserFederatedUserCredentialStore
Obtains the credentials of typetype
that are associated with the federated user identified byuserId
.- Specified by:
getStoredCredentialsByTypeStream
in interfaceUserFederatedUserCredentialStore
- Parameters:
realm
- a reference to the realm.userId
- the user identifier.type
- the credential type.- Returns:
- a non-null
Stream
of credentials.
-
getStoredCredentialByNameAndType
public CredentialModel getStoredCredentialByNameAndType(RealmModel realm, String userId, String name, String type) - Specified by:
getStoredCredentialByNameAndType
in interfaceUserFederatedUserCredentialStore
-
getStoredUsersStream
Description copied from interface:UserFederatedStorageProvider
Obtains the ids of all federated users in the realm.- Specified by:
getStoredUsersStream
in interfaceUserFederatedStorageProvider
- Parameters:
realm
- a reference to the realm.first
- first result to return. Ignored if negative ornull
.max
- maximum number of results to return. Ignored if negative ornull
.- Returns:
- a non-null
Stream
of federated user ids.
-
updateCredential
- Specified by:
updateCredential
in interfaceUserCredentialStore
-
createCredential
- Specified by:
createCredential
in interfaceUserCredentialStore
-
removeStoredCredential
Description copied from interface:UserCredentialStore
Removes credential with theid
for theuser
.- Specified by:
removeStoredCredential
in interfaceUserCredentialStore
- Parameters:
realm
- realm.user
- userid
- id- Returns:
true
if the credential was removed,false
otherwise TODO: Make this method return Boolean so that store can return "I don't know" answer, this can be used for example in async stores
-
getStoredCredentialById
- Specified by:
getStoredCredentialById
in interfaceUserCredentialStore
-
getStoredCredentialsStream
Description copied from interface:UserCredentialStore
Obtains the stored credentials associated with the specified user.- Specified by:
getStoredCredentialsStream
in interfaceUserCredentialStore
- Parameters:
realm
- a reference to the realm.user
- the user whose credentials are being searched.- Returns:
- a non-null
Stream
of credentials.
-
getStoredCredentialsByTypeStream
public Stream<CredentialModel> getStoredCredentialsByTypeStream(RealmModel realm, UserModel user, String type) Description copied from interface:UserCredentialStore
Obtains the stored credentials associated with the specified user that match the specified type.- Specified by:
getStoredCredentialsByTypeStream
in interfaceUserCredentialStore
- Parameters:
realm
- a reference to the realm.user
- the user whose credentials are being searched.type
- the type of credentials being searched.- Returns:
- a non-null
Stream
of credentials.
-
getStoredCredentialByNameAndType
public CredentialModel getStoredCredentialByNameAndType(RealmModel realm, UserModel user, String name, String type) - Specified by:
getStoredCredentialByNameAndType
in interfaceUserCredentialStore
-
moveCredentialTo
public boolean moveCredentialTo(RealmModel realm, UserModel user, String id, String newPreviousCredentialId) - Specified by:
moveCredentialTo
in interfaceUserCredentialStore
-
getStoredUsersCount
- Specified by:
getStoredUsersCount
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-
preRemove
- Specified by:
preRemove
in interfaceUserFederatedStorageProvider
-