I can't get user groups like in samples. Samples from: Take a look at our testsuite. For example:
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();
When I try to get user:
//this line works final UserResource userr = this.keycloak.realms().realm("myrealm").users().get("admin"); //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. admin is one of this users and is member of this two groups.
Users I've created are in "myrealm" realm, "admin" is one of them.
I've olso tried to give all available roles from clients and realm but this changes nothing.
admin-cli I meant keycloak app on localhost
What am I missing?
Libs I am 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;