KEYCLOAK-2549 Re-create master admin client if master realm is overwritten on import
This commit is contained in:
parent
8799405673
commit
1cc4cc30a6
2 changed files with 17 additions and 2 deletions
|
@ -33,6 +33,7 @@ import org.keycloak.models.utils.RealmImporter;
|
|||
import org.keycloak.models.utils.RepresentationToModel;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -46,10 +47,14 @@ public class ImportUtils {
|
|||
private static final Logger logger = Logger.getLogger(ImportUtils.class);
|
||||
|
||||
public static void importRealms(KeycloakSession session, Collection<RealmRepresentation> realms, Strategy strategy) {
|
||||
boolean masterImported = false;
|
||||
|
||||
// Import admin realm first
|
||||
for (RealmRepresentation realm : realms) {
|
||||
if (Config.getAdminRealm().equals(realm.getRealm())) {
|
||||
importRealm(session, realm, strategy);
|
||||
if (importRealm(session, realm, strategy)) {
|
||||
masterImported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +63,16 @@ public class ImportUtils {
|
|||
importRealm(session, realm, strategy);
|
||||
}
|
||||
}
|
||||
|
||||
// If master was imported, we may need to re-create realm management clients
|
||||
if (masterImported) {
|
||||
for (RealmModel realm : session.realms().getRealms()) {
|
||||
if (realm.getMasterAdminClient() == null) {
|
||||
logger.infof("Re-created management client in master realm for realm '%s'", realm.getName());
|
||||
new RealmManager(session).setupMasterAdminManagement(realm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -267,7 +267,7 @@ public class RealmManager implements RealmImporter {
|
|||
}
|
||||
|
||||
|
||||
private void setupMasterAdminManagement(RealmModel realm) {
|
||||
public void setupMasterAdminManagement(RealmModel realm) {
|
||||
// Need to refresh masterApp for current realm
|
||||
String adminRealmId = Config.getAdminRealm();
|
||||
RealmModel adminRealm = model.getRealm(adminRealmId);
|
||||
|
|
Loading…
Reference in a new issue