I have managed to workaround this issue by simply using separate import commands on a
running container instead of running the container with the import parameter:
docker exec -it keycloak /opt/jboss/keycloak/bin/standalone.sh
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=import
-Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=/tmp/vol/tenant1.json
-Dkeycloak.migration.strategy=OVERWRITE_EXISTING
docker exec -it keycloak /opt/jboss/keycloak/bin/standalone.sh
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=import
-Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=/tmp/vol/tenant2.json
-Dkeycloak.migration.strategy=OVERWRITE_EXISTING
Ori.
________________________________
From: keycloak-user-bounces(a)lists.jboss.org <keycloak-user-bounces(a)lists.jboss.org>
on behalf of Ori Doolman <Ori.Doolman(a)cyberark.com>
Sent: Tuesday, November 12, 2019 1:28 PM
To: keycloak-user(a)lists.jboss.org <keycloak-user(a)lists.jboss.org>
Subject: [keycloak-user] export/import realms - illegal json format?
Hi,
I'm using Keycloak docker 7.01 to export all my realms into a json file realms.json.
Then, I take the json file and try to import in another container.
The json looks like:
[ {
"id" : "tenant1",
"realm" : "tenant1",
....
},
{
"id" : "tenant2",
"realm" : "tenant2",
....
} ]
However, after I run the import, I get an error about the json format. I checked the json
with an online validator, and it seems to be valid.
Is that a bug? Is there any way to reformat the json so it will work?
When I export/import a single tenant, I don't get the error.
Here is my export command:
docker exec keycloak /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/vol/realms.json
Here is my import command:
sudo docker run -d -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e
KEYCLOAK_IMPORT=/tmp/vol/realms.json -v /home/caadmin/keycloak:/tmp/vol --name keycloak
jboss/keycloak
This is the error I get:
... 8 more
Caused by: java.lang.RuntimeException: Failed to parse json
at
org.keycloak.keycloak-services@7.0.1//org.keycloak.services.resources.KeycloakApplication.loadJson(KeycloakApplication.java:476)
at
org.keycloak.keycloak-services@7.0.1//org.keycloak.services.resources.KeycloakApplication.importRealms(KeycloakApplication.java:368)
at
org.keycloak.keycloak-services@7.0.1//org.keycloak.services.resources.KeycloakApplication.migrateAndBootstrap(KeycloakApplication.java:233)
at
org.keycloak.keycloak-services@7.0.1//org.keycloak.services.resources.KeycloakApplication$1.run(KeycloakApplication.java:146)
at
org.keycloak.keycloak-server-spi-private@7.0.1//org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:227)
at
org.keycloak.keycloak-services@7.0.1//org.keycloak.services.resources.KeycloakApplication.<init>(KeycloakApplication.java:137)
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at
org.jboss.resteasy.resteasy-jaxrs@3.7.0.Final//org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:152)
... 31 more
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize
instance of `org.keycloak.representations.idm.RealmRepresentation` out of START_ARRAY
token
at [Source: (FileInputStream); line: 1, column: 1]
----------------------------------------------------------------------
_______________________________________________
This e-mail may contain information that is confidential, privileged or otherwise
protected from disclosure.
If you are not an intended recipient of this e-mail, do not duplicate or redistribute it
by any means. Please delete it and any attachments and notify the sender that you have
received it in error.
_______________________________________________
keycloak-user mailing list
keycloak-user(a)lists.jboss.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.jboss.org_mail...