<div dir="ltr">EAP 6.4 has an old version of RestEasy without the RestEasy client. Easiest option is probably to just include newer RestEasy jars in your WAR.</div><div class="gmail_extra"><br><div class="gmail_quote">On 14 January 2016 at 09:55, JasonPeng <span dir="ltr">&lt;<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif"><div>Hi Thomas,</div><div><br></div><div>Thank’s for the recommendation. However, I bumped into some clossloader issue when I tried it on my EAP 6.4+ Keycloak 1.1.7.Final environment.</div><div><br></div><div>I keep get the class not found error against RestEasy Client, &quot;java.lang.NoClassDefFoundError: org/jboss/resteasy/client/jaxrs/ResteasyClientBuilder”. Although I’d setup my jboss-deployment-structure.xml in my project under /WEB-INF/. The setting is like below:</div><div><br></div><div><div>&lt;jboss-deployment-structure&gt;</div><div>    &lt;deployment&gt;</div><div>        &lt;dependencies&gt;</div><div>            &lt;module name=&quot;org.jboss.resteasy.resteasy-jaxrs&quot; services=&quot;import&quot;/&gt;</div><div>        &lt;/dependencies&gt;</div><div>    &lt;/deployment&gt;</div><div>&lt;/jboss-deployment-structure&gt;</div></div><div><br></div><div><br></div><div><div><div>Thank you and best regards,</div><div>— </div><div>Jason Peng</div><div>Solution Architect, Taiwan</div><div>Ret Hat Limited</div><div>TEL: <a href="tel:%2B886-2-7743-2972" value="+886277432972" target="_blank">+886-2-7743-2972</a></div><div>FAX: <a href="tel:%2B886-2-7743-2974" value="+886277432974" target="_blank">+886-2-7743-2974</a></div><div>Mobile: <a href="tel:%2B886-988-836-827" value="+886988836827" target="_blank">+886-988-836-827</a></div><div>EMAIL: <a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a></div><div><br></div><div><br></div></div></div><div><br></div><div><br></div><span><div style="font-family:Calibri;font-size:11pt;text-align:left;color:black;BORDER-BOTTOM:medium none;BORDER-LEFT:medium none;PADDING-BOTTOM:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in;BORDER-TOP:#b5c4df 1pt solid;BORDER-RIGHT:medium none;PADDING-TOP:3pt"><span style="font-weight:bold">From: </span> Thomas Darimont &lt;<a href="mailto:thomas.darimont@googlemail.com" target="_blank">thomas.darimont@googlemail.com</a>&gt;<br><span style="font-weight:bold">Date: </span> Wednesday, January 13, 2016 at 3:26 AM<br><span style="font-weight:bold">To: </span> JasonMacAir &lt;<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>&gt;<br><span style="font-weight:bold">Cc: </span> keycloak-user &lt;<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>&gt;<br><span style="font-weight:bold">Subject: </span> Re: [keycloak-user] How to correctly use REST API? delete user through REST API for example<br></div><div><div class="h5"><div><br></div><div dir="ltr">Hi Jason,<div><br></div><div>do you really need to use the raw REST API or would it be an option to use the keycloak-admin-client API?</div><div><br></div><div>here is an example for creating and deleting a user via the admin-client API:</div><div><br></div><div><div>package de.tdlabs.training.keycloak;</div><div><br></div><div>import static java.util.Arrays.asList;</div><div><br></div><div>import javax.ws.rs.core.Response;</div><div><br></div><div>import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;</div><div>import org.keycloak.admin.client.Keycloak;</div><div>import org.keycloak.admin.client.KeycloakBuilder;</div><div>import org.keycloak.representations.idm.CredentialRepresentation;</div><div>import org.keycloak.representations.idm.UserRepresentation;</div><div><br></div><div>public class KeycloakAdminClientExample {</div><div><br></div><div><span style="white-space:pre-wrap">        </span>public static void main(String[] args) throws Exception {</div><div><br></div><div><span style="white-space:pre-wrap">                </span>Keycloak kc = KeycloakBuilder.builder() //</div><div><span style="white-space:pre-wrap">                                </span>.serverUrl(&quot;<a href="http://localhost:8081/auth" target="_blank">http://localhost:8081/auth</a>&quot;) //</div><div><span style="white-space:pre-wrap">                                </span>.realm(&quot;rest-example&quot;)//</div><div><span style="white-space:pre-wrap">                                </span>.username(&quot;rest-user-admin&quot;) //</div><div><span style="white-space:pre-wrap">                                </span>.password(&quot;password&quot;) //</div><div><span style="white-space:pre-wrap">                                </span>.clientId(&quot;admin-cli&quot;) //</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><br></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(&quot;test123&quot;);</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(&quot;testuser&quot;);</div><div><span style="white-space:pre-wrap">                </span>user.setFirstName(&quot;Test&quot;);</div><div><span style="white-space:pre-wrap">                </span>user.setLastName(&quot;User&quot;);</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(&quot;admin&quot;));</div><div><br></div><div><span style="white-space:pre-wrap">                </span>// Create testuser</div><div><span style="white-space:pre-wrap">                </span>Response result = kc.realm(&quot;rest-example&quot;).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>System.err.println(&quot;Couldn&#39;t create user.&quot;);</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(&quot;Testuser created.... verify in keycloak!&quot;);</div><div><br></div><div><span style="white-space:pre-wrap">                </span>System.out.println(&quot;Press any key...&quot;);</div><div><span style="white-space:pre-wrap">                </span>System.in.read();</div><div><br></div><div><span style="white-space:pre-wrap">                </span>// Delete testuser</div><div><span style="white-space:pre-wrap">                </span>String locationHeader = result.getHeaderString(&quot;Location&quot;);</div><div><span style="white-space:pre-wrap">                </span>String userId = locationHeader.replaceAll(&quot;.*/(.*)$&quot;, &quot;$1&quot;);</div><div><span style="white-space:pre-wrap">                </span>kc.realm(&quot;rest-example&quot;).users().get(userId).remove();</div><div><span style="white-space:pre-wrap">        </span>}</div><div>}<br></div></div><div><br></div><div><br></div><div><a href="https://gist.github.com/thomasdarimont/43689aefb37540624e35" target="_blank">https://gist.github.com/thomasdarimont/43689aefb37540624e35</a><br></div><div><br></div><div>Cheers,</div><div>Thomas</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-12 19:05 GMT+01:00 JasonPeng <span dir="ltr">&lt;<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;font-size:14px;font-family:Calibri,sans-serif;color:rgb(0,0,0)"><div>Hi there,</div><div><br></div><div>Can someone give me some hint about how to correctly setup a client that can accept REST request from a httpclient in keycloak?</div><div>For example, I use the admin-access example from keycloak source project and modify it to do a DELETE action through REST API, however I keep getting the request Forbidden 403 from keycloak server. I don’t change any setting of the admin-client imported from the json file and my code snippet of deleting user as below:</div><div><br></div><div><div>public static void deleteUser(HttpServletRequest request, AccessTokenResponse res) throws Failure {</div><div><span style="white-space:pre-wrap">        </span>HttpClient client = new DefaultHttpClient();</div><div><span style="white-space:pre-wrap">        </span>String userId = &quot;e20277f8-2ebe-4e5e-aa00-0cee9c578249&quot;;</div><div><span style="white-space:pre-wrap">        </span>try {</div><div><span style="white-space:pre-wrap">                </span>HttpDelete delete = new HttpDelete(getBaseUrl(request) + &quot;/admin/realms/demo/users/&quot; + userId);</div><div><span style="white-space:pre-wrap">                </span>delete.addHeader(&quot;Authorization&quot;, &quot;Bearer &quot; + res.getToken());</div><div><span style="white-space:pre-wrap">                </span>HttpResponse response = client.execute(delete);</div><div><span style="white-space:pre-wrap">                </span>System.out.println(response.getStatusLine().getReasonPhrase());</div><div><span style="white-space:pre-wrap">                </span>if (response.getStatusLine().getStatusCode() != 200) {</div><div><span style="white-space:pre-wrap">                        </span>throw new Failure(response.getStatusLine().getStatusCode());</div><div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">                </span>HttpEntity entity = response.getEntity();</div><div><span style="white-space:pre-wrap">                </span>InputStream is = entity.getContent();</div><div><span style="white-space:pre-wrap">                </span>if (is != null)</div><div><span style="white-space:pre-wrap">                        </span>is.close();</div><div><span style="white-space:pre-wrap">        </span>} catch (IOException e) {</div><div><span style="white-space:pre-wrap">                </span>throw new RuntimeException(e);</div><div><span style="white-space:pre-wrap">        </span>} finally {</div><div><span style="white-space:pre-wrap">                </span>client.getConnectionManager().shutdown();</div><div><span style="white-space:pre-wrap">        </span>}</div><div>}</div></div></div><br>_______________________________________________<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><br></blockquote></div><br></div></div></div></span></div>
<br>_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">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><br></blockquote></div><br></div>