Skip to content

Commit

Permalink
Fix errors when importing realms with the organization feature enabled
Browse files Browse the repository at this point in the history
Closes #29630

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
  • Loading branch information
sguilhen authored and pedroigor committed May 17, 2024
1 parent 74a8099 commit 1aab371
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void runExportImportTask(KeycloakSession session) {
KeycloakModelUtils.runJobInTransaction(factory, new ExportImportSessionTask() {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
session.getContext().setRealm(session.realms().getRealmByName(realmName));
ImportUtils.importUsersFromStream(session, realmName, JsonSerialization.mapper, fis);
logger.infof("Imported users from %s", userFile.getAbsolutePath());
}
Expand All @@ -168,6 +169,7 @@ protected void runExportImportTask(KeycloakSession session) throws IOException {
KeycloakModelUtils.runJobInTransaction(factory, new ExportImportSessionTask() {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
session.getContext().setRealm(session.realms().getRealmByName(realmName));
ImportUtils.importFederatedUsersFromStream(session, realmName, JsonSerialization.mapper, fis);
logger.infof("Imported federated users from %s", userFile.getAbsolutePath());
}
Expand All @@ -182,6 +184,7 @@ protected void runExportImportTask(KeycloakSession session) throws IOException {

@Override
public void runExportImportTask(KeycloakSession session) {
session.getContext().setRealm(session.realms().getRealmByName(realmName));
RealmManager realmManager = new RealmManager(session);
realmManager.setupClientServiceAccountsAndAuthorizationOnImport(realmRep, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static boolean importRealm(KeycloakSession session, RealmRepresentation r
RealmModel realm = model.getRealmByName(realmName);

if (realm != null) {
session.getContext().setRealm(realm);
if (strategy == Strategy.IGNORE_EXISTING) {
logger.infof("Realm '%s' already exists. Import skipped", realmName);
return false;
Expand All @@ -105,6 +106,7 @@ public static boolean importRealm(KeycloakSession session, RealmRepresentation r
// TODO: For migration between versions, it should be possible to delete just realm but keep it's users
model.removeRealm(realm.getId());
}
session.getContext().setRealm(null);
}

RealmManager realmManager = new RealmManager(session);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.testsuite.organization.admin;

import org.keycloak.common.Profile;
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.exportimport.ExportImportTest;

/**
* Tests the export/import functionality with the organization feature enabled.
*
* NOTE: When export/import of organizations is implemented and the organization feature is supported, we should either enhance
* this class or the existing ExportImportTest to check org-specific settings.
*
* @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
*/
@EnableFeature(Profile.Feature.ORGANIZATION)
public class OrganizationEnabledExportImportTest extends ExportImportTest {
}

0 comments on commit 1aab371

Please sign in to comment.