[keycloak-user] Keycloak Admin Client Jar - 1.9.8/ 2.0.0 are not working properly
Paulo Pires
pires at littlebits.cc
Tue Jul 26 04:23:51 EDT 2016
You need to explicitly provide the following dependencies:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
Pires
On Tue, Jul 26, 2016 at 8:08 AM Jitendra Chouhan <
jitendrachouhan03 at gmail.com> wrote:
> I am using keycloak-admin-client jar for provisioning users in keycloak
> server instance but facing issue if using keycloak-admin-client version
> higher than 1.8.0.Final. Please find detailed informations about issue and
> configurations used to provision user as below:
>
> 1) keycloak-server version: 1.9.8.Final or 2.0.0.Final
> 2) keycloak-admin-client version: 1.9.8.Final or 2.0.0.Final
>
> Sample Code Snippet:
>
> Keycloak kc = KeycloakBuilder.builder() //
> .serverUrl("http://localhost:8080/auth") //
> .realm("master")//
> .username("admin") //
> .password("admin") //
> .clientId("admin-cli") //
> // .clientId("security-admin-console") //
> .resteasyClient(new
> ResteasyClientBuilder().connectionPoolSize(10).build())//
> .build();
> // 1. User
> CredentialRepresentation credential = new CredentialRepresentation();
> credential.setType(CredentialRepresentation.PASSWORD);
> credential.setValue("test123");
> credential.setTemporary(false);
>
> UserRepresentation user = new UserRepresentation();
> user.setUsername("testuser");
> user.setFirstName("Test");
> user.setLastName("User");
> user.setCredentials(asList(credential));
> user.setEnabled(true);
> user.setRealmRoles(asList("admin"));
>
> // create a user
> //Response result = kc.realm("master").users().create(user);
> Response result = kc.realm("demo").users().create(user);
> if (result.getStatus() != 201) {
> if(result.getStatus() == 409){
> System.err.println("Couldn't create user since user already exist.");
> System.exit(0);
> }
> System.err.println("Couldn't create user.");
> System.exit(0);
> }
> System.out.println("test user created.... verify in keycloak!");
>
> Error stack trace::
>
> Exception in thread "main" javax.ws.rs.client.ResponseProcessingException:
> javax.ws.rs.ProcessingException:
> org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized
> field "access_token" (Class
> org.keycloak.representations.AccessTokenResponse), not marked as ignorable
> at [Source: org.apache.http.conn.EofSensorInputStream at 6f3c660a; line: 1,
> column: 18] (through reference chain:
> org.keycloak.representations.AccessTokenResponse["access_token"])
> at
> org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:140)
> at
> org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:58)
> 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:62)
> at com.sun.proxy.$Proxy19.grantToken(Unknown Source)
> at
> org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:85)
> at
> org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:65)
> at
> org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:60)
> at
> org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)
> at
> org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:384)
> at
> org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:102)
> at
> org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:62)
> at com.sun.proxy.$Proxy27.create(Unknown Source)
> at
> com.samba.security.keycloak.KeycloakAdminClientExample.main(KeycloakAdminClientExample.java:79)
> Caused by: javax.ws.rs.ProcessingException:
> org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized
> field "access_token" (Class
> org.keycloak.representations.AccessTokenResponse), not marked as ignorable
> at [Source: org.apache.http.conn.EofSensorInputStream at 6f3c660a; line: 1,
> column: 18] (through reference chain:
> org.keycloak.representations.AccessTokenResponse["access_token"])
> at
> org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:282)
> at
> org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)
> at
> org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211)
> at
> org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104)
> ... 13 more
> Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException:
> Unrecognized field "access_token" (Class
> org.keycloak.representations.AccessTokenResponse), not marked as ignorable
> at [Source: org.apache.http.conn.EofSensorInputStream at 6f3c660a; line: 1,
> column: 18] (through reference chain:
> org.keycloak.representations.AccessTokenResponse["access_token"])
> at
> org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
> at
> org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
> at
> org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
> at
> org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
> at
> org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
> at
> org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
> at
> org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
> at
> org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
> at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
> at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
> at
> org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
> at
> org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:59)
> at
> org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:51)
> at
> org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
> at
> org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
> at
> org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:248)
>
> Same sample code with keycloak-admin-client version: 1.8.0 is working fine
> and able to provision user in keycloak server. Hence there is some issue
> with higher version of keycloak-client-admin bundle than 1.8.0. Please find
> attached pom file for project.
>
> Thanks,
> Jitendra Chouhan
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160726/a6d8c4da/attachment.html
More information about the keycloak-user
mailing list