public class JpaRealmProvider extends Object implements RealmProvider, ClientProvider, GroupProvider, RoleProvider
Modifier and Type | Field and Description |
---|---|
protected javax.persistence.EntityManager |
em |
protected static org.jboss.logging.Logger |
logger |
Constructor and Description |
---|
JpaRealmProvider(KeycloakSession session,
javax.persistence.EntityManager em) |
Modifier and Type | Method and Description |
---|---|
ClientModel |
addClient(RealmModel realm,
String clientId)
Adds a client with given
clientId to the given realm. |
ClientModel |
addClient(RealmModel realm,
String id,
String clientId)
Adds a client with given internal ID and
clientId to the given realm. |
RoleModel |
addClientRole(ClientModel client,
String name)
Adds a client role with given
name to the given client. |
RoleModel |
addClientRole(ClientModel client,
String id,
String name)
Adds a client role with given internal ID and
name to the given client. |
RoleModel |
addRealmRole(RealmModel realm,
String name)
Adds a realm role with given
name to the given realm. |
RoleModel |
addRealmRole(RealmModel realm,
String id,
String name)
Adds a realm role with given internal ID and
name to the given realm. |
void |
addTopLevelGroup(RealmModel realm,
GroupModel subGroup)
Removes parent group for the given group in the given realm.
|
void |
close() |
ClientInitialAccessModel |
createClientInitialAccessModel(RealmModel realm,
int expiration,
int count) |
GroupModel |
createGroup(RealmModel realm,
String id,
String name,
GroupModel toParent)
Creates a new group with the given name, id, name and parent to the given realm.
|
RealmModel |
createRealm(String name) |
RealmModel |
createRealm(String id,
String name) |
void |
decreaseRemainingCount(RealmModel realm,
ClientInitialAccessModel clientInitialAccess) |
boolean |
deleteLocalizationText(RealmModel realm,
String locale,
String key) |
boolean |
deleteLocalizationTextsByLocale(RealmModel realm,
String locale) |
Stream<ClientModel> |
getAlwaysDisplayInConsoleClientsStream(RealmModel realm)
Returns a stream of clients that are expected to always show up in account console.
|
ClientModel |
getClientByClientId(RealmModel realm,
String clientId)
Exact search for a client by its public client identifier.
|
ClientModel |
getClientById(RealmModel realm,
String id)
Exact search for a client by its internal ID.
|
ClientInitialAccessModel |
getClientInitialAccessModel(RealmModel realm,
String id) |
RoleModel |
getClientRole(ClientModel client,
String name)
Exact search for a client role by given name.
|
Stream<RoleModel> |
getClientRolesStream(ClientModel client,
Integer first,
Integer max)
Returns the client roles of the given client.
|
ClientScopeModel |
getClientScopeById(String id,
RealmModel realm) |
long |
getClientsCount(RealmModel realm)
Returns number of clients in the given realm
|
Stream<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.
|
GroupModel |
getGroupById(RealmModel realm,
String id)
Returns a group from the given realm with the corresponding id
|
Stream<GroupModel> |
getGroupsByRoleStream(RealmModel realm,
RoleModel role,
Integer firstResult,
Integer maxResults)
Returns groups with the given role in the given realm.
|
Long |
getGroupsCount(RealmModel realm,
Boolean onlyTopGroups)
Returns a number of groups/top level groups (i.e.
|
Long |
getGroupsCount(RealmModel realm,
Stream<String> ids,
String search)
Returns a number of groups that contains the search string in the name
|
Long |
getGroupsCountByNameContaining(RealmModel realm,
String search)
Returns number of 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)
Returns a list of groups with given ids.
|
Stream<GroupModel> |
getGroupsStream(RealmModel realm,
Stream<String> ids,
Integer first,
Integer max)
Returns a paginated list of groups with given ids.
|
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.
|
String |
getLocalizationTextsById(RealmModel realm,
String locale,
String key) |
MigrationModel |
getMigrationModel() |
RealmModel |
getRealm(String id) |
RealmModel |
getRealmByName(String name) |
RoleModel |
getRealmRole(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() |
Stream<RealmModel> |
getRealmsWithProviderTypeStream(Class<?> providerType) |
RoleModel |
getRoleById(RealmModel realm,
String id)
Exact search for a role by its internal ID..
|
protected Stream<RoleModel> |
getRolesStream(javax.persistence.TypedQuery<RoleEntity> query,
RealmModel realm,
Integer first,
Integer max) |
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.
|
Stream<ClientInitialAccessModel> |
listClientInitialAccessStream(RealmModel realm) |
void |
moveGroup(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.
|
void |
preRemove(RealmModel realm,
RoleModel role)
This function is called when a role is removed; this serves for removing references from groups to roles.
|
boolean |
removeClient(RealmModel realm,
String id)
Removes given client from the given realm.
|
void |
removeClientInitialAccessModel(RealmModel realm,
String id) |
void |
removeClients(RealmModel realm)
Removes all clients from the given realm.
|
void |
removeExpiredClientInitialAccess() |
boolean |
removeGroup(RealmModel realm,
GroupModel group)
Removes the given group for the given realm.
|
boolean |
removeRealm(String id) |
boolean |
removeRole(RoleModel role)
Removes given realm role from the given realm.
|
void |
removeRoles(ClientModel client)
Removes all roles from the given client.
|
void |
removeRoles(RealmModel realm)
Removes all roles from the given realm.
|
void |
saveLocalizationText(RealmModel realm,
String locale,
String key,
String text) |
void |
saveLocalizationTexts(RealmModel realm,
String locale,
Map<String,String> localizationTexts) |
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,
Integer first,
Integer max)
Returns groups with the given string in name for the given realm.
|
protected Stream<RoleModel> |
searchForRoles(javax.persistence.TypedQuery<RoleEntity> query,
RealmModel realm,
String search,
Integer first,
Integer max) |
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.
|
boolean |
updateLocalizationText(RealmModel realm,
String locale,
String key,
String text) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addClientRole, addClientRole, createGroup, createGroup, createGroup, getAlwaysDisplayInConsoleClients, getClientByClientId, getClientById, getClientRole, getClientRoles, getClientRoles, getClients, getClients, getGroupById, getGroups, getGroupsByRole, getRealmRoles, getRealmRoles, getRealms, getRealmsWithProviderType, getRoleById, getTopLevelGroups, getTopLevelGroups, listClientInitialAccess, removeClient, removeRole, searchClientsByClientId, searchForClientRoles, searchForGroupByName, searchForRoles
getClientRolesStream
protected static final org.jboss.logging.Logger logger
protected javax.persistence.EntityManager em
public JpaRealmProvider(KeycloakSession session, javax.persistence.EntityManager em)
public MigrationModel getMigrationModel()
getMigrationModel
in interface RealmProvider
public RealmModel createRealm(String name)
createRealm
in interface RealmProvider
public RealmModel createRealm(String id, String name)
createRealm
in interface RealmProvider
public RealmModel getRealm(String id)
getRealm
in interface RealmProvider
public Stream<RealmModel> getRealmsWithProviderTypeStream(Class<?> providerType)
getRealmsWithProviderTypeStream
in interface RealmProvider
public Stream<RealmModel> getRealmsStream()
getRealmsStream
in interface RealmProvider
public RealmModel getRealmByName(String name)
getRealmByName
in interface RealmProvider
public boolean removeRealm(String id)
removeRealm
in interface RealmProvider
public RoleModel addRealmRole(RealmModel realm, String name)
RoleProvider
name
to the given realm.
The internal ID of the role will be created automatically.addRealmRole
in interface RealmProvider
addRealmRole
in interface RoleProvider
realm
- Realm owning this role.name
- String name of the role.public RoleModel addRealmRole(RealmModel realm, String id, String name)
RoleProvider
name
to the given realm.addRealmRole
in interface RealmProvider
addRealmRole
in interface RoleProvider
realm
- Realm owning this role.id
- Internal ID of the role or null
if one is to be created by the underlying storename
- String name of the role.public RoleModel getRealmRole(RealmModel realm, String name)
RoleLookupProvider
getRealmRole
in interface RealmProvider
getRealmRole
in interface RoleLookupProvider
realm
- Realm.name
- String name of the role.null
if no role is found.public RoleModel addClientRole(ClientModel client, String name)
RoleProvider
name
to the given client.
The internal ID of the role will be created automatically.addClientRole
in interface RoleProvider
client
- Client owning this role.name
- String name of the role.public RoleModel addClientRole(ClientModel client, String id, String name)
RoleProvider
name
to the given client.addClientRole
in interface RoleProvider
client
- Client owning this role.id
- Internal ID of the client role or null
if one is to be created by the underlying store.name
- String name of the role.public Stream<RoleModel> getRealmRolesStream(RealmModel realm)
RoleProvider
getRealmRolesStream(realm, null, null)
.getRealmRolesStream
in interface RoleProvider
realm
- Realm.null
.public RoleModel getClientRole(ClientModel client, String name)
RoleLookupProvider
getClientRole
in interface RoleLookupProvider
client
- Client.name
- String name of the role.null
if no role is found.public Stream<RoleModel> getRealmRolesStream(RealmModel realm, Integer first, Integer max)
RoleProvider
getRealmRolesStream
in interface RoleProvider
realm
- Realm.first
- First result to return. Ignored if negative or null
.max
- Maximum number of results to return. Ignored if negative or null
.null
.public Stream<RoleModel> getClientRolesStream(ClientModel client, Integer first, Integer max)
RoleProvider
getClientRolesStream
in interface RoleProvider
client
- Client.first
- First result to return. Ignored if negative or null
.max
- Maximum number of results to return. Ignored if negative or null
.null
.protected Stream<RoleModel> getRolesStream(javax.persistence.TypedQuery<RoleEntity> query, RealmModel realm, Integer first, Integer max)
public Stream<RoleModel> searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max)
RoleLookupProvider
searchForClientRolesStream
in interface RoleLookupProvider
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
.null
.public Stream<RoleModel> searchForRolesStream(RealmModel realm, String search, Integer first, Integer max)
RoleLookupProvider
searchForRolesStream
in interface RoleLookupProvider
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
.null
.protected Stream<RoleModel> searchForRoles(javax.persistence.TypedQuery<RoleEntity> query, RealmModel realm, String search, Integer first, Integer max)
public boolean removeRole(RoleModel role)
RoleProvider
removeRole
in interface RoleProvider
role
- Role to be removed.true
if the role existed and has been removed, false
otherwise.public void removeRoles(RealmModel realm)
RoleProvider
removeRoles
in interface RoleProvider
realm
- Realm.public void removeRoles(ClientModel client)
RoleProvider
removeRoles
in interface RoleProvider
client
- Client.public RoleModel getRoleById(RealmModel realm, String id)
RoleLookupProvider
getRoleById
in interface RoleLookupProvider
realm
- Realm.id
- Internal ID of the role.public GroupModel getGroupById(RealmModel realm, String id)
GroupLookupProvider
getGroupById
in interface RealmProvider
getGroupById
in interface GroupLookupProvider
realm
- Realm.id
- Id.public void moveGroup(RealmModel realm, GroupModel group, GroupModel toParent)
GroupProvider
moveGroup
in interface GroupProvider
moveGroup
in interface RealmProvider
realm
- Realm owning this group.group
- Group to update.toParent
- New parent group, or null
if we are moving the group to top level group.public Stream<GroupModel> getGroupsStream(RealmModel realm)
GroupProvider
getGroupsStream
in interface GroupProvider
realm
- Realm.public Stream<GroupModel> getGroupsStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max)
GroupProvider
getGroupsStream
in interface GroupProvider
realm
- Realm.ids
- List 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
.public Stream<GroupModel> getGroupsStream(RealmModel realm, Stream<String> ids, Integer first, Integer max)
GroupProvider
getGroupsStream(realm, ids, null, first, max)
.getGroupsStream
in interface GroupProvider
realm
- Realm.ids
- List of ids.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
.public Stream<GroupModel> getGroupsStream(RealmModel realm, Stream<String> ids)
GroupProvider
getGroupsStream(realm, ids, null, null, null)
.getGroupsStream
in interface GroupProvider
realm
- Realm.ids
- List of ids.public Long getGroupsCount(RealmModel realm, Stream<String> ids, String search)
GroupProvider
getGroupsCount
in interface GroupProvider
realm
- Realm.ids
- List of ids.search
- Case insensitive string which will be searched for. Ignored if null.public Long getGroupsCount(RealmModel realm, Boolean onlyTopGroups)
GroupProvider
getGroupsCount
in interface GroupProvider
getGroupsCount
in interface RealmProvider
realm
- Realm.onlyTopGroups
- When true the function returns a count of top level groups only.public long getClientsCount(RealmModel realm)
ClientProvider
getClientsCount
in interface ClientProvider
getClientsCount
in interface RealmProvider
realm
- Realm.public Long getGroupsCountByNameContaining(RealmModel realm, String search)
GroupProvider
getGroupsCountByNameContaining
in interface GroupProvider
getGroupsCountByNameContaining
in interface RealmProvider
realm
- Realm.search
- Case insensitive string which will be searched for.public Stream<GroupModel> getGroupsByRoleStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults)
GroupProvider
getGroupsByRoleStream
in interface GroupProvider
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
.public Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm)
GroupProvider
getTopLevelGroupsStream
in interface GroupProvider
realm
- Realm.public Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm, Integer first, Integer max)
GroupProvider
getTopLevelGroupsStream
in interface GroupProvider
realm
- Realm.first
- First result to return. Ignored if negative or null
.max
- Maximum number of results to return. Ignored if negative or null
.public boolean removeGroup(RealmModel realm, GroupModel group)
GroupProvider
removeGroup
in interface GroupProvider
removeGroup
in interface RealmProvider
realm
- Realm.group
- Group.public GroupModel createGroup(RealmModel realm, String id, String name, GroupModel toParent)
GroupProvider
createGroup
in interface GroupProvider
createGroup
in interface RealmProvider
realm
- Realm.id
- Id, will be generated if null
.name
- Name.toParent
- Parent group, or null
if the group is top level grouppublic void addTopLevelGroup(RealmModel realm, GroupModel subGroup)
GroupProvider
addTopLevelGroup
in interface GroupProvider
addTopLevelGroup
in interface RealmProvider
realm
- Realm.subGroup
- Group.public void preRemove(RealmModel realm, RoleModel role)
GroupProvider
preRemove
in interface GroupProvider
realm
- Realm.role
- Role which will be removed.public ClientModel addClient(RealmModel realm, String clientId)
ClientProvider
clientId
to the given realm.
The internal ID of the client will be created automatically.addClient
in interface ClientProvider
addClient
in interface RealmProvider
realm
- Realm owning this client.clientId
- String that identifies the client to the external parties.
Maps to client_id
in OIDC or entityID
in SAML.public ClientModel addClient(RealmModel realm, String id, String clientId)
ClientProvider
clientId
to the given realm.addClient
in interface ClientProvider
addClient
in interface RealmProvider
realm
- Realm owning this client.id
- Internal ID of the client or null
if one is to be created by the underlying storeclientId
- String that identifies the client to the external parties.
Maps to client_id
in OIDC or entityID
in SAML.public Stream<ClientModel> getClientsStream(RealmModel realm)
ClientProvider
getClientsStream(realm, null, null)
.getClientsStream
in interface ClientProvider
realm
- Realm.null
.public Stream<ClientModel> getClientsStream(RealmModel realm, Integer firstResult, Integer maxResults)
ClientProvider
getClientsStream
in interface ClientProvider
realm
- Realm.firstResult
- First result to return. Ignored if negative or null
.maxResults
- Maximum number of results to return. Ignored if negative or null
.null
.public Stream<ClientModel> getAlwaysDisplayInConsoleClientsStream(RealmModel realm)
ClientProvider
getAlwaysDisplayInConsoleClientsStream
in interface ClientProvider
realm
- Realm owning the clients.null
.public ClientModel getClientById(RealmModel realm, String id)
ClientLookupProvider
getClientById
in interface ClientLookupProvider
realm
- Realm to limit the search.id
- Internal IDnull
if no client is found.public ClientModel getClientByClientId(RealmModel realm, String clientId)
ClientLookupProvider
getClientByClientId
in interface ClientLookupProvider
realm
- Realm to limit the search for clients.clientId
- String that identifies the client to the external parties.
Maps to client_id
in OIDC or entityID
in SAML.null
if no client is found.public Stream<ClientModel> searchClientsByClientIdStream(RealmModel realm, String clientId, Integer firstResult, Integer maxResults)
ClientLookupProvider
searchClientsByClientIdStream
in interface ClientLookupProvider
realm
- Realm to limit the search for clients.clientId
- Searched substring of the public client
identifier (client_id
in OIDC or entityID
in SAML.)firstResult
- First result to return. Ignored if negative or null
.maxResults
- Maximum number of results to return. Ignored if negative or null
.public void removeClients(RealmModel realm)
ClientProvider
removeClients
in interface ClientProvider
realm
- Realm.public boolean removeClient(RealmModel realm, String id)
ClientProvider
removeClient
in interface ClientProvider
realm
- Realm.id
- Internal ID of the clienttrue
if the client existed and has been removed, false
otherwise.public ClientScopeModel getClientScopeById(String id, RealmModel realm)
getClientScopeById
in interface RealmProvider
public Stream<GroupModel> searchForGroupByNameStream(RealmModel realm, String search, Integer first, Integer max)
GroupLookupProvider
searchForGroupByNameStream
in interface GroupLookupProvider
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
.public ClientInitialAccessModel createClientInitialAccessModel(RealmModel realm, int expiration, int count)
createClientInitialAccessModel
in interface RealmProvider
public ClientInitialAccessModel getClientInitialAccessModel(RealmModel realm, String id)
getClientInitialAccessModel
in interface RealmProvider
public void removeClientInitialAccessModel(RealmModel realm, String id)
removeClientInitialAccessModel
in interface RealmProvider
public Stream<ClientInitialAccessModel> listClientInitialAccessStream(RealmModel realm)
listClientInitialAccessStream
in interface RealmProvider
public void removeExpiredClientInitialAccess()
removeExpiredClientInitialAccess
in interface RealmProvider
public void decreaseRemainingCount(RealmModel realm, ClientInitialAccessModel clientInitialAccess)
decreaseRemainingCount
in interface RealmProvider
public boolean updateLocalizationText(RealmModel realm, String locale, String key, String text)
updateLocalizationText
in interface RealmProvider
public void saveLocalizationText(RealmModel realm, String locale, String key, String text)
saveLocalizationText
in interface RealmProvider
public void saveLocalizationTexts(RealmModel realm, String locale, Map<String,String> localizationTexts)
saveLocalizationTexts
in interface RealmProvider
public boolean deleteLocalizationTextsByLocale(RealmModel realm, String locale)
deleteLocalizationTextsByLocale
in interface RealmProvider
public String getLocalizationTextsById(RealmModel realm, String locale, String key)
getLocalizationTextsById
in interface RealmProvider
public boolean deleteLocalizationText(RealmModel realm, String locale, String key)
deleteLocalizationText
in interface RealmProvider
Copyright © 2020 JBoss by Red Hat. All rights reserved.