简体   繁体   English

如何使用管理客户端访问密钥斗篷?

[英]How to access keycloak with the admin-client?

I'm trying to change roles of a user in keycloak with the keycloak-admin-client in a spring boot application, but I can't even instanciate keycloak. 我正在尝试使用Spring Boot应用程序中的keycloak-admin-client更改keycloak中用户的角色,但是我什至无法实例化keycloak。

I'm trying to get the keycloak server here, but Im getting a InstantiationError 我正在尝试在这里获取密钥斗篷服务器,但是我收到了InstantiationError

    String serverUrl = "http://localhost:8080/auth";
    String realm = "User-Service-Realm";
    String clientId = "admin-cli";

    Keycloak keycloak = Keycloak.getInstance(
      serverUrl,
      realm,
      "admin",
      "admin",
      clientId);
Exception in thread "main" java.lang.InstantiationError: org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder
    at org.keycloak.admin.client.Keycloak.<init>(Keycloak.java:58)
    at org.keycloak.admin.client.Keycloak.getInstance(Keycloak.java:106)
    at de.uni.stuttgart.isw.ccm.userservice.api.KeycloakAdminClientExample.main(KeycloakAdminClientExample.java:31)

Apparently its a problem with the admin-client itself, since the keycloak builder is based on the resteasyclientbuilder. 显然,这是管理客户端本身的问题,因为密钥斗篷构建器基于resteasyclientbuilder。

You seem to have incompatible libraries or library versions. 您似乎具有不兼容的库或库版本。 The error message complains that ResteasyClientBuilder is abstract. 该错误消息抱怨ResteasyClientBuilder是抽象的。 That not the case in our working project. 在我们的工作项目中情况并非如此。

So as a reference, here is an extract from our gradle file so you can see a working combination of library versions: 因此,作为参考,以下是我们的gradle文件的摘录,因此您可以看到库版本的有效组合:

implementation 'org.keycloak:keycloak-admin-client:6.0.1'
implementation 'javax.ws.rs:javax.ws.rs-api:2.0'
implementation 'org.jboss.resteasy:resteasy-jaxrs:3.6.3.Final'
implementation 'org.jboss.resteasy:resteasy-client:3.6.3.Final'
implementation 'org.jboss.resteasy:resteasy-jackson2-provider:3.6.3.Final'

Update : 更新

ResteasyClientBuilder has become an abstract class with version 4.0 of RESTEasy . ResteasyClientBuilder已成为RESTEasy版本4.0的抽象类。 So it looks as if you are using version 4.x, while Keycloak expects 3.x. 因此,似乎您使用的是4.x版本,而Keycloak希望使用的是3.x版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM