Reputation: 175
I need to retrieve a specific user with a certain user role from a Keycloak user group (id is known). Presently I am doing it as below.
//get all users
keycloak.realm("myRealm").groups().group(groupId).members(0, 1000);
//query the list of users to identify the specific user
which takes some considerable amount of time (nearly 2 minutes) when the groups and the number of users increase. Is there a particular way to get a single user or a single group without querying all groups and users in a keycloak server.
I am using keycloak 2.3.0 Final keycloak server with a springboot application. Thanks in advance
Upvotes: 2
Views: 2533
Reputation: 9623
With keycloak-admin-client
3.4.3 you can retrieve users with specific role as follows.
RoleResource roleResource = keycloak.realm("realm_name").roles().get("role_name");
Set<UserRepresentation> users = roleResource.getRoleUserMembers();
Upvotes: 4