问题
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