Search in sources :

Example 6 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method configureResteasy.

@BuildStep
void configureResteasy(BuildProducer<ResteasyDeploymentCustomizerBuildItem> deploymentCustomizerProducer) {
    deploymentCustomizerProducer.produce(new ResteasyDeploymentCustomizerBuildItem(new Consumer<ResteasyDeployment>() {

        @Override
        public void accept(ResteasyDeployment resteasyDeployment) {
            // we need to explicitly set the application to avoid errors at build time due to the application
            // from keycloak-services also being added to the index
            resteasyDeployment.setApplicationClass(QuarkusKeycloakApplication.class.getName());
            // we need to disable the sanitizer to avoid escaping text/html responses from the server
            resteasyDeployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, Boolean.TRUE);
        }
    }));
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Consumer(java.util.function.Consumer) QuarkusKeycloakApplication(org.keycloak.quarkus.runtime.integration.jaxrs.QuarkusKeycloakApplication) ResteasyDeploymentCustomizerBuildItem(io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 7 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class LiquibaseProcessor method configure.

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void configure(KeycloakRecorder recorder, List<JdbcDataSourceBuildItem> jdbcDataSources, CombinedIndexBuildItem indexBuildItem) {
    DotName liquibaseServiceName = DotName.createSimple(LiquibaseService.class.getName());
    Map<String, List<String>> services = new HashMap<>();
    IndexView index = indexBuildItem.getIndex();
    JdbcDataSourceBuildItem dataSourceBuildItem = jdbcDataSources.get(0);
    String dbKind = dataSourceBuildItem.getDbKind();
    for (Class<?> c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, liquibase.parser.NamespaceDetails.class, liquibase.precondition.Precondition.class, Database.class, liquibase.change.Change.class, liquibase.snapshot.SnapshotGenerator.class, liquibase.changelog.ChangeLogHistoryService.class, liquibase.datatype.LiquibaseDataType.class, liquibase.executor.Executor.class, SqlGenerator.class)) {
        List<String> impls = new ArrayList<>();
        services.put(c.getName(), impls);
        Set<ClassInfo> classes = new HashSet<>();
        if (c.isInterface()) {
            classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName())));
        } else {
            classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName())));
        }
        filterImplementations(c, dbKind, classes);
        for (ClassInfo found : classes) {
            if (Modifier.isAbstract(found.flags()) || Modifier.isInterface(found.flags()) || !found.hasNoArgsConstructor() || !Modifier.isPublic(found.flags())) {
                continue;
            }
            AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName);
            if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) {
                impls.add(found.name().toString());
            }
        }
    }
    services.put(LockService.class.getName(), Arrays.asList(DummyLockService.class.getName()));
    services.put(ChangeLogParser.class.getName(), Arrays.asList(XMLChangeLogSAXParser.class.getName()));
    recorder.configureLiquibase(services);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DotName(org.jboss.jandex.DotName) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) DummyLockService(org.keycloak.connections.jpa.updater.liquibase.lock.DummyLockService) LockService(liquibase.lockservice.LockService) IndexView(org.jboss.jandex.IndexView) ChangeLogParser(liquibase.parser.ChangeLogParser) LiquibaseService(liquibase.servicelocator.LiquibaseService) JdbcDataSourceBuildItem(io.quarkus.agroal.spi.JdbcDataSourceBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 8 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project redisson by redisson.

the class QuarkusRedissonClientProcessor method addConfig.

@BuildStep
void addConfig(BuildProducer<NativeImageResourceBuildItem> nativeResources, BuildProducer<HotDeploymentWatchedFileBuildItem> watchedFiles, BuildProducer<RuntimeInitializedClassBuildItem> staticItems, BuildProducer<ReflectiveClassBuildItem> reflectiveItems) {
    nativeResources.produce(new NativeImageResourceBuildItem("redisson.yaml"));
    nativeResources.produce(new NativeImageResourceBuildItem("META-INF/services/org.jboss.marshalling.ProviderDescriptor"));
    watchedFiles.produce(new HotDeploymentWatchedFileBuildItem("redisson.yaml"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(false, false, "org.redisson.codec.MarshallingCodec"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(false, false, "org.jboss.marshalling.river.RiverProviderDescriptor"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, false, "org.redisson.executor.RemoteExecutorService"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, false, "org.redisson.executor.RemoteExecutorServiceAsync"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.Config"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.BaseConfig"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.BaseMasterSlaveServersConfig"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.SingleServerConfig"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.ReplicatedServersConfig"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.SentinelServersConfig"));
    reflectiveItems.produce(new ReflectiveClassBuildItem(true, true, "org.redisson.config.ClusterServersConfig"));
}
Also used : NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) HotDeploymentWatchedFileBuildItem(io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 9 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method configureHibernate.

/**
 * <p>Configures the persistence unit for Quarkus.
 *
 * <p>The main reason we have this build step is because we re-use the same persistence unit from {@code keycloak-model-jpa}
 * module, the same used by the Wildfly distribution. The {@code hibernate-orm} extension expects that the dialect is statically
 * set to the persistence unit if there is any from the classpath and we use this method to obtain the dialect from the configuration
 * file so that we can build the application with whatever dialect we want. In addition to the dialect, we should also be
 * allowed to set any additional defaults that we think that makes sense.
 *
 * @param config
 * @param descriptors
 */
@BuildStep
void configureHibernate(HibernateOrmConfig config, List<PersistenceXmlDescriptorBuildItem> descriptors, List<JdbcDataSourceBuildItem> jdbcDataSources, BuildProducer<AdditionalJpaModelBuildItem> additionalJpaModel, CombinedIndexBuildItem indexBuildItem) {
    ParsedPersistenceXmlDescriptor descriptor = descriptors.get(0).getDescriptor();
    configureJpaProperties(descriptor, config, jdbcDataSources);
    configureJpaModel(descriptor, indexBuildItem);
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 10 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep 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)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)11 Record (io.quarkus.deployment.annotations.Record)4 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)2 Consume (io.quarkus.deployment.annotations.Consume)2 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)2 HotDeploymentWatchedFileBuildItem (io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem)2 IndexDependencyBuildItem (io.quarkus.deployment.builditem.IndexDependencyBuildItem)2 StaticInitConfigSourceProviderBuildItem (io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem)2 ResteasyDeploymentCustomizerBuildItem (io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem)2 LaunchMode (io.quarkus.runtime.LaunchMode)2 SmallRyeHealthHandler (io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler)2 FilterBuildItem (io.quarkus.vertx.http.deployment.FilterBuildItem)2 ConfigValue (io.smallrye.config.ConfigValue)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)2