Class RealmCacheSession
- java.lang.Object
- 
- org.keycloak.models.cache.infinispan.RealmCacheSession
 
- 
- All Implemented Interfaces:
- CacheRealmProvider,- ClientProvider,- ClientScopeProvider,- GroupProvider,- RealmProvider,- RoleProvider,- Provider,- ClientLookupProvider,- ClientScopeLookupProvider,- GroupLookupProvider,- RoleLookupProvider
 
 public class RealmCacheSession extends Object implements CacheRealmProvider - the high level architecture of this cache is an invalidation cache. - the cache is manual/custom versioned. When a model is updated, we remove it from the cache which causes an invalidation message to be sent across the cluster. - We had to do it this way because Infinispan REPEATABLE_READ wouldn't cut it in invalidation mode. Also, REPEATABLE_READ doesn't work very well on relationships and items that are not in the cache. - There are two Infinispan caches. One clustered that holds actual objects and a another local one that holds revision numbers of cached objects. Whenever a cached object is removed (invalidated), the local revision cache number or that key is bumped higher based on a local version counter. Whenever a cache entry is fetched, this revision number is also fetched and compared against the revision number in the cache entry to see if the cache entry is stale. Whenever a cache entry is added, this revision number is also checked against the revision cache. - Revision entries are actually never removed (although they could be evicted by cache eviction policies). The reason for this is that it is possible for a stale object to be inserted if one thread loads and the data is updated in the database before it is added to the cache. So, we keep the version number around for this. - In a transaction, objects are registered to be invalidated. If an object is marked for invalidation within a transaction a cached object should never be returned. An DB adapter should always be returned. - After DB commits, the objects marked for invalidation are invalidated, or rather removed from the cache. At this time the revision cache entry for this object has its version number bumped. - Whenever an object is marked for invalidation, the cache is also searched for any objects that are related to this object and need to also be evicted/removed. We use the Infinispan Stream SPI for this. ClientList caches: - lists of clients are cached in a specific cache entry i.e. realm clients, find client by clientId - realm client lists need to be invalidated and evited whenever a client is added or removed from a realm. RealmProvider now has addClient/removeClient at its top level. All adapaters should use these methods so that the appropriate invalidations can be registered. - whenever a client is added/removed the realm of the client is added to a listInvalidations set this set must be checked before sending back or caching a cached query. This check is required to avoid caching an uncommitted removal/add in a query cache. - when a client is removed, any queries that contain that client must also be removed. - a client removal will also cause anything that is contained and cached within that client to be removed Clustered caches: - There is a Infinispan @Listener registered. If an invalidation event happens, this is treated like the object was removed from the database and will perform evictions based on that assumption. - Eviction events will also cascade other evictions, but not assume this is a db removal. - With an invalidation cache, if you remove an entry on node 1 and this entry does not exist on node 2, node 2 will not receive a @Listener invalidation event. so, hat we have to put a marker entry in the invalidation cache before we read from the DB, so if the DB changes in between reading and adding a cache entry, the cache will be notified and bump the version information. DBs with Repeatable Read: - DBs like MySQL are Repeatable Read by default. So, if you query a Client for instance, it will always return the same result in the same transaction even if the DB was updated in between these queries. This makes it possible to store stale cache entries. To avoid this problem, this class stores the current local version counter at the beginningof the transaction. Whenever an entry is added to the cache, the current coutner is compared against the counter at the beginning of the tx. If the current is greater, then don't cache. Groups and Roles: - roles are tricky because of composites. Composite lists are cached too. So, when a role is removed we also iterate and invalidate any role or group that contains that role being removed. - any relationship should be resolved from session.realms(). For example if JPA.getClientByClientId() is invoked, JPA should find the id of the client and then call session.realms().getClientById(). THis is to ensure that the cached object is invoked and all proper invalidation are being invoked.- Version:
- $Revision: 1 $
- Author:
- Bill Burke
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected RealmCacheManagercacheprotected booleanclearAllprotected ClientProviderclientDelegateprotected ClientScopeProviderclientScopeDelegateprotected GroupProvidergroupDelegateprotected Set<InvalidationEvent>invalidationEventsprotected Set<String>invalidationsprotected Set<String>listInvalidationsprotected static org.jboss.logging.Loggerloggerprotected Map<String,ClientModel>managedApplicationsprotected Map<String,ClientScopeAdapter>managedClientScopesprotected Map<String,GroupAdapter>managedGroupsprotected Map<String,RealmAdapter>managedRealmsprotected Map<String,RoleAdapter>managedRolesstatic StringREALM_CLIENTS_QUERY_SUFFIXprotected RealmProviderrealmDelegateprotected RoleProviderroleDelegatestatic StringROLES_QUERY_SUFFIXprotected KeycloakSessionsessionprotected booleansetRollbackOnlyprotected longstartupRevisionprotected booleantransactionActive
 - 
Constructor SummaryConstructors Constructor Description RealmCacheSession(RealmCacheManager cache, KeycloakSession session)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientModeladdClient(RealmModel realm, String clientId)Adds a client with givenclientIdto the given realm.ClientModeladdClient(RealmModel realm, String id, String clientId)Adds a client with given internal ID andclientIdto the given realm.RoleModeladdClientRole(ClientModel client, String name)Adds a client role with givennameto the given client.RoleModeladdClientRole(ClientModel client, String id, String name)Adds a client role with given internal ID andnameto the given client.ClientScopeModeladdClientScope(RealmModel realm, String name)Creates new client scope with givennameto the given realm.ClientScopeModeladdClientScope(RealmModel realm, String id, String name)Creates new client scope with given internal ID andnameto the given realm.voidaddClientScopes(RealmModel realm, ClientModel client, Set<ClientScopeModel> clientScopes, boolean defaultScope)Assign clientScopes to the client.RoleModeladdRealmRole(RealmModel realm, String name)Adds a realm role with givennameto the given realm.RoleModeladdRealmRole(RealmModel realm, String id, String name)Adds a realm role with given internal ID andnameto the given realm.voidaddTopLevelGroup(RealmModel realm, GroupModel subGroup)Removes parent group for the given group in the given realm.protected ClientModelcacheClient(RealmModel realm, ClientModel delegate, Long revision)voidclear()voidclose()ClientInitialAccessModelcreateClientInitialAccessModel(RealmModel realm, int expiration, int count)GroupModelcreateGroup(RealmModel realm, String id, String name, GroupModel toParent)Creates a new group with the given name, id, name and parent to the given realm.RealmModelcreateRealm(String name)Creates new realm with the given name.RealmModelcreateRealm(String id, String name)Created new realm with given ID and name.booleandeleteLocalizationText(RealmModel realm, String locale, String key)booleandeleteLocalizationTextsByLocale(RealmModel realm, String locale)voidevictRealmOnRemoval(RealmModel realm)Map<ClientModel,Set<String>>getAllRedirectUrisOfEnabledClients(RealmModel realm)Returns a map of (rootUrl, {validRedirectUris}) for all enabled clients.Stream<ClientModel>getAlwaysDisplayInConsoleClientsStream(RealmModel realm)Returns a stream of clients that are expected to always show up in account console.ClientModelgetClientByClientId(RealmModel realm, String clientId)Exact search for a client by its public client identifier.ClientModelgetClientById(RealmModel realm, String id)Exact search for a client by its internal ID.ClientProvidergetClientDelegate()ClientInitialAccessModelgetClientInitialAccessModel(RealmModel realm, String id)RoleModelgetClientRole(ClientModel client, String name)Exact search for a client role by given name.Stream<RoleModel>getClientRolesStream(ClientModel client)Returns all the client roles of the given client.Stream<RoleModel>getClientRolesStream(ClientModel client, Integer first, Integer max)Returns the client roles of the given client.ClientScopeModelgetClientScopeById(RealmModel realm, String id)Exact search for a client scope by its internal ID..ClientScopeProvidergetClientScopeDelegate()Map<String,ClientScopeModel>getClientScopes(RealmModel realm, ClientModel client, boolean defaultScopes)Return all default scopes (ifdefaultScopeistrue) or all optional scopes (ifdefaultScopeisfalse) linked with the clientStream<ClientScopeModel>getClientScopesStream(RealmModel realm)Returns all the client scopes of the given realm as a stream.longgetClientsCount(RealmModel realm)Returns number of clients in the given realmStream<ClientModel>getClientsStream(RealmModel realm)Returns all the clients of the given realm as a stream.Stream<ClientModel>getClientsStream(RealmModel realm, Integer firstResult, Integer maxResults)Returns the clients of the given realm as a stream.GroupModelgetGroupById(RealmModel realm, String id)Returns a group from the given realm with the corresponding idGroupProvidergetGroupDelegate()Stream<GroupModel>getGroupsByRoleStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults)Returns groups with the given role in the given realm.LonggetGroupsCount(RealmModel realm, Boolean onlyTopGroups)Returns a number of groups/top level groups (i.e.LonggetGroupsCount(RealmModel realm, Stream<String> ids, String search)Returns a number of groups that contains the search string in the nameLonggetGroupsCountByNameContaining(RealmModel realm, String search)Returns the number of top level groups containing groups with the given string in name for the given realm.Stream<GroupModel>getGroupsStream(RealmModel realm)Returns groups for the given realm.Stream<GroupModel>getGroupsStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max)Returns a paginated stream of groups with given ids and given search value in group names.StringgetLocalizationTextsById(RealmModel realm, String locale, String key)RealmModelgetRealm(String id)Exact search for a realm by its internal ID.RealmModelgetRealmByName(String name)Exact search for a realm by its name.RealmProvidergetRealmDelegate()RoleModelgetRealmRole(RealmModel realm, String name)Exact search for a role by given name.Stream<RoleModel>getRealmRolesStream(RealmModel realm)Returns all the realm roles of the given realm as a stream.Stream<RoleModel>getRealmRolesStream(RealmModel realm, Integer first, Integer max)Returns the realm roles of the given realm as a stream.Stream<RealmModel>getRealmsStream()Returns realms as a stream.Stream<RealmModel>getRealmsWithProviderTypeStream(Class<?> type)Returns stream of realms which has component with the given provider type.RoleModelgetRoleById(RealmModel realm, String id)Exact search for a role by its internal ID..RoleProvidergetRoleDelegate()Stream<RoleModel>getRolesStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max)Returns a paginated stream of roles with given ids and given search value in role names.longgetStartupRevision()Stream<GroupModel>getTopLevelGroupsStream(RealmModel realm)Returns all top level groups (i.e.Stream<GroupModel>getTopLevelGroupsStream(RealmModel realm, Integer first, Integer max)Returns top level groups (i.e.booleanisInvalid(String id)Stream<ClientInitialAccessModel>listClientInitialAccessStream(RealmModel realm)Returns client's initial access as a stream.voidmoveGroup(RealmModel realm, GroupModel group, GroupModel toParent)This method is used for moving groups in group structure, for example: making an existing child group child group of some other group, setting a top level group (i.e.voidregisterClientInvalidation(String id, String clientId, String realmId)voidregisterClientScopeInvalidation(String id, String realmId)voidregisterGroupInvalidation(String id)voidregisterRealmInvalidation(String id, String name)voidregisterRoleInvalidation(String id, String roleName, String roleContainerId)booleanremoveClient(RealmModel realm, String id)Removes given client from the given realm.voidremoveClientInitialAccessModel(RealmModel realm, String id)voidremoveClients(RealmModel realm)Removes all clients from the given realm.booleanremoveClientScope(RealmModel realm, String id)Removes client scope from the given realm.voidremoveClientScope(RealmModel realm, ClientModel client, ClientScopeModel clientScope)Unassign clientScope from the client.voidremoveClientScopes(RealmModel realm)Removes all client scopes from the given realm.voidremoveExpiredClientInitialAccess()Removes all expired client initial accesses from all realms.booleanremoveGroup(RealmModel realm, GroupModel group)Removes the given group for the given realm.booleanremoveRealm(String id)Removes realm with the given id.booleanremoveRole(RoleModel role)Removes given realm role from the given realm.voidremoveRoles(ClientModel client)Removes all roles from the given client.voidremoveRoles(RealmModel realm)Removes all roles from the given realm.protected voidrunInvalidations()voidsaveLocalizationText(RealmModel realm, String locale, String key, String text)voidsaveLocalizationTexts(RealmModel realm, String locale, Map<String,String> localizationTexts)Stream<ClientModel>searchClientsByAttributes(RealmModel realm, Map<String,String> attributes, Integer firstResult, Integer maxResults)Stream<ClientModel>searchClientsByClientIdStream(RealmModel realm, String clientId, Integer firstResult, Integer maxResults)Case-insensitive search for clients that contain the given string in their public client identifier.Stream<RoleModel>searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max)Case-insensitive search for client roles that contain the given string in their name or description.Stream<GroupModel>searchForGroupByNameStream(RealmModel realm, String search, Boolean exact, Integer firstResult, Integer maxResults)Returns the group hierarchy with the given string in name for the given realm.Stream<GroupModel>searchForGroupByNameStream(RealmModel realm, String search, Integer first, Integer max)Returns the group hierarchy with the given string in name for the given realm.Stream<RoleModel>searchForRolesStream(RealmModel realm, String search, Integer first, Integer max)Case-insensitive search for roles that contain the given string in their name or description.Stream<GroupModel>searchGroupsByAttributes(RealmModel realm, Map<String,String> attributes, Integer firstResult, Integer maxResults)Returns the groups filtered by attribute names and attribute values for the given realm.booleanupdateLocalizationText(RealmModel realm, String locale, String key, String text)protected ClientModelvalidateCache(RealmModel realm, CachedClient cached)- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.models.GroupProvidergetGroupsStream, getGroupsStream
 - 
Methods inherited from interface org.keycloak.models.RealmProvideraddClientRole, addClientRole, createGroup, createGroup, createGroup, decreaseRemainingCount, getClientRole, getClientRoles, getClientRoles, getClientScopeById, getRealmRoles, getRoleById, removeRole, searchForClientRoles, searchForRoles
 
- 
 
- 
- 
- 
Field Detail- 
loggerprotected static final org.jboss.logging.Logger logger 
 - 
REALM_CLIENTS_QUERY_SUFFIXpublic static final String REALM_CLIENTS_QUERY_SUFFIX - See Also:
- Constant Field Values
 
 - 
ROLES_QUERY_SUFFIXpublic static final String ROLES_QUERY_SUFFIX - See Also:
- Constant Field Values
 
 - 
cacheprotected RealmCacheManager cache 
 - 
sessionprotected KeycloakSession session 
 - 
realmDelegateprotected RealmProvider realmDelegate 
 - 
clientDelegateprotected ClientProvider clientDelegate 
 - 
clientScopeDelegateprotected ClientScopeProvider clientScopeDelegate 
 - 
groupDelegateprotected GroupProvider groupDelegate 
 - 
roleDelegateprotected RoleProvider roleDelegate 
 - 
transactionActiveprotected boolean transactionActive 
 - 
setRollbackOnlyprotected boolean setRollbackOnly 
 - 
managedRealmsprotected Map<String,RealmAdapter> managedRealms 
 - 
managedApplicationsprotected Map<String,ClientModel> managedApplications 
 - 
managedClientScopesprotected Map<String,ClientScopeAdapter> managedClientScopes 
 - 
managedRolesprotected Map<String,RoleAdapter> managedRoles 
 - 
managedGroupsprotected Map<String,GroupAdapter> managedGroups 
 - 
invalidationEventsprotected Set<InvalidationEvent> invalidationEvents 
 - 
clearAllprotected boolean clearAll 
 - 
startupRevisionprotected final long startupRevision 
 
- 
 - 
Constructor Detail- 
RealmCacheSessionpublic RealmCacheSession(RealmCacheManager cache, KeycloakSession session) 
 
- 
 - 
Method Detail- 
getStartupRevisionpublic long getStartupRevision() 
 - 
isInvalidpublic boolean isInvalid(String id) 
 - 
clearpublic void clear() - Specified by:
- clearin interface- CacheRealmProvider
 
 - 
getRealmDelegatepublic RealmProvider getRealmDelegate() - Specified by:
- getRealmDelegatein interface- CacheRealmProvider
 
 - 
getClientDelegatepublic ClientProvider getClientDelegate() 
 - 
getClientScopeDelegatepublic ClientScopeProvider getClientScopeDelegate() 
 - 
getRoleDelegatepublic RoleProvider getRoleDelegate() 
 - 
getGroupDelegatepublic GroupProvider getGroupDelegate() 
 - 
registerRealmInvalidationpublic void registerRealmInvalidation(String id, String name) - Specified by:
- registerRealmInvalidationin interface- CacheRealmProvider
 
 - 
registerClientInvalidationpublic void registerClientInvalidation(String id, String clientId, String realmId) - Specified by:
- registerClientInvalidationin interface- CacheRealmProvider
 
 - 
registerClientScopeInvalidationpublic void registerClientScopeInvalidation(String id, String realmId) - Specified by:
- registerClientScopeInvalidationin interface- CacheRealmProvider
 
 - 
registerRoleInvalidationpublic void registerRoleInvalidation(String id, String roleName, String roleContainerId) - Specified by:
- registerRoleInvalidationin interface- CacheRealmProvider
 
 - 
registerGroupInvalidationpublic void registerGroupInvalidation(String id) - Specified by:
- registerGroupInvalidationin interface- CacheRealmProvider
 
 - 
runInvalidationsprotected void runInvalidations() 
 - 
createRealmpublic RealmModel createRealm(String name) Description copied from interface:RealmProviderCreates new realm with the given name. The internal ID will be generated automatically.- Specified by:
- createRealmin interface- RealmProvider
- Parameters:
- name- String name of the realm
- Returns:
- Model of the created realm.
 
 - 
createRealmpublic RealmModel createRealm(String id, String name) Description copied from interface:RealmProviderCreated new realm with given ID and name.- Specified by:
- createRealmin interface- RealmProvider
- Parameters:
- id- Internal ID of the realm or- nullif one is to be created by the underlying store. If the store expects the ID to have a certain format (for example- UUID) and the supplied ID doesn't follow the expected format, the store may replace the- idwith a new one at its own discretion.
- name- String name of the realm
- Returns:
- Model of the created realm.
 
 - 
getRealmpublic RealmModel getRealm(String id) Description copied from interface:RealmProviderExact search for a realm by its internal ID.- Specified by:
- getRealmin interface- RealmProvider
- Parameters:
- id- Internal ID of the realm.
- Returns:
- Model of the realm
 
 - 
getRealmByNamepublic RealmModel getRealmByName(String name) Description copied from interface:RealmProviderExact search for a realm by its name.- Specified by:
- getRealmByNamein interface- RealmProvider
- Parameters:
- name- String name of the realm
- Returns:
- Model of the realm
 
 - 
getRealmsWithProviderTypeStreampublic Stream<RealmModel> getRealmsWithProviderTypeStream(Class<?> type) Description copied from interface:RealmProviderReturns stream of realms which has component with the given provider type.- Specified by:
- getRealmsWithProviderTypeStreamin interface- RealmProvider
- Parameters:
- type-- Class<?>Type of the provider.
- Returns:
- Stream of RealmModel. Never returnsnull.
 
 - 
getRealmsStreampublic Stream<RealmModel> getRealmsStream() Description copied from interface:RealmProviderReturns realms as a stream.- Specified by:
- getRealmsStreamin interface- RealmProvider
- Returns:
- Stream of RealmModel. Never returnsnull.
 
 - 
removeRealmpublic boolean removeRealm(String id) Description copied from interface:RealmProviderRemoves realm with the given id.- Specified by:
- removeRealmin interface- RealmProvider
- Parameters:
- id- of realm.
- Returns:
- trueif the realm was successfully removed.
 
 - 
evictRealmOnRemovalpublic void evictRealmOnRemoval(RealmModel realm) 
 - 
addClientpublic ClientModel addClient(RealmModel realm, String clientId) Description copied from interface:ClientProviderAdds a client with givenclientIdto the given realm. The internal ID of the client will be created automatically.- Specified by:
- addClientin interface- ClientProvider
- Specified by:
- addClientin interface- RealmProvider
- Parameters:
- realm- Realm owning this client.
- clientId- String that identifies the client to the external parties. Maps to- client_idin OIDC or- entityIDin SAML.
- Returns:
- Model of the created client.
 
 - 
addClientpublic ClientModel addClient(RealmModel realm, String id, String clientId) Description copied from interface:ClientProviderAdds a client with given internal ID andclientIdto the given realm.- Specified by:
- addClientin interface- ClientProvider
- Specified by:
- addClientin interface- RealmProvider
- Parameters:
- realm- Realm owning this client.
- id- Internal ID of the client or- nullif one is to be created by the underlying store
- clientId- String that identifies the client to the external parties. Maps to- client_idin OIDC or- entityIDin SAML.
- Returns:
- Model of the created client.
 
 - 
getClientsStreampublic Stream<ClientModel> getClientsStream(RealmModel realm, Integer firstResult, Integer maxResults) Description copied from interface:ClientProviderReturns the clients of the given realm as a stream.- Specified by:
- getClientsStreamin interface- ClientProvider
- Parameters:
- realm- Realm.
- firstResult- First result to return. Ignored if negative or- null.
- maxResults- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of the clients. Never returns null.
 
 - 
getClientsStreampublic Stream<ClientModel> getClientsStream(RealmModel realm) Description copied from interface:ClientProviderReturns all the clients of the given realm as a stream. Effectively the same as the callgetClientsStream(realm, null, null).- Specified by:
- getClientsStreamin interface- ClientProvider
- Parameters:
- realm- Realm.
- Returns:
- Stream of the clients. Never returns null.
 
 - 
getAlwaysDisplayInConsoleClientsStreampublic Stream<ClientModel> getAlwaysDisplayInConsoleClientsStream(RealmModel realm) Description copied from interface:ClientProviderReturns a stream of clients that are expected to always show up in account console.- Specified by:
- getAlwaysDisplayInConsoleClientsStreamin interface- ClientProvider
- Parameters:
- realm- Realm owning the clients.
- Returns:
- Stream of the clients. Never returns null.
 
 - 
getAllRedirectUrisOfEnabledClientspublic Map<ClientModel,Set<String>> getAllRedirectUrisOfEnabledClients(RealmModel realm) Description copied from interface:ClientProviderReturns a map of (rootUrl, {validRedirectUris}) for all enabled clients.- Specified by:
- getAllRedirectUrisOfEnabledClientsin interface- ClientProvider
- Returns:
 
 - 
removeClientspublic void removeClients(RealmModel realm) Description copied from interface:ClientProviderRemoves all clients from the given realm.- Specified by:
- removeClientsin interface- ClientProvider
- Parameters:
- realm- Realm.
 
 - 
removeClientpublic boolean removeClient(RealmModel realm, String id) Description copied from interface:ClientProviderRemoves given client from the given realm.- Specified by:
- removeClientin interface- ClientProvider
- Parameters:
- realm- Realm.
- id- Internal ID of the client
- Returns:
- trueif the client existed and has been removed,- falseotherwise.
 
 - 
addRealmRolepublic RoleModel addRealmRole(RealmModel realm, String name) Description copied from interface:RoleProviderAdds a realm role with givennameto the given realm. The internal ID of the role will be created automatically.- Specified by:
- addRealmRolein interface- RealmProvider
- Specified by:
- addRealmRolein interface- RoleProvider
- Parameters:
- realm- Realm owning this role.
- name- String name of the role.
- Returns:
- Model of the created role.
 
 - 
addRealmRolepublic RoleModel addRealmRole(RealmModel realm, String id, String name) Description copied from interface:RoleProviderAdds a realm role with given internal ID andnameto the given realm.- Specified by:
- addRealmRolein interface- RealmProvider
- Specified by:
- addRealmRolein interface- RoleProvider
- Parameters:
- realm- Realm owning this role.
- id- Internal ID of the role or- nullif one is to be created by the underlying store
- name- String name of the role.
- Returns:
- Model of the created client.
 
 - 
getRealmRolesStreampublic Stream<RoleModel> getRealmRolesStream(RealmModel realm) Description copied from interface:RoleProviderReturns all the realm roles of the given realm as a stream. Effectively the same as the callgetRealmRolesStream(realm, null, null).- Specified by:
- getRealmRolesStreamin interface- RoleProvider
- Parameters:
- realm- Realm.
- Returns:
- Stream of the roles. Never returns null.
 
 - 
getClientRolesStreampublic Stream<RoleModel> getClientRolesStream(ClientModel client) Description copied from interface:RoleProviderReturns all the client roles of the given client. Effectively the same as the callgetClientRoles(client, null, null).- Specified by:
- getClientRolesStreamin interface- RoleProvider
- Parameters:
- client- Client.
- Returns:
- Stream of the roles. Never returns null.
 
 - 
getRealmRolesStreampublic Stream<RoleModel> getRealmRolesStream(RealmModel realm, Integer first, Integer max) Description copied from interface:RoleProviderReturns the realm roles of the given realm as a stream.- Specified by:
- getRealmRolesStreamin interface- RoleProvider
- Parameters:
- realm- Realm.
- first- First result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of the roles. Never returns null.
 
 - 
getRolesStreampublic Stream<RoleModel> getRolesStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max) Description copied from interface:RoleProviderReturns a paginated stream of roles with given ids and given search value in role names.- Specified by:
- getRolesStreamin interface- RoleProvider
- Parameters:
- realm- Realm. Cannot be- null.
- ids- Stream of ids. Returns empty- Streamwhen- null.
- search- Case-insensitive string to search by role's name or description. Ignored if- null.
- first- Index of the first result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of desired roles. Never returns null.
 
 - 
getClientRolesStreampublic Stream<RoleModel> getClientRolesStream(ClientModel client, Integer first, Integer max) Description copied from interface:RoleProviderReturns the client roles of the given client.- Specified by:
- getClientRolesStreamin interface- RoleProvider
- Parameters:
- client- Client.
- first- First result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of the roles. Never returns null.
 
 - 
searchForClientRolesStreampublic Stream<RoleModel> searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max) Description copied from interface:RoleLookupProviderCase-insensitive search for client roles that contain the given string in their name or description.- Specified by:
- searchForClientRolesStreamin interface- RoleLookupProvider
- Parameters:
- client- Client.
- search- String to search by role's name or description.
- first- First result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of the client roles their name or description contains given search string. 
 Never returns null.
 
 - 
searchForRolesStreampublic Stream<RoleModel> searchForRolesStream(RealmModel realm, String search, Integer first, Integer max) Description copied from interface:RoleLookupProviderCase-insensitive search for roles that contain the given string in their name or description.- Specified by:
- searchForRolesStreamin interface- RoleLookupProvider
- Parameters:
- realm- Realm.
- search- Searched substring of the role's name or description.
- first- First result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of the realm roles their name or description contains given search string. 
 Never returns null.
 
 - 
addClientRolepublic RoleModel addClientRole(ClientModel client, String name) Description copied from interface:RoleProviderAdds a client role with givennameto the given client. The internal ID of the role will be created automatically.- Specified by:
- addClientRolein interface- RoleProvider
- Parameters:
- client- Client owning this role.
- name- String name of the role.
- Returns:
- Model of the created role.
 
 - 
addClientRolepublic RoleModel addClientRole(ClientModel client, String id, String name) Description copied from interface:RoleProviderAdds a client role with given internal ID andnameto the given client.- Specified by:
- addClientRolein interface- RoleProvider
- Parameters:
- client- Client owning this role.
- id- Internal ID of the client role or- nullif one is to be created by the underlying store.
- name- String name of the role.
- Returns:
- Model of the created role.
 
 - 
getRealmRolepublic RoleModel getRealmRole(RealmModel realm, String name) Description copied from interface:RoleLookupProviderExact search for a role by given name.- Specified by:
- getRealmRolein interface- RealmProvider
- Specified by:
- getRealmRolein interface- RoleLookupProvider
- Parameters:
- realm- Realm.
- name- String name of the role.
- Returns:
- Model of the role, or nullif no role is found.
 
 - 
getClientRolepublic RoleModel getClientRole(ClientModel client, String name) Description copied from interface:RoleLookupProviderExact search for a client role by given name.- Specified by:
- getClientRolein interface- RoleLookupProvider
- Parameters:
- client- Client.
- name- String name of the role.
- Returns:
- Model of the role, or nullif no role is found.
 
 - 
removeRolepublic boolean removeRole(RoleModel role) Description copied from interface:RoleProviderRemoves given realm role from the given realm.- Specified by:
- removeRolein interface- RoleProvider
- Parameters:
- role- Role to be removed.
- Returns:
- trueif the role existed and has been removed,- falseotherwise.
 
 - 
removeRolespublic void removeRoles(RealmModel realm) Description copied from interface:RoleProviderRemoves all roles from the given realm.- Specified by:
- removeRolesin interface- RoleProvider
- Parameters:
- realm- Realm.
 
 - 
removeRolespublic void removeRoles(ClientModel client) Description copied from interface:RoleProviderRemoves all roles from the given client.- Specified by:
- removeRolesin interface- RoleProvider
- Parameters:
- client- Client.
 
 - 
getRoleByIdpublic RoleModel getRoleById(RealmModel realm, String id) Description copied from interface:RoleLookupProviderExact search for a role by its internal ID..- Specified by:
- getRoleByIdin interface- RoleLookupProvider
- Parameters:
- realm- Realm.
- id- Internal ID of the role.
- Returns:
- Model of the role.
 
 - 
getGroupByIdpublic GroupModel getGroupById(RealmModel realm, String id) Description copied from interface:GroupLookupProviderReturns a group from the given realm with the corresponding id- Specified by:
- getGroupByIdin interface- GroupLookupProvider
- Specified by:
- getGroupByIdin interface- RealmProvider
- Parameters:
- realm- Realm.
- id- Id.
- Returns:
- GroupModel with the corresponding id.
 
 - 
moveGrouppublic void moveGroup(RealmModel realm, GroupModel group, GroupModel toParent) Description copied from interface:GroupProviderThis method is used for moving groups in group structure, for example:- making an existing child group child group of some other group,
- setting a top level group (i.e. group without parent group) child of some group,
- making a child group top level group (i.e. removing its parent group).
 - Specified by:
- moveGroupin interface- GroupProvider
- Specified by:
- moveGroupin interface- RealmProvider
- Parameters:
- realm- Realm owning this group.
- group- Group to update.
- toParent- New parent group, or- nullif we are moving the group to top level group.
 
 - 
getGroupsStreampublic Stream<GroupModel> getGroupsStream(RealmModel realm) Description copied from interface:GroupProviderReturns groups for the given realm.- Specified by:
- getGroupsStreamin interface- GroupProvider
- Parameters:
- realm- Realm.
- Returns:
- Stream of groups in the Realm.
 
 - 
getGroupsStreampublic Stream<GroupModel> getGroupsStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max) Description copied from interface:GroupProviderReturns a paginated stream of groups with given ids and given search value in group names.- Specified by:
- getGroupsStreamin interface- GroupProvider
- Parameters:
- realm- Realm.
- ids- Stream of ids.
- search- Case insensitive string which will be searched for. Ignored if null.
- first- Index of the first result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of desired groups. Never returns null.
 
 - 
getGroupsCountpublic Long getGroupsCount(RealmModel realm, Stream<String> ids, String search) Description copied from interface:GroupProviderReturns a number of groups that contains the search string in the name- Specified by:
- getGroupsCountin interface- GroupProvider
- Parameters:
- realm- Realm.
- ids- List of ids.
- search- Case insensitive string which will be searched for. Ignored if null.
- Returns:
- Number of groups.
 
 - 
getGroupsCountpublic Long getGroupsCount(RealmModel realm, Boolean onlyTopGroups) Description copied from interface:GroupProviderReturns a number of groups/top level groups (i.e. groups without parent group) for the given realm.- Specified by:
- getGroupsCountin interface- GroupProvider
- Specified by:
- getGroupsCountin interface- RealmProvider
- Parameters:
- realm- Realm.
- onlyTopGroups- When true the function returns a count of top level groups only.
- Returns:
- Number of groups/top level groups.
 
 - 
getClientsCountpublic long getClientsCount(RealmModel realm) Description copied from interface:ClientProviderReturns number of clients in the given realm- Specified by:
- getClientsCountin interface- ClientProvider
- Specified by:
- getClientsCountin interface- RealmProvider
- Parameters:
- realm- Realm.
- Returns:
- Number of the clients in the given realm.
 
 - 
getGroupsCountByNameContainingpublic Long getGroupsCountByNameContaining(RealmModel realm, String search) Description copied from interface:GroupProviderReturns the number of top level groups containing groups with the given string in name for the given realm.- Specified by:
- getGroupsCountByNameContainingin interface- GroupProvider
- Specified by:
- getGroupsCountByNameContainingin interface- RealmProvider
- Parameters:
- realm- Realm.
- search- Case insensitive string which will be searched for.
- Returns:
- Number of groups with the given string in its name.
 
 - 
getGroupsByRoleStreampublic Stream<GroupModel> getGroupsByRoleStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults) Description copied from interface:GroupProviderReturns groups with the given role in the given realm.- Specified by:
- getGroupsByRoleStreamin interface- GroupProvider
- Parameters:
- realm- Realm.
- role- Role.
- firstResult- First result to return. Ignored if negative or- null.
- maxResults- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of groups with the given role. Never returns null.
 
 - 
getTopLevelGroupsStreampublic Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm) Description copied from interface:GroupProviderReturns all top level groups (i.e. groups without parent group) for the given realm.- Specified by:
- getTopLevelGroupsStreamin interface- GroupProvider
- Parameters:
- realm- Realm.
- Returns:
- Stream of all top level groups in the realm. Never returns null.
 
 - 
getTopLevelGroupsStreampublic Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm, Integer first, Integer max) Description copied from interface:GroupProviderReturns top level groups (i.e. groups without parent group) for the given realm.- Specified by:
- getTopLevelGroupsStreamin interface- GroupProvider
- Parameters:
- realm- Realm.
- first- First result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of top level groups in the realm. Never returns null.
 
 - 
searchForGroupByNameStreampublic Stream<GroupModel> searchForGroupByNameStream(RealmModel realm, String search, Integer first, Integer max) Description copied from interface:GroupLookupProviderReturns the group hierarchy with the given string in name for the given realm. For a matching group node the parent group is fetched by id (with all children) and added to the result stream. This is done until the group node does not have a parent (root group)- Specified by:
- searchForGroupByNameStreamin interface- GroupLookupProvider
- Parameters:
- realm- Realm.
- search- Case sensitive searched string.
- first- First result to return. Ignored if negative or- null.
- max- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of root groups that have the given string in their name themself or a group in their child-collection has.
 The returned hierarchy contains siblings that do not necessarily have a matching name. Never returns null.
 
 - 
searchForGroupByNameStreampublic Stream<GroupModel> searchForGroupByNameStream(RealmModel realm, String search, Boolean exact, Integer firstResult, Integer maxResults) Description copied from interface:GroupLookupProviderReturns the group hierarchy with the given string in name for the given realm. For a matching group node the parent group is fetched by id (with all children) and added to the result stream. This is done until the group node does not have a parent (root group)- Specified by:
- searchForGroupByNameStreamin interface- GroupLookupProvider
- Parameters:
- realm- Realm.
- search- Case sensitive searched string.
- exact- Boolean which defines wheather search param should be matched exactly.
- firstResult- First result to return. Ignored if negative or- null.
- maxResults- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of root groups that have the given string in their name themself or a group in their child-collection has.
 The returned hierarchy contains siblings that do not necessarily have a matching name. Never returns null.
 
 - 
searchGroupsByAttributespublic Stream<GroupModel> searchGroupsByAttributes(RealmModel realm, Map<String,String> attributes, Integer firstResult, Integer maxResults) Description copied from interface:GroupLookupProviderReturns the groups filtered by attribute names and attribute values for the given realm.- Specified by:
- searchGroupsByAttributesin interface- GroupLookupProvider
- Parameters:
- realm- Realm.
- attributes- name-value pairs that are compared to group attributes.
- firstResult- First result to return. Ignored if negative or- null.
- maxResults- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of groups with attributes matching all searched attributes. Never returns null.
 
 - 
removeGrouppublic boolean removeGroup(RealmModel realm, GroupModel group) Description copied from interface:GroupProviderRemoves the given group for the given realm.- Specified by:
- removeGroupin interface- GroupProvider
- Specified by:
- removeGroupin interface- RealmProvider
- Parameters:
- realm- Realm.
- group- Group.
- Returns:
- true if the group was removed, false if group doesn't exist or doesn't belong to the given realm
 
 - 
createGrouppublic GroupModel createGroup(RealmModel realm, String id, String name, GroupModel toParent) Description copied from interface:GroupProviderCreates a new group with the given name, id, name and parent to the given realm.- Specified by:
- createGroupin interface- GroupProvider
- Specified by:
- createGroupin interface- RealmProvider
- Parameters:
- realm- Realm.
- id- Id, will be generated if- null.
- name- Name.
- toParent- Parent group, or- nullif the group is top level group
- Returns:
- Model of the created group
 
 - 
addTopLevelGrouppublic void addTopLevelGroup(RealmModel realm, GroupModel subGroup) Description copied from interface:GroupProviderRemoves parent group for the given group in the given realm.- Specified by:
- addTopLevelGroupin interface- GroupProvider
- Specified by:
- addTopLevelGroupin interface- RealmProvider
- Parameters:
- realm- Realm.
- subGroup- Group.
 
 - 
getClientByIdpublic ClientModel getClientById(RealmModel realm, String id) Description copied from interface:ClientLookupProviderExact search for a client by its internal ID.- Specified by:
- getClientByIdin interface- ClientLookupProvider
- Parameters:
- realm- Realm to limit the search.
- id- Internal ID
- Returns:
- Model of the client, or nullif no client is found.
 
 - 
cacheClientprotected ClientModel cacheClient(RealmModel realm, ClientModel delegate, Long revision) 
 - 
validateCacheprotected ClientModel validateCache(RealmModel realm, CachedClient cached) 
 - 
searchClientsByClientIdStreampublic Stream<ClientModel> searchClientsByClientIdStream(RealmModel realm, String clientId, Integer firstResult, Integer maxResults) Description copied from interface:ClientLookupProviderCase-insensitive search for clients that contain the given string in their public client identifier.- Specified by:
- searchClientsByClientIdStreamin interface- ClientLookupProvider
- Parameters:
- realm- Realm to limit the search for clients.
- clientId- Searched substring of the public client identifier (- client_idin OIDC or- entityIDin SAML.)
- firstResult- First result to return. Ignored if negative or- null.
- maxResults- Maximum number of results to return. Ignored if negative or- null.
- Returns:
- Stream of ClientModel or an empty stream if no client is found. Never returns null.
 
 - 
searchClientsByAttributespublic Stream<ClientModel> searchClientsByAttributes(RealmModel realm, Map<String,String> attributes, Integer firstResult, Integer maxResults) - Specified by:
- searchClientsByAttributesin interface- ClientLookupProvider
 
 - 
getClientByClientIdpublic ClientModel getClientByClientId(RealmModel realm, String clientId) Description copied from interface:ClientLookupProviderExact search for a client by its public client identifier.- Specified by:
- getClientByClientIdin interface- ClientLookupProvider
- Parameters:
- realm- Realm to limit the search for clients.
- clientId- String that identifies the client to the external parties. Maps to- client_idin OIDC or- entityIDin SAML.
- Returns:
- Model of the client, or nullif no client is found.
 
 - 
getClientScopeByIdpublic ClientScopeModel getClientScopeById(RealmModel realm, String id) Description copied from interface:ClientScopeLookupProviderExact search for a client scope by its internal ID..- Specified by:
- getClientScopeByIdin interface- ClientScopeLookupProvider
- Specified by:
- getClientScopeByIdin interface- RealmProvider
- Parameters:
- realm- Realm.
- id- Internal ID of the role.
- Returns:
- Model of the client scope.
 
 - 
getClientScopesStreampublic Stream<ClientScopeModel> getClientScopesStream(RealmModel realm) Description copied from interface:ClientScopeProviderReturns all the client scopes of the given realm as a stream.- Specified by:
- getClientScopesStreamin interface- ClientScopeProvider
- Parameters:
- realm- Realm.
- Returns:
- Stream of the client scopes. Never returns null.
 
 - 
addClientScopepublic ClientScopeModel addClientScope(RealmModel realm, String name) Description copied from interface:ClientScopeProviderCreates new client scope with givennameto the given realm. Spaces innamewill be replaced by underscore so that scope name can be used as value of scope parameter. The internal ID will be created automatically.- Specified by:
- addClientScopein interface- ClientScopeProvider
- Parameters:
- realm- Realm owning this client scope.
- name- String name of the client scope.
- Returns:
- Model of the created client scope.
 
 - 
addClientScopepublic ClientScopeModel addClientScope(RealmModel realm, String id, String name) Description copied from interface:ClientScopeProviderCreates new client scope with given internal ID andnameto the given realm. Spaces innamewill be replaced by underscore so that scope name can be used as value of scope parameter.- Specified by:
- addClientScopein interface- ClientScopeProvider
- Parameters:
- realm- Realm owning this client scope.
- id- Internal ID of the client scope or- nullif one is to be created by the underlying store
- name- String name of the client scope.
- Returns:
- Model of the created client scope.
 
 - 
removeClientScopepublic boolean removeClientScope(RealmModel realm, String id) Description copied from interface:ClientScopeProviderRemoves client scope from the given realm.- Specified by:
- removeClientScopein interface- ClientScopeProvider
- Parameters:
- realm- Realm.
- id- Internal ID of the client scope
- Returns:
- trueif the client scope existed and has been removed,- falseotherwise.
 
 - 
removeClientScopespublic void removeClientScopes(RealmModel realm) Description copied from interface:ClientScopeProviderRemoves all client scopes from the given realm.- Specified by:
- removeClientScopesin interface- ClientScopeProvider
- Parameters:
- realm- Realm.
 
 - 
addClientScopespublic void addClientScopes(RealmModel realm, ClientModel client, Set<ClientScopeModel> clientScopes, boolean defaultScope) Description copied from interface:ClientProviderAssign clientScopes to the client. Add as default scopes (if parameter 'defaultScope' is true) or optional scopes (if parameter 'defaultScope' is false)- Specified by:
- addClientScopesin interface- ClientProvider
- Parameters:
- realm- Realm.
- client- Client.
- clientScopes- to be assigned
- defaultScope- if true the scopes are assigned as default, or optional in case of false
 
 - 
removeClientScopepublic void removeClientScope(RealmModel realm, ClientModel client, ClientScopeModel clientScope) Description copied from interface:ClientProviderUnassign clientScope from the client.- Specified by:
- removeClientScopein interface- ClientProvider
- Parameters:
- realm- Realm.
- client- Client.
- clientScope- to be unassigned
 
 - 
getClientScopespublic Map<String,ClientScopeModel> getClientScopes(RealmModel realm, ClientModel client, boolean defaultScopes) Description copied from interface:ClientLookupProviderReturn all default scopes (ifdefaultScopeistrue) or all optional scopes (ifdefaultScopeisfalse) linked with the client- Specified by:
- getClientScopesin interface- ClientLookupProvider
- Parameters:
- realm- Realm
- client- Client
- defaultScopes- if true default scopes, if false optional scopes, are returned
- Returns:
- map where key is the name of the clientScope, value is particular clientScope. Returns empty map if no scopes linked (never returns null).
 
 - 
createClientInitialAccessModelpublic ClientInitialAccessModel createClientInitialAccessModel(RealmModel realm, int expiration, int count) - Specified by:
- createClientInitialAccessModelin interface- RealmProvider
 
 - 
getClientInitialAccessModelpublic ClientInitialAccessModel getClientInitialAccessModel(RealmModel realm, String id) - Specified by:
- getClientInitialAccessModelin interface- RealmProvider
 
 - 
removeClientInitialAccessModelpublic void removeClientInitialAccessModel(RealmModel realm, String id) - Specified by:
- removeClientInitialAccessModelin interface- RealmProvider
 
 - 
listClientInitialAccessStreampublic Stream<ClientInitialAccessModel> listClientInitialAccessStream(RealmModel realm) Description copied from interface:RealmProviderReturns client's initial access as a stream.- Specified by:
- listClientInitialAccessStreamin interface- RealmProvider
- Parameters:
- realm-- RealmModelThe realm where to list client's initial access.
- Returns:
- Stream of ClientInitialAccessModel. Never returnsnull.
 
 - 
removeExpiredClientInitialAccesspublic void removeExpiredClientInitialAccess() Description copied from interface:RealmProviderRemoves all expired client initial accesses from all realms.- Specified by:
- removeExpiredClientInitialAccessin interface- RealmProvider
 
 - 
saveLocalizationTextpublic void saveLocalizationText(RealmModel realm, String locale, String key, String text) - Specified by:
- saveLocalizationTextin interface- RealmProvider
 
 - 
saveLocalizationTextspublic void saveLocalizationTexts(RealmModel realm, String locale, Map<String,String> localizationTexts) - Specified by:
- saveLocalizationTextsin interface- RealmProvider
 
 - 
updateLocalizationTextpublic boolean updateLocalizationText(RealmModel realm, String locale, String key, String text) - Specified by:
- updateLocalizationTextin interface- RealmProvider
 
 - 
deleteLocalizationTextsByLocalepublic boolean deleteLocalizationTextsByLocale(RealmModel realm, String locale) - Specified by:
- deleteLocalizationTextsByLocalein interface- RealmProvider
 
 - 
deleteLocalizationTextpublic boolean deleteLocalizationText(RealmModel realm, String locale, String key) - Specified by:
- deleteLocalizationTextin interface- RealmProvider
 
 - 
getLocalizationTextsByIdpublic String getLocalizationTextsById(RealmModel realm, String locale, String key) - Specified by:
- getLocalizationTextsByIdin interface- RealmProvider
 
 
- 
 
-