<div dir="ltr">You need to explicitly provide the following dependencies:<div><br></div><div><div> <dependency></div><div> <groupId>org.keycloak</groupId></div><div> <artifactId>keycloak-admin-client</artifactId></div><div> <version>${keycloak.version}</version></div><div> </dependency></div><div> <dependency></div><div> <groupId>org.jboss.resteasy</groupId></div><div> <artifactId>resteasy-client</artifactId></div><div> <version>${resteasy.version}</version></div><div> </dependency></div><div> <dependency></div><div> <groupId>org.jboss.resteasy</groupId></div><div> <artifactId>resteasy-jackson2-provider</artifactId></div><div> <version>${resteasy.version}</version></div><div> </dependency></div><div> <dependency></div><div> <groupId>org.jboss.resteasy</groupId></div><div> <artifactId>resteasy-multipart-provider</artifactId></div><div> <version>${resteasy.version}</version></div><div> </dependency></div></div><div><br></div><div>Pires</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 26, 2016 at 8:08 AM Jitendra Chouhan <<a href="mailto:jitendrachouhan03@gmail.com">jitendrachouhan03@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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:<div><br></div><div>1) keycloak-server version: 1.9.8.Final or 2.0.0.Final</div><div>2) keycloak-admin-client version: 1.9.8.Final or 2.0.0.Final</div><div><br></div><div>Sample Code Snippet:</div><div><br></div><div><div>Keycloak kc = KeycloakBuilder.builder() //</div><div><span style="white-space:pre-wrap">                                </span>.serverUrl("<a href="http://localhost:8080/auth" target="_blank">http://localhost:8080/auth</a>") //</div><div><span style="white-space:pre-wrap">                                </span>.realm("master")//</div><div><span style="white-space:pre-wrap">                                </span>.username("admin") //</div><div><span style="white-space:pre-wrap">                                </span>.password("admin") //</div><div><span style="white-space:pre-wrap">                                </span>.clientId("admin-cli") //</div><div><span style="white-space:pre-wrap">                                </span>// .clientId("security-admin-console") //</div><div><span style="white-space:pre-wrap">                                </span>.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())//</div><div><span style="white-space:pre-wrap">                                </span>.build();</div></div><div><div>// 1. User</div><div><span style="white-space:pre-wrap">                </span>CredentialRepresentation credential = new CredentialRepresentation();</div><div><span style="white-space:pre-wrap">                </span>credential.setType(CredentialRepresentation.PASSWORD);</div><div><span style="white-space:pre-wrap">                </span>credential.setValue("test123");</div><div><span style="white-space:pre-wrap">                </span>credential.setTemporary(false);</div><div><br></div><div><span style="white-space:pre-wrap">                </span>UserRepresentation user = new UserRepresentation();</div><div><span style="white-space:pre-wrap">                </span>user.setUsername("testuser");</div><div><span style="white-space:pre-wrap">                </span>user.setFirstName("Test");</div><div><span style="white-space:pre-wrap">                </span>user.setLastName("User");</div><div><span style="white-space:pre-wrap">                </span>user.setCredentials(asList(credential));</div><div><span style="white-space:pre-wrap">                </span>user.setEnabled(true);</div><div><span style="white-space:pre-wrap">                </span>user.setRealmRoles(asList("admin"));</div><div><br></div><div><span style="white-space:pre-wrap">                </span>// create a user</div><div><span style="white-space:pre-wrap">                </span>//Response result = kc.realm("master").users().create(user);</div><div><span style="white-space:pre-wrap">                </span>Response result = kc.realm("demo").users().create(user);</div><div><span style="white-space:pre-wrap">                </span>if (result.getStatus() != 201) {</div><div><span style="white-space:pre-wrap">                        </span>if(result.getStatus() == 409){</div><div><span style="white-space:pre-wrap">                                </span>System.err.println("Couldn't create user since user already exist.");</div><div><span style="white-space:pre-wrap">                                </span>System.exit(0);</div><div><span style="white-space:pre-wrap">                        </span>}</div><div><span style="white-space:pre-wrap">                        </span>System.err.println("Couldn't create user.");</div><div><span style="white-space:pre-wrap">                        </span>System.exit(0);</div><div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">                </span>System.out.println("test user created.... verify in keycloak!");</div></div><div><br></div><div>Error stack trace::</div><div><br></div><div><div>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</div><div> at [Source: org.apache.http.conn.EofSensorInputStream@6f3c660a; line: 1, column: 18] (through reference chain: org.keycloak.representations.AccessTokenResponse["access_token"])</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:140)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:58)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:62)</div><div><span style="white-space:pre-wrap">        </span>at com.sun.proxy.$Proxy19.grantToken(Unknown Source)</div><div><span style="white-space:pre-wrap">        </span>at org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:85)</div><div><span style="white-space:pre-wrap">        </span>at org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:65)</div><div><span style="white-space:pre-wrap">        </span>at org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:60)</div><div><span style="white-space:pre-wrap">        </span>at org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:384)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:102)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:62)</div><div><span style="white-space:pre-wrap">        </span>at com.sun.proxy.$Proxy27.create(Unknown Source)</div><div><span style="white-space:pre-wrap">        </span>at com.samba.security.keycloak.KeycloakAdminClientExample.main(KeycloakAdminClientExample.java:79)</div><div>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</div><div> at [Source: org.apache.http.conn.EofSensorInputStream@6f3c660a; line: 1, column: 18] (through reference chain: org.keycloak.representations.AccessTokenResponse["access_token"])</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:282)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104)</div><div><span style="white-space:pre-wrap">        </span>... 13 more</div><div>Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "access_token" (Class org.keycloak.representations.AccessTokenResponse), not marked as ignorable</div><div> at [Source: org.apache.http.conn.EofSensorInputStream@6f3c660a; line: 1, column: 18] (through reference chain: org.keycloak.representations.AccessTokenResponse["access_token"])</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)</div><div><span style="white-space:pre-wrap">        </span>at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:59)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:51)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)</div><div><span style="white-space:pre-wrap">        </span>at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:248)</div></div><div><br></div><div>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.</div><div><br></div><div>Thanks,</div><div>Jitendra Chouhan</div><div><br></div></div>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></blockquote></div>