由于"未知资源"由keycloak-admin-client将用户添加到Keycloak失败

时间:2016-07-12 04:41:27

标签: java client admin keycloak

我尝试在下面的Java代码中使用keycloak-admin-client,然后我得到了例外。从例外情况来看,即使在到达Keycloak之前,它似乎也无法构建API URL。有人知道为什么会这样吗?

我在Docker容器中运行Keycloak并暴露了端口8078.

public static void main(String ... args) {
        Keycloak kc = KeycloakBuilder.builder()
                .serverUrl("http://localhost:8078/auth")
                .realm("master")
                .username("admin")
                .password("admin")
                .clientId("admin-cli")
                .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())
                .build();
        CredentialRepresentation credential = new CredentialRepresentation();
        credential.setType(CredentialRepresentation.PASSWORD);
        credential.setValue("test123");
        UserRepresentation user = new UserRepresentation();
        user.setUsername("testuser");
        user.setFirstName("Test");
        user.setLastName("User");
        user.setEnabled(true);
        user.setCredentials(Arrays.asList(credential));
        kc.realm("master").users().create(user);
}

例外:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
    at java.lang.Thread.run(Thread.java:745)
Caused by: 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:158)
    at org.jboss.resteasy.client.jaxrs.internal.proxy.SubResourceInvoker.invoke(SubResourceInvoker.java:65)
    at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
    at com.sun.proxy.$Proxy39.realm(Unknown Source)
    at org.keycloak.admin.client.Keycloak.realm(Keycloak.java:71)
    at com.gallagher.security.keycloak.client.Program.main(Program.java:76)

1 个答案:

答案 0 :(得分:2)

Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplates(Ljava/util/Map;)Ljavax/ws/rs/core/UriBuilder;    

此错误通常表示您在路径上有2个版本的类 如果您使用像Maven这样的依赖框架,则可以验证heirarchy中是否包含了正确的库 这个类 - “javax.ws.rs.core.UriBuilder”