<div dir="ltr">Thanks Paulo. Adding last two dependencies solved root problem.<div><br><div>I am trying to create new realm using below code snippet but getting error. Please find code snippet and error stack at keycloak server console which as follows:</div><div><br></div><div>Code Snippet:</div><div><br></div><div><div>Keycloak kc = KeycloakBuilder.builder() //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.serverUrl("<a href="http://localhost:8080/auth">http://localhost:8080/auth</a>") //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.realm("master")//</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.username("admin") //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.password("admin") //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.clientId("admin-cli") //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>// .clientId("security-admin-console") //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) //</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>.build();</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>RealmRepresentation realmRep = new RealmRepresentation();</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>realmRep.setDisplayName("Created_Realm");</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>realmRep.setEnabled(true);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>kc.realms().create(realmRep);</div><div><br></div><div>Error Stack:</div><div><br></div><div><div>Caused by: java.lang.NullPointerException</div><div> at org.keycloak.services.managers.RealmManager.createMasterAdminManagement(RealmManager.java:289)</div><div> at org.keycloak.services.managers.RealmManager.setupMasterAdminManagement(RealmManager.java:281)</div><div> at org.keycloak.services.managers.RealmManager.importRealm(RealmManager.java:433)</div><div> at org.keycloak.services.resources.admin.RealmsAdminResource.importRealm(RealmsAdminResource.java:151)</div><div> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</div><div> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)</div><div> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div><div> at java.lang.reflect.Method.invoke(Method.java:498)</div><div> at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)</div><div> at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)</div><div> at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)</div><div> at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:138)</div><div> at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:101)</div><div> at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)</div><div> ... 37 more</div></div><div><br></div><div>Upon looking into RealmManger source code at git hub found there is a conditional check kept which compare realmName and adminRealm from configuration</div><div><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"><br></span></div><div><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"> </span><span class="gmail-pl-k" style="color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">if</span><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"> (realm</span><span class="gmail-pl-k" style="color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">.</span><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">getName()</span><span class="gmail-pl-k" style="color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">.</span><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">equals(</span><span class="gmail-pl-smi" style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">Config</span><span class="gmail-pl-k" style="color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">.</span><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">getAdminRealm())) inside </span><span style="color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">setupMasterAdminManagement method</span><br></div><div><span style="color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"><br></span></div><div><span style="color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">If we look above code snippet only realmDisplayName and enable attributes are set during creation of realm(generally use to provide if create realm using keycloak server console) </span></div><div><span style="color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">but conditional check on getName(name) of RealmModel class which might be causing issue, there is no setName method(setter) available inside RealmRepresentation class under keycloak client admin library.</span></div><div><br></div><div><span style="color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre">Can someone please provide guidance on this issue or suggest a way to create realm using keycloak-admin-client bundle.</span></div><div><span style="color:rgb(51,51,51);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;white-space:pre"><br></span></div><div><br></div><div>Thanks,</div><div>Jitendra Chouhan</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 26, 2016 at 1:53 PM, Paulo Pires <span dir="ltr"><<a href="mailto:pires@littlebits.cc" target="_blank">pires@littlebits.cc</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><div class="h5"><div dir="ltr">On Tue, Jul 26, 2016 at 8:08 AM Jitendra Chouhan <<a href="mailto:jitendrachouhan03@gmail.com" target="_blank">jitendrachouhan03@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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></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>
</blockquote></div><br></div>