[keycloak-user] Keycloak Admin Client dependencies for Keycloak 5.0.0?
Jody H
j9dy1g at gmail.com
Mon Apr 1 16:39:39 EDT 2019
Hi,
I have looked around on Google for a while now but I can't seem to figure
out my problem. I mostly used the Gist from Github here to get started:
https://gist.github.com/thomasdarimont/43689aefb37540624e35
After things were not really working out, I tried some other stuff that you
can find below:
I am trying to use the Keycloak admin client in Java, version 5.0.0.
My POM contains the following:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<keycloak.version>5.0.0</keycloak.version>
<resteasy.version>3.1.3.Final</resteasy.version>
<jackson.version>2.9.8</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
When I add the following code, building the keycloak client fails:
Keycloak keycloak =
KeycloakBuilder.builder().serverUrl("localhost:8080/auth").realm("master")
.username("admin").password("admin").clientId("admin-cli").build();
System.out.println(keycloak.serverInfo().getInfo().toString());
Produces the following exception:
java -jar .\keycloak-admin-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.IllegalArgumentException:
RESTEASY003720: path param realm has not been provided by the parameter map
at
org.jboss.resteasy.specimpl.ResteasyUriBuilder.replaceParameter(ResteasyUriBuilder.java:659)
at
org.jboss.resteasy.specimpl.ResteasyUriBuilder.buildString(ResteasyUriBuilder.java:581)
at
org.jboss.resteasy.specimpl.ResteasyUriBuilder.buildFromValues(ResteasyUriBuilder.java:780)
at
org.jboss.resteasy.specimpl.ResteasyUriBuilder.build(ResteasyUriBuilder.java:772)
at
org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.getUri(ClientWebTarget.java:107)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.createRequest(ClientInvoker.java:124)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy15.grantToken(Unknown Source)
at
org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:89)
at
org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69)
at
org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:64)
at
org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)
at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:431)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:105)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy17.getInfo(Unknown Source)
When using the Keycloak.getInstance method, I get another exception:
Keycloak keycloak = Keycloak.getInstance("http://localhost:8080/auth",
"master", "admin", "admin", "admin-cli");
Produces exception:
Exception in thread "main" javax.ws.rs.client.ResponseProcessingException:
javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a
MessageBodyReader of content-type application/json and type class
org.keycloak.representations.AccessTokenResponse
at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:156)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:60)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:107)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy15.grantToken(Unknown Source)
at
org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:89)
at
org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69)
at
org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:64)
at
org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)
at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:431)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:105)
at
org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy17.getInfo(Unknown Source)
at test.KeycloakAdmin.main(MyMain.java:17)
Caused by: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find
a MessageBodyReader of content-type application/json and type class
org.keycloak.representations.AccessTokenResponse
at
org.jboss.resteasy.core.interception.jaxrs.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:42)
at
org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:80)
at
org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
at
org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:266)
at
org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:196)
at
org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:212)
at
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:120)
... 13 more
Can someone share insight on how to use the keycloak admin client library
in the most recent version? Which dependencies do I need inside of my pom?
Thanks!
More information about the keycloak-user
mailing list