Search in sources :

Example 1 with Provider

use of org.keycloak.provider.Provider 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;
}
Also used : DefaultKeycloakSessionFactory(org.keycloak.services.DefaultKeycloakSessionFactory) Scope(org.keycloak.Config.Scope) DefaultExecutorsProviderFactory(org.keycloak.executors.DefaultExecutorsProviderFactory) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) DefaultAuthorizationProviderFactory(org.keycloak.authorization.DefaultAuthorizationProviderFactory) DefaultComponentFactoryProviderFactory(org.keycloak.services.DefaultComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) DeploymentStateProviderFactory(org.keycloak.models.DeploymentStateProviderFactory) ProviderManager(org.keycloak.provider.ProviderManager) BeforeClass(org.junit.BeforeClass) Map(java.util.Map) ComponentFactorySpi(org.keycloak.component.ComponentFactorySpi) ClientScopeSpi(org.keycloak.models.ClientScopeSpi) ExecutorsSpi(org.keycloak.executors.ExecutorsSpi) DBLockSpi(org.keycloak.models.dblock.DBLockSpi) ClusterSpi(org.keycloak.cluster.ClusterSpi) UserSpi(org.keycloak.models.UserSpi) Spi(org.keycloak.provider.Spi) UserLoginFailureSpi(org.keycloak.models.UserLoginFailureSpi) TimerSpi(org.keycloak.timer.TimerSpi) ClientSpi(org.keycloak.models.ClientSpi) StoreFactorySpi(org.keycloak.authorization.store.StoreFactorySpi) RealmSpi(org.keycloak.models.RealmSpi) GroupSpi(org.keycloak.models.GroupSpi) UserSessionSpi(org.keycloak.models.UserSessionSpi) DeploymentStateSpi(org.keycloak.models.DeploymentStateSpi) EventStoreSpi(org.keycloak.events.EventStoreSpi) AuthorizationSpi(org.keycloak.authorization.AuthorizationSpi) RoleSpi(org.keycloak.models.RoleSpi) Provider(org.keycloak.provider.Provider) PostMigrationEvent(org.keycloak.models.utils.PostMigrationEvent)

Example 2 with Provider

use of org.keycloak.provider.Provider 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;
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) ScriptProviderMetadata(org.keycloak.representations.provider.ScriptProviderMetadata) QUERY_PROPERTY_PREFIX(org.keycloak.quarkus.runtime.storage.database.jpa.QuarkusJpaConnectionProviderFactory.QUERY_PROPERTY_PREFIX) NS_QUARKUS(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_QUARKUS) KeycloakConfigSourceProvider(org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider) DeployedScriptAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.DeployedScriptAuthenticatorFactory) PersistenceXmlDescriptorBuildItem(io.quarkus.hibernate.orm.deployment.PersistenceXmlDescriptorBuildItem) ResteasyDeploymentCustomizerBuildItem(io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem) Map(java.util.Map) Spi(org.keycloak.provider.Spi) Entity(javax.persistence.Entity) Consume(io.quarkus.deployment.annotations.Consume) AuthenticatorSpi(org.keycloak.authentication.AuthenticatorSpi) ProtocolMapperSpi(org.keycloak.protocol.ProtocolMapperSpi) StandardCharsets(java.nio.charset.StandardCharsets) FolderThemeProviderFactory(org.keycloak.theme.FolderThemeProviderFactory) ResteasyContextParameters(org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FilterBuildItem(io.quarkus.vertx.http.deployment.FilterBuildItem) RequestHostnameProviderFactory(org.keycloak.url.RequestHostnameProviderFactory) SmallRyeHealthHandler(io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler) Environment.getProviderFiles(org.keycloak.quarkus.runtime.Environment.getProviderFiles) PersistedConfigSource(org.keycloak.quarkus.runtime.configuration.PersistedConfigSource) DefaultJpaConnectionProviderFactory(org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory) Record(io.quarkus.deployment.annotations.Record) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AvailableSettings(org.hibernate.cfg.AvailableSettings) JBossJtaTransactionManagerLookup(org.keycloak.transaction.JBossJtaTransactionManagerLookup) DotName(org.jboss.jandex.DotName) FilesPlainTextVaultProviderFactory(org.keycloak.vault.FilesPlainTextVaultProviderFactory) AUTHENTICATORS(org.keycloak.representations.provider.ScriptProviderDescriptor.AUTHENTICATORS) DevServicesDatasourceResultBuildItem(io.quarkus.datasource.deployment.spi.DevServicesDatasourceResultBuildItem) ArrayList(java.util.ArrayList) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) AdditionalJpaModelBuildItem(io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem) HibernateOrmConfig(io.quarkus.hibernate.orm.deployment.HibernateOrmConfig) PropertyMappers(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers) ProviderFactory(org.keycloak.provider.ProviderFactory) Configuration.getPropertyNames(org.keycloak.quarkus.runtime.configuration.Configuration.getPropertyNames) Environment(org.keycloak.quarkus.runtime.Environment) Properties(java.util.Properties) IOException(java.io.IOException) File(java.io.File) FixedHostnameProviderFactory(org.keycloak.url.FixedHostnameProviderFactory) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) QuarkusDevRequestFilter(org.keycloak.quarkus.runtime.dev.QuarkusDevRequestFilter) QuarkusPropertiesConfigSource(org.keycloak.quarkus.runtime.configuration.QuarkusPropertiesConfigSource) URL(java.net.URL) JarFile(java.util.jar.JarFile) NonApplicationRootPathBuildItem(io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem) ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) Configuration(org.keycloak.quarkus.runtime.configuration.Configuration) RoutingContext(io.vertx.ext.web.RoutingContext) Config(org.keycloak.Config) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) QUARKUS_PROPERTY_ENABLED(org.keycloak.quarkus.runtime.configuration.QuarkusPropertiesConfigSource.QUARKUS_PROPERTY_ENABLED) DeployedScriptOIDCProtocolMapper(org.keycloak.protocol.oidc.mappers.DeployedScriptOIDCProtocolMapper) AnnotationTarget(org.jboss.jandex.AnnotationTarget) ProviderManager(org.keycloak.provider.ProviderManager) DefaultHostnameProviderFactory(org.keycloak.url.DefaultHostnameProviderFactory) PolicySpi(org.keycloak.authorization.policy.provider.PolicySpi) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) JpaUtils.loadSpecificNamedQueries(org.keycloak.connections.jpa.util.JpaUtils.loadSpecificNamedQueries) ConfigValue(io.smallrye.config.ConfigValue) List(java.util.List) Provider(org.keycloak.provider.Provider) Entry(java.util.Map.Entry) Optional(java.util.Optional) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) QuarkusKeycloakApplication(org.keycloak.quarkus.runtime.integration.jaxrs.QuarkusKeycloakApplication) StaticInitConfigSourceProviderBuildItem(io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem) KeycloakDeploymentInfo(org.keycloak.provider.KeycloakDeploymentInfo) RouteBuildItem(io.quarkus.vertx.http.deployment.RouteBuildItem) Profile(org.keycloak.common.Profile) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) HotDeploymentWatchedFileBuildItem(io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem) QuarkusProfile(org.keycloak.quarkus.runtime.QuarkusProfile) Logger(org.jboss.logging.Logger) MicroProfileConfigProvider(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) ServicesLogger(org.keycloak.services.ServicesLogger) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) Function(java.util.function.Function) IsDevelopment(io.quarkus.deployment.IsDevelopment) JarEntry(java.util.jar.JarEntry) KeycloakRecorder(org.keycloak.quarkus.runtime.KeycloakRecorder) BuildStep(io.quarkus.deployment.annotations.BuildStep) DefaultLiquibaseConnectionProvider(org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider) StreamUtil(org.keycloak.common.util.StreamUtil) POLICIES(org.keycloak.representations.provider.ScriptProviderDescriptor.POLICIES) RuntimeConfigSetupCompleteBuildItem(io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem) LiquibaseJpaUpdaterProviderFactory(org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProviderFactory) IndexView(org.jboss.jandex.IndexView) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) QuarkusRequestFilter(org.keycloak.quarkus.runtime.integration.web.QuarkusRequestFilter) PersistenceUnitTransactionType(javax.persistence.spi.PersistenceUnitTransactionType) Consumer(java.util.function.Consumer) JsonSerialization(org.keycloak.util.JsonSerialization) DeployedScriptPolicyFactory(org.keycloak.authorization.policy.provider.js.DeployedScriptPolicyFactory) MAPPERS(org.keycloak.representations.provider.ScriptProviderDescriptor.MAPPERS) JdbcDataSourceBuildItem(io.quarkus.agroal.spi.JdbcDataSourceBuildItem) NotFoundHandler(org.keycloak.quarkus.runtime.integration.web.NotFoundHandler) ProfileManager(io.quarkus.runtime.configuration.ProfileManager) Comparator(java.util.Comparator) Handler(io.vertx.core.Handler) InputStream(java.io.InputStream) KeycloakDeploymentInfo(org.keycloak.provider.KeycloakDeploymentInfo) HashMap(java.util.HashMap) HibernateOrmConfig(io.quarkus.hibernate.orm.deployment.HibernateOrmConfig) Config(org.keycloak.Config) ArrayList(java.util.ArrayList) MicroProfileConfigProvider(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider) Spi(org.keycloak.provider.Spi) AuthenticatorSpi(org.keycloak.authentication.AuthenticatorSpi) ProtocolMapperSpi(org.keycloak.protocol.ProtocolMapperSpi) PolicySpi(org.keycloak.authorization.policy.provider.PolicySpi) KeycloakConfigSourceProvider(org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider) Provider(org.keycloak.provider.Provider) MicroProfileConfigProvider(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider) DefaultLiquibaseConnectionProvider(org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider) ProviderManager(org.keycloak.provider.ProviderManager) FolderThemeProviderFactory(org.keycloak.theme.FolderThemeProviderFactory) RequestHostnameProviderFactory(org.keycloak.url.RequestHostnameProviderFactory) DefaultJpaConnectionProviderFactory(org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory) FilesPlainTextVaultProviderFactory(org.keycloak.vault.FilesPlainTextVaultProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) FixedHostnameProviderFactory(org.keycloak.url.FixedHostnameProviderFactory) DefaultHostnameProviderFactory(org.keycloak.url.DefaultHostnameProviderFactory) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) LiquibaseJpaUpdaterProviderFactory(org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProviderFactory) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Provider

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

the class KeycloakProcessor method configureProviders.

/**
 * <p>Load the built-in provider factories during build time so we don't spend time looking up them at runtime. By loading
 * providers at this stage we are also able to perform a more dynamic configuration based on the default providers.
 *
 * <p>User-defined providers are going to be loaded at startup</p>
 *
 * @param recorder
 */
@Consume(RuntimeConfigSetupCompleteBuildItem.class)
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
KeycloakSessionFactoryPreInitBuildItem configureProviders(KeycloakRecorder recorder) {
    Profile.setInstance(new QuarkusProfile());
    Map<Spi, Map<Class<? extends Provider>, Map<String, Class<? extends ProviderFactory>>>> factories = new HashMap<>();
    Map<Class<? extends Provider>, String> defaultProviders = new HashMap<>();
    Map<String, ProviderFactory> preConfiguredProviders = new HashMap<>();
    for (Entry<Spi, Map<Class<? extends Provider>, Map<String, ProviderFactory>>> entry : loadFactories(preConfiguredProviders).entrySet()) {
        checkProviders(entry.getKey(), entry.getValue(), defaultProviders);
        for (Entry<Class<? extends Provider>, Map<String, ProviderFactory>> value : entry.getValue().entrySet()) {
            for (ProviderFactory factory : value.getValue().values()) {
                factories.computeIfAbsent(entry.getKey(), key -> new HashMap<>()).computeIfAbsent(entry.getKey().getProviderClass(), aClass -> new HashMap<>()).put(factory.getId(), factory.getClass());
            }
        }
    }
    recorder.configSessionFactory(factories, defaultProviders, preConfiguredProviders, Environment.isRebuild());
    return new KeycloakSessionFactoryPreInitBuildItem();
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) ScriptProviderMetadata(org.keycloak.representations.provider.ScriptProviderMetadata) QUERY_PROPERTY_PREFIX(org.keycloak.quarkus.runtime.storage.database.jpa.QuarkusJpaConnectionProviderFactory.QUERY_PROPERTY_PREFIX) NS_QUARKUS(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_QUARKUS) KeycloakConfigSourceProvider(org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider) DeployedScriptAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.DeployedScriptAuthenticatorFactory) PersistenceXmlDescriptorBuildItem(io.quarkus.hibernate.orm.deployment.PersistenceXmlDescriptorBuildItem) ResteasyDeploymentCustomizerBuildItem(io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem) Map(java.util.Map) Spi(org.keycloak.provider.Spi) Entity(javax.persistence.Entity) Consume(io.quarkus.deployment.annotations.Consume) AuthenticatorSpi(org.keycloak.authentication.AuthenticatorSpi) ProtocolMapperSpi(org.keycloak.protocol.ProtocolMapperSpi) StandardCharsets(java.nio.charset.StandardCharsets) FolderThemeProviderFactory(org.keycloak.theme.FolderThemeProviderFactory) ResteasyContextParameters(org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FilterBuildItem(io.quarkus.vertx.http.deployment.FilterBuildItem) RequestHostnameProviderFactory(org.keycloak.url.RequestHostnameProviderFactory) SmallRyeHealthHandler(io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler) Environment.getProviderFiles(org.keycloak.quarkus.runtime.Environment.getProviderFiles) PersistedConfigSource(org.keycloak.quarkus.runtime.configuration.PersistedConfigSource) DefaultJpaConnectionProviderFactory(org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory) Record(io.quarkus.deployment.annotations.Record) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AvailableSettings(org.hibernate.cfg.AvailableSettings) JBossJtaTransactionManagerLookup(org.keycloak.transaction.JBossJtaTransactionManagerLookup) DotName(org.jboss.jandex.DotName) FilesPlainTextVaultProviderFactory(org.keycloak.vault.FilesPlainTextVaultProviderFactory) AUTHENTICATORS(org.keycloak.representations.provider.ScriptProviderDescriptor.AUTHENTICATORS) DevServicesDatasourceResultBuildItem(io.quarkus.datasource.deployment.spi.DevServicesDatasourceResultBuildItem) ArrayList(java.util.ArrayList) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) AdditionalJpaModelBuildItem(io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem) HibernateOrmConfig(io.quarkus.hibernate.orm.deployment.HibernateOrmConfig) PropertyMappers(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers) ProviderFactory(org.keycloak.provider.ProviderFactory) Configuration.getPropertyNames(org.keycloak.quarkus.runtime.configuration.Configuration.getPropertyNames) Environment(org.keycloak.quarkus.runtime.Environment) Properties(java.util.Properties) IOException(java.io.IOException) File(java.io.File) FixedHostnameProviderFactory(org.keycloak.url.FixedHostnameProviderFactory) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) QuarkusDevRequestFilter(org.keycloak.quarkus.runtime.dev.QuarkusDevRequestFilter) QuarkusPropertiesConfigSource(org.keycloak.quarkus.runtime.configuration.QuarkusPropertiesConfigSource) URL(java.net.URL) JarFile(java.util.jar.JarFile) NonApplicationRootPathBuildItem(io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem) ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) Configuration(org.keycloak.quarkus.runtime.configuration.Configuration) RoutingContext(io.vertx.ext.web.RoutingContext) Config(org.keycloak.Config) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) QUARKUS_PROPERTY_ENABLED(org.keycloak.quarkus.runtime.configuration.QuarkusPropertiesConfigSource.QUARKUS_PROPERTY_ENABLED) DeployedScriptOIDCProtocolMapper(org.keycloak.protocol.oidc.mappers.DeployedScriptOIDCProtocolMapper) AnnotationTarget(org.jboss.jandex.AnnotationTarget) ProviderManager(org.keycloak.provider.ProviderManager) DefaultHostnameProviderFactory(org.keycloak.url.DefaultHostnameProviderFactory) PolicySpi(org.keycloak.authorization.policy.provider.PolicySpi) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) JpaUtils.loadSpecificNamedQueries(org.keycloak.connections.jpa.util.JpaUtils.loadSpecificNamedQueries) ConfigValue(io.smallrye.config.ConfigValue) List(java.util.List) Provider(org.keycloak.provider.Provider) Entry(java.util.Map.Entry) Optional(java.util.Optional) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) QuarkusKeycloakApplication(org.keycloak.quarkus.runtime.integration.jaxrs.QuarkusKeycloakApplication) StaticInitConfigSourceProviderBuildItem(io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem) KeycloakDeploymentInfo(org.keycloak.provider.KeycloakDeploymentInfo) RouteBuildItem(io.quarkus.vertx.http.deployment.RouteBuildItem) Profile(org.keycloak.common.Profile) ScriptProviderDescriptor(org.keycloak.representations.provider.ScriptProviderDescriptor) HotDeploymentWatchedFileBuildItem(io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem) QuarkusProfile(org.keycloak.quarkus.runtime.QuarkusProfile) Logger(org.jboss.logging.Logger) MicroProfileConfigProvider(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider) LaunchMode(io.quarkus.runtime.LaunchMode) HashMap(java.util.HashMap) ServicesLogger(org.keycloak.services.ServicesLogger) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) Function(java.util.function.Function) IsDevelopment(io.quarkus.deployment.IsDevelopment) JarEntry(java.util.jar.JarEntry) KeycloakRecorder(org.keycloak.quarkus.runtime.KeycloakRecorder) BuildStep(io.quarkus.deployment.annotations.BuildStep) DefaultLiquibaseConnectionProvider(org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider) StreamUtil(org.keycloak.common.util.StreamUtil) POLICIES(org.keycloak.representations.provider.ScriptProviderDescriptor.POLICIES) RuntimeConfigSetupCompleteBuildItem(io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem) LiquibaseJpaUpdaterProviderFactory(org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProviderFactory) IndexView(org.jboss.jandex.IndexView) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) QuarkusRequestFilter(org.keycloak.quarkus.runtime.integration.web.QuarkusRequestFilter) PersistenceUnitTransactionType(javax.persistence.spi.PersistenceUnitTransactionType) Consumer(java.util.function.Consumer) JsonSerialization(org.keycloak.util.JsonSerialization) DeployedScriptPolicyFactory(org.keycloak.authorization.policy.provider.js.DeployedScriptPolicyFactory) MAPPERS(org.keycloak.representations.provider.ScriptProviderDescriptor.MAPPERS) JdbcDataSourceBuildItem(io.quarkus.agroal.spi.JdbcDataSourceBuildItem) NotFoundHandler(org.keycloak.quarkus.runtime.integration.web.NotFoundHandler) ProfileManager(io.quarkus.runtime.configuration.ProfileManager) Comparator(java.util.Comparator) Handler(io.vertx.core.Handler) InputStream(java.io.InputStream) HashMap(java.util.HashMap) QuarkusProfile(org.keycloak.quarkus.runtime.QuarkusProfile) Spi(org.keycloak.provider.Spi) AuthenticatorSpi(org.keycloak.authentication.AuthenticatorSpi) ProtocolMapperSpi(org.keycloak.protocol.ProtocolMapperSpi) PolicySpi(org.keycloak.authorization.policy.provider.PolicySpi) KeycloakConfigSourceProvider(org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider) Provider(org.keycloak.provider.Provider) MicroProfileConfigProvider(org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider) DefaultLiquibaseConnectionProvider(org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider) FolderThemeProviderFactory(org.keycloak.theme.FolderThemeProviderFactory) RequestHostnameProviderFactory(org.keycloak.url.RequestHostnameProviderFactory) DefaultJpaConnectionProviderFactory(org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory) FilesPlainTextVaultProviderFactory(org.keycloak.vault.FilesPlainTextVaultProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) FixedHostnameProviderFactory(org.keycloak.url.FixedHostnameProviderFactory) DefaultHostnameProviderFactory(org.keycloak.url.DefaultHostnameProviderFactory) EnvironmentDependentProviderFactory(org.keycloak.provider.EnvironmentDependentProviderFactory) LiquibaseJpaUpdaterProviderFactory(org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProviderFactory) Map(java.util.Map) HashMap(java.util.HashMap) Consume(io.quarkus.deployment.annotations.Consume) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with Provider

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

the class DefaultComponentFactoryProviderFactory method getProviderFactory.

@Override
@SuppressWarnings("unchecked")
public <T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz, String realmId, String componentId, Function<KeycloakSessionFactory, ComponentModel> modelGetter) {
    ProviderFactory res = componentsMap.get().get(componentId);
    if (res != null) {
        LOG.tracef("Found cached ProviderFactory for %s in (%s, %s)", clazz, realmId, componentId);
        return res;
    }
    // Apply the expensive operation before putting it into the cache
    final ComponentModel cm;
    if (modelGetter == null) {
        LOG.debugf("Getting component configuration for component (%s, %s) from realm configuration", clazz, realmId, componentId);
        cm = KeycloakModelUtils.getComponentModel(factory, realmId, componentId);
    } else {
        LOG.debugf("Getting component configuration for component (%s, %s) via provided method", realmId, componentId);
        cm = modelGetter.apply(factory);
    }
    if (cm == null) {
        return null;
    }
    final String provider = cm.getProviderId();
    ProviderFactory<T> pf = provider == null ? factory.getProviderFactory(clazz) : factory.getProviderFactory(clazz, provider);
    if (pf == null) {
        // Either not found or not enabled
        LOG.debugf("ProviderFactory for %s in (%s, %s) not found", clazz, realmId, componentId);
        return null;
    }
    final ProviderFactory newFactory;
    try {
        newFactory = pf.getClass().getDeclaredConstructor().newInstance();
    } catch (ReflectiveOperationException ex) {
        LOG.warn("Cannot instantiate factory", ex);
        return null;
    }
    Scope scope = Config.scope(factory.getSpi(clazz).getName(), provider);
    ComponentModelScope configScope = new ComponentModelScope(scope, cm);
    ProviderFactory<T> providerFactory;
    if (this.componentCachingAvailable) {
        providerFactory = componentsMap.get().computeIfAbsent(componentId, cId -> initializeFactory(clazz, realmId, componentId, newFactory, configScope));
    } else {
        providerFactory = initializeFactory(clazz, realmId, componentId, newFactory, configScope);
    }
    return providerFactory;
}
Also used : Scope(org.keycloak.Config.Scope) InvalidableObjectType(org.keycloak.provider.InvalidationHandler.InvalidableObjectType) Arrays(java.util.Arrays) ComponentModelScope(org.keycloak.component.ComponentModelScope) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) Collection(java.util.Collection) Logger(org.jboss.logging.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Config(org.keycloak.Config) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) Objects(java.util.Objects) ClusterProvider(org.keycloak.cluster.ClusterProvider) InvalidationHandler(org.keycloak.provider.InvalidationHandler) Provider(org.keycloak.provider.Provider) Stream(java.util.stream.Stream) StackUtil(org.keycloak.common.util.StackUtil) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) ObjectType(org.keycloak.provider.InvalidationHandler.ObjectType) ComponentModel(org.keycloak.component.ComponentModel) ProviderFactory(org.keycloak.provider.ProviderFactory) Scope(org.keycloak.Config.Scope) ComponentModelScope(org.keycloak.component.ComponentModelScope) ComponentModelScope(org.keycloak.component.ComponentModelScope) ComponentFactoryProviderFactory(org.keycloak.component.ComponentFactoryProviderFactory) ProviderFactory(org.keycloak.provider.ProviderFactory) ComponentModel(org.keycloak.component.ComponentModel)

Example 5 with Provider

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

the class DefaultKeycloakSessionFactory method deploy.

@Override
public void deploy(ProviderManager pm) {
    Map<Class<? extends Provider>, Map<String, ProviderFactory>> copy = getFactoriesCopy();
    Map<Class<? extends Provider>, Map<String, ProviderFactory>> newFactories = loadFactories(pm);
    List<ProviderFactory> deployed = new LinkedList<>();
    List<ProviderFactory> undeployed = new LinkedList<>();
    for (Map.Entry<Class<? extends Provider>, Map<String, ProviderFactory>> entry : newFactories.entrySet()) {
        Map<String, ProviderFactory> current = copy.get(entry.getKey());
        if (current == null) {
            copy.put(entry.getKey(), entry.getValue());
        } else {
            for (ProviderFactory f : entry.getValue().values()) {
                deployed.add(f);
                ProviderFactory old = current.remove(f.getId());
                if (old != null)
                    undeployed.add(old);
            }
            current.putAll(entry.getValue());
        }
    }
    factoriesMap = copy;
    // need to update the default provider map
    checkProvider();
    boolean cfChanged = false;
    for (ProviderFactory factory : undeployed) {
        invalidate(ObjectType.PROVIDER_FACTORY, factory.getClass());
        factory.close();
        cfChanged |= (componentFactoryPF == factory);
    }
    // Component factory must be initialized first, so that postInit in other factories can use component factories
    if (cfChanged) {
        updateComponentFactoryProviderFactory();
        if (componentFactoryPF != null) {
            componentFactoryPF.postInit(this);
        }
    }
    for (ProviderFactory factory : deployed) {
        if (factory != componentFactoryPF) {
            factory.postInit(this);
        }
    }
    if (pm.getInfo().hasThemes() || pm.getInfo().hasThemeResources()) {
        themeManagerFactory.clearCache();
    }
}
Also used : 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) LinkedList(java.util.LinkedList) 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