From 0e717f735e1b17d2ef10fa7b4764b1dc495d4746 Mon Sep 17 00:00:00 2001 From: Stefan Guilhen Date: Fri, 15 Mar 2024 08:24:22 -0300 Subject: [PATCH] Add realm to session context when exporting to prevent NPE when vault is enabled. (#27911) Closes #22617 Signed-off-by: Stefan Guilhen --- .../exportimport/singlefile/SingleFileExportProvider.java | 2 ++ .../exportimport/util/MultipleStepsExportProvider.java | 3 +++ 2 files changed, 5 insertions(+) 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