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

Chris Smith chris.smith at cmfirstgroup.com
Mon Aug 26 23:44:52 EDT 2019


Thank you.  That worked.

From: Stefan Guilhen <sguilhen at redhat.com>
Sent: Monday, August 26, 2019 9:58 PM
To: Chris Smith <chris.smith at cmfirstgroup.com>
Cc: keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] REST api and the Admin Client Java Wrapper

RealmResource.toRepresentation() doesn't include the users. To retrieve the users try the following:

RealmResource realmsResource = keycloak.realm("fms-sso");
List<UserRepresentation> userRepresentations = realmsResource.users().list();

On Mon, Aug 26, 2019 at 4:10 PM Chris Smith <chris.smith at cmfirstgroup.com<mailto:chris.smith at cmfirstgroup.com>> wrote:
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?
_______________________________________________
keycloak-user mailing list
keycloak-user at lists.jboss.org<mailto:keycloak-user at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/keycloak-user


--

Stefan Guilhen

Principal Software Engineer

Red Hat<https://www.redhat.com/>

sguilhen at redhat.com<mailto:sguilhen at redhat.com>    IM: sguilhen
@RedHat<https://twitter.com/redhat>   Red Hat<https://www.linkedin.com/company/red-hat>  Red Hat<https://www.facebook.com/RedHatInc>
[https://marketing-outfit-prod-images.s3-us-west-2.amazonaws.com/f5445ae0c9ddafd5b2f1836854d7416a/Logo-RedHat-Email.png]<https://www.redhat.com/>



More information about the keycloak-user mailing list