From ad497a66cd9626e87c31488ef9d78912e260ed22 Mon Sep 17 00:00:00 2001 From: William DeCoste Date: Sat, 29 Aug 2015 08:57:04 -0700 Subject: [PATCH] KEYCLOAK-1783 --- .../exportimport/ExportImportManager.java | 44 +++++++++++-------- .../services/DefaultKeycloakSession.java | 5 +++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/services/src/main/java/org/keycloak/exportimport/ExportImportManager.java b/services/src/main/java/org/keycloak/exportimport/ExportImportManager.java index c42077a5dd..540ef2c3d7 100644 --- a/services/src/main/java/org/keycloak/exportimport/ExportImportManager.java +++ b/services/src/main/java/org/keycloak/exportimport/ExportImportManager.java @@ -45,27 +45,33 @@ public class ExportImportManager { logger.info("Export finished successfully"); } else { ImportProvider importProvider = session.getProvider(ImportProvider.class, exportImportProviderId); - Strategy strategy = ExportImportConfig.getStrategy(); - if (realmName == null) { - logger.infof("Full model import requested. Strategy: %s", strategy.toString()); - - // Check if master realm was exported. If it's not, then it needs to be created before other realms are imported - if (!importProvider.isMasterRealmExported()) { - new ApplianceBootstrap().bootstrap(sessionFactory, contextPath); - } - - importProvider.importModel(sessionFactory, strategy); + + if (importProvider == null) { + logger.errorf("Invalid Import Provider %s", exportImportProviderId); } else { - logger.infof("Import of realm '%s' requested. Strategy: %s", realmName, strategy.toString()); - - if (!realmName.equals(Config.getAdminRealm())) { - // Check if master realm exists. If it's not, then it needs to be created before other realm is imported - new ApplianceBootstrap().bootstrap(sessionFactory, contextPath); - } - - importProvider.importRealm(sessionFactory, realmName, strategy); + + Strategy strategy = ExportImportConfig.getStrategy(); + if (realmName == null) { + logger.infof("Full model import requested. Strategy: %s", strategy.toString()); + + // Check if master realm was exported. If it's not, then it needs to be created before other realms are imported + if (!importProvider.isMasterRealmExported()) { + new ApplianceBootstrap().bootstrap(sessionFactory, contextPath); + } + + importProvider.importModel(sessionFactory, strategy); + } else { + logger.infof("Import of realm '%s' requested. Strategy: %s", realmName, strategy.toString()); + + if (!realmName.equals(Config.getAdminRealm())) { + // Check if master realm exists. If it's not, then it needs to be created before other realm is imported + new ApplianceBootstrap().bootstrap(sessionFactory, contextPath); + } + + importProvider.importRealm(sessionFactory, realmName, strategy); + } + logger.info("Import finished successfully"); } - logger.info("Import finished successfully"); } } catch (Throwable ioe) { logger.error("Error during export/import", ioe); diff --git a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java index fc06d93af1..8588a53939 100755 --- a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java +++ b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java @@ -1,5 +1,6 @@ package org.keycloak.services; +import org.jboss.logging.Logger; import org.jboss.resteasy.spi.HttpRequest; import org.jboss.resteasy.spi.ResteasyProviderFactory; import org.keycloak.models.KeycloakContext; @@ -16,6 +17,7 @@ import org.keycloak.provider.Provider; import org.keycloak.provider.ProviderFactory; import javax.ws.rs.core.UriInfo; + import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -37,6 +39,8 @@ public class DefaultKeycloakSession implements KeycloakSession { private UserSessionProvider sessionProvider; private UserFederationManager federationManager; private KeycloakContext context; + + private static final Logger logger = Logger.getLogger(DefaultKeycloakSession.class); public DefaultKeycloakSession(DefaultKeycloakSessionFactory factory) { this.factory = factory; @@ -108,6 +112,7 @@ public class DefaultKeycloakSession implements KeycloakSession { T provider = (T) providers.get(hash); if (provider == null) { ProviderFactory providerFactory = factory.getProviderFactory(clazz, id); + if (providerFactory != null) { provider = providerFactory.create(this); providers.put(hash, provider);