[keycloak-user] How to programically get groups/users/users in groups with roles from client using keycloak.admin.client.Keycloak,

adam.michalski at aol.com adam.michalski at aol.com
Wed Jan 11 09:10:40 EST 2017


I can't get user groups like in samples.
Sample code from examples for receiving groups user is member of:


 List<GroupRepresentation> membership = realm.users().get(user.getId()).groups();


My approach:
1. I create keycloak object for admin-cli client in myrealm realm:


	this.keycloak = KeycloakBuilder.builder()
				.serverUrl("http://localhost:18080/auth")
				.realm("myrealm")
				.username("admin")
				.password("admin")
				.clientId("admin-cli")
				.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())
				.build();


2.  When I try to get user:


	//this line works

	final UserResource userr = this.keycloak.realms().realm(this.REALM).users().get(user.getId());	


	//this two doesnt, in both result is javax.ws.rs.NotFoundException: HTTP 404 Not Found


	final UserRepresentation ur = userr.toRepresentation();
	final List<GroupRepresentation> groups = this.getRealm().users().get(user.getId()).groups();


In keycloak from admin-cli I created realm "myrealm" with 2 users and 2 groups
Every user is member of both groups.


What am I missing?



Using

import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.admin.client.resource.UsersResource;
import org.keycloak.representations.idm.GroupRepresentation;
import org.keycloak.representations.idm.UserRepresentation;


-----Original Message-----
From: Marko Strukelj <mstrukel at redhat.com>
To: adam.michalski <adam.michalski at aol.com>
Cc: keycloak-user <keycloak-user at lists.jboss.org>
Sent: Tue, Jan 10, 2017 12:33 pm
Subject: Re: [keycloak-user] How to programically get groups/users/users in groups with roles from client using keycloak.admin.client.Keycloak,



Take a look at our testsuite. For example:


https://github.com/keycloak/keycloak/blob/2.5.0.Final/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java#L837-L915



https://github.com/keycloak/keycloak/blob/2.5.0.Final/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java#L425-L495









On Tue, Jan 10, 2017 at 11:36 AM,  <adam.michalski at aol.com> wrote:

How to programically get groups/users/users in groups with roles from client using keycloak.admin.client.Keycloak,
_______________________________________________
keycloak-user mailing list
keycloak-user at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user







More information about the keycloak-user mailing list