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

Stefan Guilhen sguilhen at redhat.com
Mon Aug 26 22:58:06 EDT 2019


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>
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
> https://lists.jboss.org/mailman/listinfo/keycloak-user
>


-- 

Stefan Guilhen

Principal Software Engineer

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

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://www.redhat.com/>


More information about the keycloak-user mailing list