<div dir="ltr"><div>We have an issue outstanding to get the admin-client example working on EAP 6.4.</div><a href="https://issues.jboss.org/browse/KEYCLOAK-1921">https://issues.jboss.org/browse/KEYCLOAK-1921</a><br><div><br></div><div>Not sure when we'll get to it though.</div><div><br></div><div>I suspect the only way to get it to work on EAP 6.4 would be to prevent the old RestEasy from being added (should be possible to do in jboss-secure-deployment with exclude subsystem), then add the new RestEasy dependencies directly to the WAR. </div><div><br></div><div>You could also look at <a href="https://docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html/Installation_Configuration.html#upgrading-eap61">https://docs.jboss.org/resteasy/docs/3.0.1.Final/userguide/html/Installation_Configuration.html#upgrading-eap61</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 15 January 2016 at 05:44, JasonPeng <span dir="ltr"><<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>></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 Stian,</div><div><br></div><div>Do you have an example of pom.xml if I want to fully control the Keycloak user management(ex: create user, change roles)? I’ve tried the approach you suggest, however it comes out with problem that I don’t know if it’s missing some dependency in my client project or I fail on configuring the jboss-deployment-structure.xml</div><div><br></div><div><div><div>Thanks,</div><div>Jason</div><div><br></div><div><br></div></div></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> Stian Thorgersen <<a href="mailto:sthorger@redhat.com" target="_blank">sthorger@redhat.com</a>><br><span style="font-weight:bold">Reply-To: </span> <<a href="mailto:stian@redhat.com" target="_blank">stian@redhat.com</a>><br><span style="font-weight:bold">Date: </span> Thursday, January 14, 2016 at 5:00 PM<br><span style="font-weight:bold">To: </span> JasonMacAir <<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>><br><span style="font-weight:bold">Cc: </span> Thomas Darimont <<a href="mailto:thomas.darimont@googlemail.com" target="_blank">thomas.darimont@googlemail.com</a>>, keycloak-user <<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>><div><div class="h5"><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><div><div class="h5"><div><br></div><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"><<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>></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, "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><jboss-deployment-structure></div><div> <deployment></div><div> <dependencies></div><div> <module name="org.jboss.resteasy.resteasy-jaxrs" services="import"/></div><div> </dependencies></div><div> </deployment></div><div></jboss-deployment-structure></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 <<a href="mailto:thomas.darimont@googlemail.com" target="_blank">thomas.darimont@googlemail.com</a>><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 <<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>><br><span style="font-weight:bold">Cc: </span> keycloak-user <<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>><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><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("<a href="http://localhost:8081/auth" target="_blank">http://localhost:8081/auth</a>") //</div><div><span style="white-space:pre-wrap">                                </span>.realm("rest-example")//</div><div><span style="white-space:pre-wrap">                                </span>.username("rest-user-admin") //</div><div><span style="white-space:pre-wrap">                                </span>.password("password") //</div><div><span style="white-space:pre-wrap">                                </span>.clientId("admin-cli") //</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("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 testuser</div><div><span style="white-space:pre-wrap">                </span>Response result = kc.realm("rest-example").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("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("Testuser created.... verify in keycloak!");</div><div><br></div><div><span style="white-space:pre-wrap">                </span>System.out.println("Press any key...");</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("Location");</div><div><span style="white-space:pre-wrap">                </span>String userId = locationHeader.replaceAll(".*/(.*)$", "$1");</div><div><span style="white-space:pre-wrap">                </span>kc.realm("rest-example").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"><<a href="mailto:hpeng@redhat.com" target="_blank">hpeng@redhat.com</a>></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 = "e20277f8-2ebe-4e5e-aa00-0cee9c578249";</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) + "/admin/realms/demo/users/" + userId);</div><div><span style="white-space:pre-wrap">                </span>delete.addHeader("Authorization", "Bearer " + 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" 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>
</blockquote></div><br></div>