use of org.keycloak.provider.ProviderManager in project keycloak by keycloak.
the class FeatureDeployerUtil method deployFactoriesAfterFeatureEnabled.
public static void deployFactoriesAfterFeatureEnabled(Profile.Feature feature) {
ProviderManager manager = deployersCache.get(feature);
if (manager == null) {
// Need to figure which provider factories were enabled after feature was enabled. Create deployer based on it and save it to the cache
Map<ProviderFactory, Spi> factoriesBeforeEnable = initializer.remove(feature);
Map<ProviderFactory, Spi> factoriesAfterEnable = loadEnabledEnvironmentFactories();
Map<ProviderFactory, Spi> factories = getFactoriesDependentOnFeature(factoriesBeforeEnable, factoriesAfterEnable);
logger.infof("New factories when enabling feature '%s': %s", feature, factories.keySet());
KeycloakDeploymentInfo di = createDeploymentInfo(factories);
manager = new ProviderManager(di, FeatureDeployerUtil.class.getClassLoader());
deployersCache.put(feature, manager);
}
ProviderManagerRegistry.SINGLETON.deploy(manager);
}
use of org.keycloak.provider.ProviderManager in project keycloak by keycloak.
the class KeycloakProviderDeploymentProcessor method undeploy.
@Override
public void undeploy(DeploymentUnit context) {
ProviderManager pm = context.getAttachment(ATTACHMENT_KEY);
if (pm != null) {
logger.infov("Undeploying Keycloak provider: {0}", context.getName());
ProviderManagerRegistry.SINGLETON.undeploy(pm);
context.removeAttachment(ATTACHMENT_KEY);
}
}
use of org.keycloak.provider.ProviderManager in project keycloak by keycloak.
the class KeycloakModelTest method createKeycloakSessionFactory.
/**
* Creates a fresh initialized {@link KeycloakSessionFactory}. The returned factory uses configuration
* local to the thread that calls this method, allowing for per-thread customization. This in turn allows
* testing of several parallel session factories which can be used to simulate several servers
* running in parallel.
* @return
*/
public static KeycloakSessionFactory createKeycloakSessionFactory() {
int factoryIndex = FACTORY_COUNT.incrementAndGet();
String threadName = Thread.currentThread().getName();
CONFIG.reset();
CONFIG.spi(ComponentFactorySpi.NAME).provider(DefaultComponentFactoryProviderFactory.PROVIDER_ID).config("cachingForced", "true");
MODEL_PARAMETERS.forEach(m -> m.updateConfig(CONFIG));
LOG.debugf("Creating factory %d in %s using the following configuration:\n %s", factoryIndex, threadName, CONFIG);
DefaultKeycloakSessionFactory res = new DefaultKeycloakSessionFactory() {
@Override
protected boolean isEnabled(ProviderFactory factory, Scope scope) {
return super.isEnabled(factory, scope) && isFactoryAllowed(factory);
}
@Override
protected Map<Class<? extends Provider>, Map<String, ProviderFactory>> loadFactories(ProviderManager pm) {
spis.removeIf(s -> !isSpiAllowed(s));
return super.loadFactories(pm);
}
private boolean isSpiAllowed(Spi s) {
return MODEL_PARAMETERS.stream().anyMatch(p -> p.isSpiAllowed(s));
}
private boolean isFactoryAllowed(ProviderFactory factory) {
return MODEL_PARAMETERS.stream().anyMatch(p -> p.isFactoryAllowed(factory));
}
@Override
public String toString() {
return "KeycloakSessionFactory " + factoryIndex + " (from " + threadName + " thread)";
}
};
res.init();
res.publish(new PostMigrationEvent());
return res;
}
use of org.keycloak.provider.ProviderManager in project keycloak by keycloak.
the class KeycloakProviderDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
KeycloakAdapterConfigService config = KeycloakAdapterConfigService.INSTANCE;
String deploymentName = deploymentUnit.getName();
if (config.isKeycloakServerDeployment(deploymentName)) {
return;
}
KeycloakDeploymentInfo info = KeycloakProviderDependencyProcessor.getKeycloakProviderDeploymentInfo(deploymentUnit);
ScriptProviderDeploymentProcessor.deploy(deploymentUnit, info);
if (info.isProvider()) {
logger.infov("Deploying Keycloak provider: {0}", deploymentUnit.getName());
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
ProviderManager pm = new ProviderManager(info, module.getClassLoader());
ProviderManagerRegistry.SINGLETON.deploy(pm);
deploymentUnit.putAttachment(ATTACHMENT_KEY, pm);
}
}
use of org.keycloak.provider.ProviderManager in project keycloak by keycloak.
the class KeycloakProcessor method loadFactories.
private Map<Spi, Map<Class<? extends Provider>, Map<String, ProviderFactory>>> loadFactories(Map<String, ProviderFactory> preConfiguredProviders) {
Config.init(new MicroProfileConfigProvider());
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
KeycloakDeploymentInfo keycloakDeploymentInfo = KeycloakDeploymentInfo.create().name("classpath").services().themeResources();
ProviderManager pm = new ProviderManager(keycloakDeploymentInfo, classLoader);
Map<Spi, Map<Class<? extends Provider>, Map<String, ProviderFactory>>> factories = new HashMap<>();
for (Spi spi : pm.loadSpis()) {
Map<Class<? extends Provider>, Map<String, ProviderFactory>> providers = new HashMap<>();
List<ProviderFactory> loadedFactories = new ArrayList<>(pm.load(spi));
Map<String, ProviderFactory> deployedScriptProviders = loadDeployedScriptProviders(classLoader, spi);
loadedFactories.addAll(deployedScriptProviders.values());
preConfiguredProviders.putAll(deployedScriptProviders);
for (ProviderFactory factory : loadedFactories) {
if (IGNORED_PROVIDER_FACTORY.contains(factory.getClass())) {
continue;
}
Config.Scope scope = Config.scope(spi.getName(), factory.getId());
if (isEnabled(factory, scope)) {
if (spi.isInternal() && !isInternal(factory)) {
ServicesLogger.LOGGER.spiMayChange(factory.getId(), factory.getClass().getName(), spi.getName());
}
providers.computeIfAbsent(spi.getProviderClass(), aClass -> new HashMap<>()).put(factory.getId(), factory);
} else {
logger.debugv("SPI {0} provider {1} disabled", spi.getName(), factory.getId());
}
}
factories.put(spi, providers);
}
return factories;
}
Aggregations