Skip to content

Commit

Permalink
Add realm to session context when exporting to prevent NPE when vault…
Browse files Browse the repository at this point in the history
… is enabled. (keycloak#27911)

Closes keycloak#22617

Signed-off-by: Stefan Guilhen <[email protected]>
  • Loading branch information
sguilhen authored Mar 15, 2024
1 parent 9b967e3 commit 0e717f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void exportModel() {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
Stream<RealmRepresentation> realms = session.realms().getRealmsStream()
.peek(realm -> session.getContext().setRealm(realm))
.map(realm -> ExportUtils.exportRealm(session, realm, true, true));

writeToFile(realms);
Expand All @@ -88,6 +89,7 @@ private void exportRealm(final String realmName) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected void exportRealmImpl(final String realmName) {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
RealmModel realm = session.realms().getRealmByName(realmName);
session.getContext().setRealm(realm);
RealmRepresentation rep = ExportUtils.exportRealm(session, realm, exportUsersIntoRealmFile, true);
writeRealm(realmName + "-realm.json", rep);
logger.info("Realm '" + realmName + "' - data exported");
Expand Down Expand Up @@ -131,6 +132,7 @@ protected void runExportImportTask(KeycloakSession session) throws IOException {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
RealmModel realm = session.realms().getRealmByName(realmName);
session.getContext().setRealm(realm);
usersHolder.users = session.users()
.searchForUserStream(realm, Collections.emptyMap(), usersHolder.currentPageStart, usersHolder.currentPageEnd - usersHolder.currentPageStart)
.collect(Collectors.toList());
Expand Down Expand Up @@ -164,6 +166,7 @@ protected void runExportImportTask(KeycloakSession session) throws IOException {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
RealmModel realm = session.realms().getRealmByName(realmName);
session.getContext().setRealm(realm);
federatedUsersHolder.users = UserStorageUtil.userFederatedStorage(session)
.getStoredUsersStream(realm, federatedUsersHolder.currentPageStart, federatedUsersHolder.currentPageEnd - federatedUsersHolder.currentPageStart)
.collect(Collectors.toList());
Expand Down

0 comments on commit 0e717f7

Please sign in to comment.