Search in sources :

Example 6 with Provider

use of org.keycloak.provider.Provider in project keycloak by keycloak.

the class DefaultKeycloakSessionFactory method loadFactories.

protected Map<Class<? extends Provider>, Map<String, ProviderFactory>> loadFactories(ProviderManager pm) {
    Map<Class<? extends Provider>, Map<String, ProviderFactory>> factoryMap = new HashMap<>();
    Set<Spi> spiList = spis;
    for (Spi spi : spiList) {
        Map<String, ProviderFactory> factories = new HashMap<String, ProviderFactory>();
        factoryMap.put(spi.getProviderClass(), factories);
        String provider = Config.getProvider(spi.getName());
        if (provider != null) {
            ProviderFactory factory = pm.load(spi, provider);
            if (factory == null) {
                continue;
            }
            Config.Scope scope = Config.scope(spi.getName(), provider);
            if (isEnabled(factory, scope)) {
                factory.init(scope);
                if (spi.isInternal() && !isInternal(factory)) {
                    ServicesLogger.LOGGER.spiMayChange(factory.getId(), factory.getClass().getName(), spi.getName());
                }
                factories.put(factory.getId(), factory);
                logger.debugv("Loaded SPI {0} (provider = {1})", spi.getName(), provider);
            }
        } else {
            for (ProviderFactory factory : pm.load(spi)) {
                Config.Scope scope = Config.scope(spi.getName(), factory.getId());
                if (isEnabled(factory, scope)) {
                    factory.init(scope);
                    if (spi.isInternal() && !isInternal(factory)) {
                        ServicesLogger.LOGGER.spiMayChange(factory.getId(), factory.getClass().getName(), spi.getName());
                    }
                    factories.put(factory.getId(), factory);
                } else {
                    logger.debugv("SPI {0} provider {1} disabled", spi.getName(), factory.getId());
                }
            }
        }
    }
    return factoryMap;
}
Also used : HashMap(java.util.HashMap) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) Config(org.keycloak.Config) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) Spi(org.keycloak.provider.Spi) ComponentFactoryProvider(org.keycloak.component.ComponentFactoryProvider) Provider(org.keycloak.provider.Provider)

Example 7 with Provider

use of org.keycloak.provider.Provider in project keycloak by keycloak.

the class DefaultKeycloakSessionFactory method undeploy.

@Override
public void undeploy(ProviderManager pm) {
    logger.debug("undeploy");
    // we make a copy to avoid concurrent access exceptions
    Map<Class<? extends Provider>, Map<String, ProviderFactory>> copy = getFactoriesCopy();
    MultivaluedHashMap<Class<? extends Provider>, ProviderFactory> factories = pm.getLoadedFactories();
    List<ProviderFactory> undeployed = new LinkedList<>();
    for (Map.Entry<Class<? extends Provider>, List<ProviderFactory>> entry : factories.entrySet()) {
        Map<String, ProviderFactory> registered = copy.get(entry.getKey());
        for (ProviderFactory factory : entry.getValue()) {
            undeployed.add(factory);
            logger.debugv("undeploying {0} of id {1}", factory.getClass().getName(), factory.getId());
            if (registered != null) {
                registered.remove(factory.getId());
            }
        }
    }
    factoriesMap = copy;
    for (ProviderFactory factory : undeployed) {
        factory.close();
    }
}
Also used : EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) LinkedList(java.util.LinkedList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LinkedList(java.util.LinkedList) ComponentFactoryProvider(org.keycloak.component.ComponentFactoryProvider) Provider(org.keycloak.provider.Provider)

Example 8 with Provider

use of org.keycloak.provider.Provider in project keycloak by keycloak.

the class DefaultKeycloakSessionFactory method init.

public void init() {
    serverStartupTimestamp = System.currentTimeMillis();
    ProviderManager pm = new ProviderManager(KeycloakDeploymentInfo.create().services(), getClass().getClassLoader(), Config.scope().getArray("providers"));
    for (Spi spi : pm.loadSpis()) {
        if (spi.isEnabled()) {
            spis.add(spi);
        }
    }
    factoriesMap = loadFactories(pm);
    synchronized (ProviderManagerRegistry.SINGLETON) {
        for (ProviderManager manager : ProviderManagerRegistry.SINGLETON.getPreBoot()) {
            Map<Class<? extends Provider>, Map<String, ProviderFactory>> factoryMap = loadFactories(manager);
            for (Map.Entry<Class<? extends Provider>, Map<String, ProviderFactory>> entry : factoryMap.entrySet()) {
                Map<String, ProviderFactory> factories = factoriesMap.get(entry.getKey());
                if (factories == null) {
                    factoriesMap.put(entry.getKey(), entry.getValue());
                } else {
                    factories.putAll(entry.getValue());
                }
            }
        }
        checkProvider();
        // Component factory must be initialized first, so that postInit in other factories can use component factories
        updateComponentFactoryProviderFactory();
        if (componentFactoryPF != null) {
            componentFactoryPF.postInit(this);
        }
        for (Map<String, ProviderFactory> factories : factoriesMap.values()) {
            for (ProviderFactory factory : factories.values()) {
                if (factory != componentFactoryPF) {
                    factory.postInit(this);
                }
            }
        }
        // make the session factory ready for hot deployment
        ProviderManagerRegistry.SINGLETON.setDeployer(this);
    }
    AdminPermissions.registerListener(this);
}
Also used : ProviderManager(org.keycloak.provider.ProviderManager) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) Spi(org.keycloak.provider.Spi) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentFactoryProvider(org.keycloak.component.ComponentFactoryProvider) Provider(org.keycloak.provider.Provider)

Aggregations

Provider (org.keycloak.provider.Provider)8 ProviderFactory (org.keycloak.provider.ProviderFactory)8 Map (java.util.Map)7 HashMap (java.util.HashMap)6 ComponentFactoryProviderFactory (org.keycloak.component.ComponentFactoryProviderFactory)6 EnvironmentDependentProviderFactory (org.keycloak.provider.EnvironmentDependentProviderFactory)6 Spi (org.keycloak.provider.Spi)5 Config (org.keycloak.Config)4 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)4 ComponentFactoryProvider (org.keycloak.component.ComponentFactoryProvider)4 ProviderManager (org.keycloak.provider.ProviderManager)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 List (java.util.List)3 Function (java.util.function.Function)3 Logger (org.jboss.logging.Logger)3 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)2 DevServicesDatasourceResultBuildItem (io.quarkus.datasource.deployment.spi.DevServicesDatasourceResultBuildItem)2 IsDevelopment (io.quarkus.deployment.IsDevelopment)2 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)2