-
-
Save ThomasVitale/b1f9b166277721582ce78ff1f7ec5873 to your computer and use it in GitHub Desktop.
| group 'com.thomasvitale.keycloak-demo' | |
| version '1.0-SNAPSHOT' | |
| apply plugin: 'java' | |
| sourceCompatibility = 1.8 | |
| repositories { | |
| mavenCentral() | |
| } | |
| dependencies { | |
| compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '3.3.0.CR2' | |
| //compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '3.2.1.Final' | |
| compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.4.Final' | |
| compile group: 'org.jboss.resteasy', name: 'resteasy-client', version: '3.1.4.Final' | |
| compile group: 'org.jboss.resteasy', name: 'resteasy-jackson2-provider', version: '3.1.4.Final' | |
| testCompile group: 'junit', name: 'junit', version: '4.12' | |
| } |
| import com.sun.org.apache.regexp.internal.RE; | |
| import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; | |
| import org.keycloak.admin.client.Keycloak; | |
| import org.keycloak.admin.client.KeycloakBuilder; | |
| import org.keycloak.admin.client.resource.UserResource; | |
| import org.keycloak.admin.client.resource.UsersResource; | |
| import org.keycloak.representations.idm.CredentialRepresentation; | |
| import org.keycloak.representations.idm.UserRepresentation; | |
| import java.util.Arrays; | |
| public class Main { | |
| private static final String SERVER_URL = "http://localhost:8180/auth"; | |
| private static final String REALM = "demo"; | |
| private static final String USERNAME = "dumbledore"; | |
| private static final String PASSWORD = "password"; | |
| private static final String CLIENT_ID = "demo-client"; | |
| public static void main(String[] args) { | |
| Keycloak keycloak = KeycloakBuilder | |
| .builder() | |
| .serverUrl(SERVER_URL) | |
| .realm(REALM) | |
| .username(USERNAME) | |
| .password(PASSWORD) | |
| .clientId(CLIENT_ID) | |
| .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) | |
| .build(); | |
| CredentialRepresentation credentialRepresentation = new CredentialRepresentation(); | |
| credentialRepresentation.setType(CredentialRepresentation.PASSWORD); | |
| credentialRepresentation.setValue("12345678"); | |
| UserRepresentation userRepresentation = new UserRepresentation(); | |
| userRepresentation.setUsername("lupin"); | |
| userRepresentation.setFirstName("Remus"); | |
| userRepresentation.setLastName("Lupin"); | |
| userRepresentation.setEnabled(true); | |
| userRepresentation.setCredentials(Arrays.asList(credentialRepresentation)); | |
| //keycloak.realm(REALM).users().create(userRepresentation); | |
| UsersResource usersResource = keycloak.realm(REALM).users(); | |
| UserRepresentation user = usersResource.search("lupin").get(0); | |
| user.setEmail("[email protected]"); | |
| usersResource.get(user.getId()).update(user); | |
| } | |
| } |
hey, i'm setting these client roles but still getting error. Although I'm using keycloak version 10 and it seems a bit different. Does anybody have a good source that explains how to set this up ?
Help! org.jboss.resteasy resteasy-client 3.1.4.Final
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplates(Ljava/util/Map;)Ljavax/ws/rs/core/UriBuilder; at org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.resolveTemplates(ClientWebTarget.java:177) at org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.resolveTemplates(ClientWebTarget.java:25) at org.jboss.resteasy.client.jaxrs.internal.proxy.SubResourceInvoker.invoke(SubResourceInvoker.java:71) at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76) at com.sun.proxy.$Proxy20.realm(Unknown Source) at org.keycloak.admin.client.Keycloak.realm(Keycloak.java:116) at com.fit2cloud.mc.test.main(test.java:45)
https://stackoverflow.com/a/60471582/10311582 this helped me for the same issue.

me to