diff --git a/model/storage-services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java b/model/storage-services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java index ee9a037e1f..6ad575fe66 100755 --- a/model/storage-services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java +++ b/model/storage-services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java @@ -71,6 +71,7 @@ public class SingleFileExportProvider implements ExportProvider { @Override protected void runExportImportTask(KeycloakSession session) throws IOException { Stream realms = session.realms().getRealmsStream() + .peek(realm -> session.getContext().setRealm(realm)) .map(realm -> ExportUtils.exportRealm(session, realm, true, true)); writeToFile(realms); @@ -88,6 +89,7 @@ public class SingleFileExportProvider implements ExportProvider { protected void runExportImportTask(KeycloakSession session) throws IOException { RealmModel realm = session.realms().getRealmByName(realmName); Objects.requireNonNull(realm, "realm not found by realm name '" + realmName + "'"); + session.getContext().setRealm(realm); RealmRepresentation realmRep = ExportUtils.exportRealm(session, realm, true, true); writeToFile(realmRep); } diff --git a/model/storage-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java b/model/storage-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java index 270dcb710a..8802d3ac55 100755 --- a/model/storage-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java +++ b/model/storage-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java @@ -95,6 +95,7 @@ public abstract class MultipleStepsExportProvider