3

I'm trying to display a userEmail() or to display all the information about a user in our realm in general.

I'm trying to invoke this method :-

@Test 
    public void displayUser(){

        UsersResource users=kc.realm("SpringBoot").users();
        UserResource user=users.get("b3479699-430b-4cd3-be96-d26db584d207"); //Succeeds, we have the user
        UserRepresentation ur=user.toRepresentation();
        System.out.println(ur.getEmail());


    }

But it fails, giving me this error:-|

javax.ws.rs.client.ResponseProcessingException: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "notBefore" (class org.keycloak.representations.idm.UserRepresentation), not marked as ignorable (25 known properties: "disableableCredentialTypes", "enabled", "emailVerified", "origin", "self", "applicationRoles", "createdTimestamp", "clientRoles", "groups", "username", "totp", "id", "email", "federationLink", "serviceAccountClientId", "lastName", "clientConsents", "socialLinks", "realmRoles", "attributes", "firstName", "credentials", "requiredActions", "federatedIdentities", "access"])
 at [Source: org.apache.http.conn.EofSensorInputStream@4ee203eb; line: 1, column: 248] (through reference chain: org.keycloak.representations.idm.UserRepresentation["notBefore"])
        at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834)
        at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1489)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1467)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
        at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1583)
        at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:964)
        at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.readFrom(ResteasyJackson2Provider.java:127)
        at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:61)
        at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
        at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
        at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:55)
        at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)
        at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)
        at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:213)
        at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:105)
        at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:60)
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
        at com.sun.proxy.$Proxy31.toRepresentation(Unknown Source)
        at com.example.keycloakaccess2.KeycloakAccess2ApplicationTests.displayUser(KeycloakAccess2ApplicationTests.java:134)

I wonder if there is a proper way to display the information about the user or even to display the users we have in our realm !

I appreciate your help.

Ziko
  • 919
  • 2
  • 10
  • 22
  • Check https://stackoverflow.com/questions/37786756/keycloak-error-unrecognized-field-access-token – Yohannes Gebremariam Sep 26 '17 at 15:57
  • I saw it, I'm already using Jackson provider 2. That solved a first issue I had, but the UserRepresentation has a problem everytime I try to use it I get Unrecognizedfield. While RoleRepresentation works well! – Ziko Sep 26 '17 at 17:15
  • 1
    Which version of Keycloak are you using ? Are you sure you are using the same version for the server and the admin client classes ? – Sébastien Blanc Sep 27 '17 at 06:13
  • Hello Sebastien !! First of all I'm glad you replied to my comment, I have always been a fan to your videos. I'm using keycloak-admin-client 3.1.0 Final and keycloak server 3.3.0.CR2, do you suggest anything? @SébastienBlanc – Ziko Sep 27 '17 at 13:24
  • @SébastienBlanc Okay by fixing the different versions problem, it worked ! Thank you so much :) – Ziko Sep 27 '17 at 16:54

1 Answers1

1

Just to make it more visible, I do repeat Sébastien's Blanc answer found in the comments.

The keycloak adapter and client dependencies are not the same version, so Jackson got some fields that cannot be mapped to a class (in this case the field notBefore was not available in the UserRepresentation class).

So in your pom.xml, make sure depencies are the same. For example:

<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-spring-security-adapter</artifactId>
    <version>3.4.0.Final</version>
</dependency>
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-admin-client</artifactId>
    <version>3.4.0.Final</version>
</dependency>
Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78
  • 1
    Yeah thank you so that is becomes helpful for other people who face the same problem I faced. – Ziko Nov 17 '17 at 14:53