通过keycloak管理客户端在keycloak中创建用户returns IllegalArgumentException
Create user in keycloak through keycloak admin client returns IllegalArgumentException
我想通过 keycloak 管理客户端创建一个用户,但我得到:
java.lang.IllegalArgumentException: RESTEASY003720: path param realm has not been provided by the parameter map
这是我用于 keycloak 的 bean:
@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();
}
我使用此代码调用 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);
keycloak 和 keycloak 管理客户端都是相同的版本 (4.0.0.Final)
我的堆栈跟踪看起来像这样:
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.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69)
at org.mycompany.usermanagement.service.KeycloakService.createUserInSSO(KeycloakService.java:45)
这是我的 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'
您是否正在使用 Spring 引导?
我已经为自己尝试了你的方案,对我来说效果很好(在 keycloak 4.0.0 和 Spring Boot 1.5.10.RELEASE 上测试)。
我对您创建 Bean Keycloak 的方式做了 1 处更改(我的代码来自官方 docs)。确保 realm
是 master
并且 client_id
是 admin-cli
。
@Bean
Keycloak initKeycloakWithAdminRole() {
return Keycloak.getInstance(
"http://localhost:8080/auth",
"master",
"admin",
"admin",
"admin-cli");
我的代码
服务
Code
控制器Code
依赖项here
我想通过 keycloak 管理客户端创建一个用户,但我得到:
java.lang.IllegalArgumentException: RESTEASY003720: path param realm has not been provided by the parameter map
这是我用于 keycloak 的 bean:
@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();
}
我使用此代码调用 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);
keycloak 和 keycloak 管理客户端都是相同的版本 (4.0.0.Final)
我的堆栈跟踪看起来像这样:
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.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69) at org.mycompany.usermanagement.service.KeycloakService.createUserInSSO(KeycloakService.java:45)
这是我的 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'
您是否正在使用 Spring 引导?
我已经为自己尝试了你的方案,对我来说效果很好(在 keycloak 4.0.0 和 Spring Boot 1.5.10.RELEASE 上测试)。
我对您创建 Bean Keycloak 的方式做了 1 处更改(我的代码来自官方 docs)。确保 realm
是 master
并且 client_id
是 admin-cli
。
@Bean
Keycloak initKeycloakWithAdminRole() {
return Keycloak.getInstance(
"http://localhost:8080/auth",
"master",
"admin",
"admin",
"admin-cli");
我的代码
服务 Code
控制器Code
依赖项here