[keycloak-user] REST api and the Admin Client Java Wrapper

Chris Smith chris.smith at cmfirstgroup.com
Mon Aug 26 15:05:05 EDT 2019


I'm trying to use the REST java api.
My maven dependencies

  <dependencies>
     <dependency>
           <groupId>org.keycloak</groupId>
           <artifactId>keycloak-admin-client</artifactId>
           <version>7.0.0-SNAPSHOT</version>
     </dependency>
     <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-client</artifactId>
           <version>3.8.1.Final</version>
     </dependency>
     <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-jackson2-provider</artifactId>
           <version>3.8.1.Final</version>
     </dependency>
     <dependency>
           <groupId>org.jboss.resteasy</groupId>
           <artifactId>resteasy-multipart-provider</artifactId>
           <version>3.8.1.Final</version>
     </dependency>
  </dependencies>

I can create a keycloak instance and get a RealmRepresentation.  The RealmRepresentation looks like I expect it should, matching what I see in the KC console.

When I try to get users or federated users, a null is returned.

Here is a code snip

                                                Keycloak keycloak = Keycloak.getInstance(
                         serverUrl,
                         realmName,
                         username,
                         password,
                         clientId);
                RealmResource realmsResource = keycloak.realm("fms-sso");
                RealmRepresentation realm = realmsResource.toRepresentation();
                List<UserRepresentation> userRepresentations = realm.getFederatedUsers();
                userRepresentations.stream().forEach(this::printUser);
                userRepresentations = realm.getUsers();
                userRepresentations.stream().forEach(this::printUser);

realm.getFederatedUsers();
and
realm.getUsers()

both return null, not even an empty list.

Is there something required before getting the users from a RealmRepresenetation?


More information about the keycloak-user mailing list