简体   繁体   中英

Displaying a User Email using keycloak Admin Client not working(UnrecognizedPropertyException)

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM