Keycloak Import Realm “Create” From Java?

♀尐吖头ヾ 提交于 2019-12-12 03:26:17

问题


I've tried to import a realm from java application, but the server always return:

Exception in thread "main" javax.ws.rs.BadRequestException: HTTP 400 Bad Request
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:197)
at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:50)
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:64)
at com.sun.proxy.$Proxy20.create(Unknown Source)
at com.blulogix.core.rest.util.TestKeycloakToken.createRealm(TestKeycloakToken.java:59)
at com.blulogix.core.rest.util.TestKeycloakToken.main(TestKeycloakToken.java:38)

and this is my code:

     Keycloak kc = Keycloak.getInstance("http://localhost:8080/auth", "master", "admin", "admin", "security-admin-console");
     RealmRepresentation rr = new RealmRepresentation();
     rr.setId("TestRealm2");
     rr.setRealm("TestRealm2");
     rr.setEnabled(true);

Code for adding a new user to any realm are worked.

   kc.realm("master").users().create(user);

Please, Can anyone help me out with importing realm??


回答1:


You are not telling us which Keycloak version you are using. Assuming it is 1.7.0 or newer I suggest using "admin-cli" rather than "security-admin-console" to connect to Keycloak.

See the "Migrating to 1.7.0.CR1" section in the user guide http://www.keycloak.org/docs/latest/server_admin/topics/MigrationFromOlderVersions.html (on this page search for 1.7.0)




回答2:


Try to place the import for org.apache.httpcomponents version "4.3.6".



来源:https://stackoverflow.com/questions/36041604/keycloak-import-realm-create-from-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!