diff --git a/docbook/reference/en/en-US/modules/export-import.xml b/docbook/reference/en/en-US/modules/export-import.xml
index 13da6cbc2d..492a84758b 100755
--- a/docbook/reference/en/en-US/modules/export-import.xml
+++ b/docbook/reference/en/en-US/modules/export-import.xml
@@ -12,6 +12,13 @@
Directory on local filesystem
Single JSON file on your filesystem
+
+ When importing using the "dir" or "zip" strategies, note that the files need to follow the naming convention specified below.
+ If you are importing files which were previously exported, the files already follow this convention.
+
+ {REALM_NAME}-realm.json, such as "acme-roadrunner-affairs-realm.json" for the realm named "acme-roadrunner-affairs"
+ {REALM_NAME}-users-{INDEX}.json, such as "acme-roadrunner-affairs-users-0.json" for the first users file of the realm named "acme-roadrunner-affairs"
+
Encrypted ZIP is recommended as export contains many sensitive informations like passwords of your users (even if they are hashed),
@@ -111,5 +118,14 @@ bin/standalone.sh -Dkeycloak.migration.action=import
+
+ When importing realm files that weren't exported before, the option keycloak.import can be used. If more than one realm
+ file needs to be imported, a comma separated list of file names can be specified. This is more appropriate than the cases before, as this
+ will happen only after the master realm has been initialized. Examples:
+
+ -Dkeycloak.import=/tmp/realm1.json
+ -Dkeycloak.import=/tmp/realm1.json,/tmp/realm2.json
+
+
\ No newline at end of file
diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
index a2d5a60d29..36679123f3 100755
--- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
+++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
@@ -194,15 +194,19 @@ public class KeycloakApplication extends Application {
}
public void importRealmFile() {
- String file = System.getProperty("keycloak.import");
- if (file != null) {
- RealmRepresentation rep = null;
- try {
- rep = loadJson(new FileInputStream(file), RealmRepresentation.class);
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
+ String files = System.getProperty("keycloak.import");
+ if (files != null) {
+ StringTokenizer tokenizer = new StringTokenizer(files, ",");
+ while (tokenizer.hasMoreTokens()) {
+ String file = tokenizer.nextToken().trim();
+ RealmRepresentation rep = null;
+ try {
+ rep = loadJson(new FileInputStream(file), RealmRepresentation.class);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ importRealm(rep, "file " + file);
}
- importRealm(rep, "file " + file);
}
}
@@ -223,11 +227,14 @@ public class KeycloakApplication extends Application {
return;
}
- RealmModel realm = manager.importRealm(rep);
-
- log.info("Imported realm " + realm.getName() + " from " + from);
-
- session.getTransaction().commit();
+ try {
+ RealmModel realm = manager.importRealm(rep);
+ session.getTransaction().commit();
+ log.info("Imported realm " + realm.getName() + " from " + from);
+ } catch (Throwable t) {
+ session.getTransaction().rollback();
+ log.warn("Unable to import realm " + rep.getRealm() + " from " + from + ". Cause: " + t.getMessage());
+ }
} finally {
session.close();
}