Search in sources :

Example 1 with Strategy

use of org.keycloak.exportimport.Strategy in project keycloak by keycloak.

the class ImportUtils method importRealms.

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())) {
            if (importRealm(session, realm, strategy, false)) {
                masterImported = true;
            }
        }
    }
    for (RealmRepresentation realm : realms) {
        if (!Config.getAdminRealm().equals(realm.getRealm())) {
            importRealm(session, realm, strategy, false);
        }
    }
    // If master was imported, we may need to re-create realm management clients
    if (masterImported) {
        session.realms().getRealmsStream().filter(realm -> realm.getMasterAdminClient() == null).forEach(realm -> {
            logger.infof("Re-created management client in master realm for realm '%s'", realm.getName());
            new RealmManager(session).setupMasterAdminManagement(realm);
        });
    }
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) JsonParser(com.fasterxml.jackson.core.JsonParser) RealmManager(org.keycloak.services.managers.RealmManager) Logger(org.jboss.logging.Logger) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KeycloakSession(org.keycloak.models.KeycloakSession) IOException(java.io.IOException) HashMap(java.util.HashMap) Config(org.keycloak.Config) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) RepresentationToModel(org.keycloak.models.utils.RepresentationToModel) ArrayList(java.util.ArrayList) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ExportImportConfig(org.keycloak.exportimport.ExportImportConfig) Strategy(org.keycloak.exportimport.Strategy) RealmProvider(org.keycloak.models.RealmProvider) Map(java.util.Map) JsonToken(com.fasterxml.jackson.core.JsonToken) InputStream(java.io.InputStream) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) RealmManager(org.keycloak.services.managers.RealmManager)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Logger (org.jboss.logging.Logger)1 Config (org.keycloak.Config)1 ExportImportConfig (org.keycloak.exportimport.ExportImportConfig)1 Strategy (org.keycloak.exportimport.Strategy)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 RealmModel (org.keycloak.models.RealmModel)1 RealmProvider (org.keycloak.models.RealmProvider)1 RepresentationToModel (org.keycloak.models.utils.RepresentationToModel)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1