[英]Create user in keycloak through keycloak admin client returns IllegalArgumentException
I want to create a user through keycloak admin client but I am getting: 我想通过keycloak管理客户端创建一个用户,但是我得到了:
java.lang.IllegalArgumentException: RESTEASY003720: path param realm has not been provided by the parameter map
java.lang.IllegalArgumentException:RESTEASY003720:参数映射未提供路径参数领域
Here's my bean for keycloak: 这是我的钥匙斗篷豆:
@Bean
Keycloak keycloak() {
return KeycloakBuilder
.builder()
.serverUrl(localhost:9080/auth)
.realm(REALM)
.clientId(CLIENT_ID)
.username(USERNAME)
.password(PASSWORD)
.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())
.build();
}
I use this code for calling keycloak: 我使用以下代码来调用keycloak:
CredentialRepresentation credentialRepresentation = new
CredentialRepresentation();
credentialRepresentation.setType(CredentialRepresentation.PASSWORD);
credentialRepresentation.setValue(password);
UserRepresentation userRepresentation = new UserRepresentation();
userRepresentation.setUsername(username);
userRepresentation.setFirstName(firstName);
userRepresentation.setLastName(lastName);
userRepresentation.setEnabled(true);
userRepresentation.setCredentials(
Arrays.asList(credentialRepresentation));
keycloak.realm(REALM).users().create(userRepresentation);
both keycloak and keycloak admin client are the same version (4.0.0.Final) keycloak和keycloak管理客户端都是相同的版本(4.0.0.Final)
My stacktrace looks like this: 我的堆栈跟踪看起来像这样:
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:108) 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.$Proxy240.grantToken(Unknown Source) at org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:89) at org
java.lang.IllegalArgumentException:RESTEASY003720:org.jboss.resteasy.specimpl.ResteasyUriBuilder上的org.jboss.resteasy.specimpl.ResteasyUriBuilder.replaceParameter(ResteasyUriBuilder.java:659)上的参数映射未提供路径参数领域。 (ResteasyUriBuilder.java:581)在org.jboss.resteasy.specimpl.ResteasyUriBuilder.build(ResteasyUriBuilder.java:772)在org.jboss.resteasy.specimpl.ResteasyUriBuilder.buildFromValues(ResteasyUriBuilder.java:780)在org.jboss.resteasy.specimpl.ResteasyUriBuilder.build(ResteasyUriBuilds.java:772) org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.createRequest(ClientInvoker.java:124)上的resteasy.client.jaxrs.internal.ClientWebTarget.getUri(ClientWebTarget.java:108)在org.jboss.resteasy上。 org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)上的client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)com.sun.proxy上的(ClientProxy.java:76)。 org处org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:89)处的$ Proxy240.grantToken(未知源) .keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69) at org.mycompany.usermanagement.service.KeycloakService.createUserInSSO(KeycloakService.java:45)
org.mycompany.usermanagement.service.KeycloakService.createUserInSSO(KeycloakService.java:45)处的.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69)
and here is my build.gradle 这是我的build.gradle
compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '4.0.0.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'
Are you using Spring Boot? 您正在使用Spring Boot吗?
I have tried your scenario for myself, and works well for me (tested on keycloak 4.0.0 and Spring Boot 1.5.10.RELEASE). 我已经亲自尝试了您的方案,并且对我来说效果很好(在keycloak 4.0.0和Spring Boot 1.5.10.RELEASE上进行了测试)。
I have done 1 change that the way you create Bean Keycloak (my code is from official docs ). 我做了1次更改,即您创建Bean Keycloak的方式(我的代码来自官方文档 )。 Make sure that
realm
is master
and client_id
is admin-cli
. 确保
realm
是master
, client_id
是admin-cli
。
@Bean
Keycloak initKeycloakWithAdminRole() {
return Keycloak.getInstance(
"http://localhost:8080/auth",
"master",
"admin",
"admin",
"admin-cli");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.