diff --git a/docbook/reference/en/en-US/modules/export-import.xml b/docbook/reference/en/en-US/modules/export-import.xml
index 13da6cb..492a847 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 @@
<listitem>Directory on local filesystem</listitem>
<listitem>Single JSON file on your filesystem</listitem>
</itemizedlist>
+
+ 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.
+ <itemizedlist>
+ <listitem>{REALM_NAME}-realm.json, such as "acme-roadrunner-affairs-realm.json" for the realm named "acme-roadrunner-affairs"</listitem>
+ <listitem>{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"</listitem>
+ </itemizedlist>
</para>
<para>
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
</varlistentry>
</variablelist>
</para>
+ <para>
+ When importing realm files that weren't exported before, the option <literal>keycloak.import</literal> 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:
+ <itemizedlist>
+ <listitem>-Dkeycloak.import=/tmp/realm1.json</listitem>
+ <listitem>-Dkeycloak.import=/tmp/realm1.json,/tmp/realm2.json</listitem>
+ </itemizedlist>
+ </para>
</chapter>
\ 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 a2d5a60..3667912 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();
}