From 52d205ca916688b7fc6c77d6a319f584b6b3fd6f Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 19 Apr 2022 03:01:42 -0300 Subject: [PATCH] Allow exposing some initial provider config options via web site (#10572) * Allow exposing some initial provider config options via web site Co-authored-by: Stian Thorgersen Closes #10571 * Include type to provider options, and hide build-icon column as it's not relevant Co-authored-by: stianst --- .../src/main/server/all-provider-config.adoc | 16 ++++ docs/guides/src/main/templates/options.adoc | 10 ++- docs/maven-plugin/pom.xml | 6 -- .../org/keycloak/guides/maven/Options.java | 41 +++++++++ ...nAuthenticationSessionProviderFactory.java | 14 ++++ ...anStickySessionEncoderProviderFactory.java | 16 ++++ .../lock/LiquibaseDBLockProviderFactory.java | 13 +++ .../quarkus/deployment/KeycloakProcessor.java | 10 +-- .../keycloak/quarkus/runtime/Providers.java | 33 ++++++++ .../runtime/configuration/Configuration.java | 19 +++++ .../MicroProfileConfigProvider.java | 20 +---- .../QuarkusJpaConnectionProviderFactory.java | 26 ++++++ .../keycloak/provider/ProviderFactory.java | 10 +++ .../httpclient/DefaultHttpClientFactory.java | 83 +++++++++++++++++++ .../GzipResourceEncodingProviderFactory.java | 15 ++++ .../EmailEventListenerProviderFactory.java | 28 +++++++ ...ssLoggingEventListenerProviderFactory.java | 29 +++++++ .../oidc/OIDCWellKnownProviderFactory.java | 20 +++++ ...pAuthenticationChannelProviderFactory.java | 14 ++++ .../FileTruststoreProviderFactory.java | 27 +++++- 20 files changed, 414 insertions(+), 36 deletions(-) create mode 100644 docs/guides/src/main/server/all-provider-config.adoc create mode 100644 quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/Providers.java diff --git a/docs/guides/src/main/server/all-provider-config.adoc b/docs/guides/src/main/server/all-provider-config.adoc new file mode 100644 index 0000000000..9f0f868219 --- /dev/null +++ b/docs/guides/src/main/server/all-provider-config.adoc @@ -0,0 +1,16 @@ +<#import "/templates/guide.adoc" as template> +<#import "/templates/options.adoc" as opts> + +<@template.guide +title="All provider configuration" +summary="Complete list of all the available provider configuration options"> + +<#list ctx.options.getProviderOptions() as spi, providers> +== ${spi} +<#list providers as provider, options> +=== ${provider} +<@opts.list options=options buildIcon=false> + + + + diff --git a/docs/guides/src/main/templates/options.adoc b/docs/guides/src/main/templates/options.adoc index 7895a7df64..dc78179180 100644 --- a/docs/guides/src/main/templates/options.adoc +++ b/docs/guides/src/main/templates/options.adoc @@ -4,10 +4,16 @@ -<#macro list options> +<#macro list options buildIcon=true> +<#if buildIcon> [cols="12a,4,4,1",role="options"] |=== | |Type|Default| +<#else> +[cols="12a,4,4",role="options"] +|=== +| |Type|Default + <#list options as option> | @@ -25,7 +31,7 @@ |<#if option.defaultValue?has_content>[.options-default]#${option.defaultValue!}# -|<#if option.build>icon:tools[role=options-build] +<#if buildIcon>|<#if option.build>icon:tools[role=options-build] |=== diff --git a/docs/maven-plugin/pom.xml b/docs/maven-plugin/pom.xml index d0b1bfa272..a2d6ba108b 100644 --- a/docs/maven-plugin/pom.xml +++ b/docs/maven-plugin/pom.xml @@ -62,12 +62,6 @@ org.keycloak keycloak-quarkus-server - - - * - * - - org.keycloak diff --git a/docs/maven-plugin/src/main/java/org/keycloak/guides/maven/Options.java b/docs/maven-plugin/src/main/java/org/keycloak/guides/maven/Options.java index 1e63ddadcd..a915b3e624 100644 --- a/docs/maven-plugin/src/main/java/org/keycloak/guides/maven/Options.java +++ b/docs/maven-plugin/src/main/java/org/keycloak/guides/maven/Options.java @@ -1,11 +1,24 @@ package org.keycloak.guides.maven; +import static org.keycloak.quarkus.runtime.configuration.Configuration.OPTION_PART_SEPARATOR; +import static org.keycloak.quarkus.runtime.configuration.Configuration.toDashCase; +import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX; + +import org.apache.commons.lang3.ArrayUtils; +import org.keycloak.provider.ProviderConfigProperty; +import org.keycloak.provider.ProviderFactory; +import org.keycloak.provider.ProviderManager; +import org.keycloak.provider.Spi; +import org.keycloak.quarkus.runtime.Providers; +import org.keycloak.quarkus.runtime.configuration.Configuration; import org.keycloak.quarkus.runtime.configuration.mappers.ConfigCategory; import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper; import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -17,6 +30,7 @@ import java.util.stream.StreamSupport; public class Options { private final Map options; + private final Map>> providerOptions = new LinkedHashMap<>(); public Options() { options = PropertyMappers.getMappers().stream() @@ -25,6 +39,29 @@ public class Options { .map(m -> new Option(m.getFrom(), m.getCategory(), m.isBuildTime(), m.getDescription(), m.getDefaultValue(), m.getExpectedValues())) .sorted(Comparator.comparing(Option::getKey)) .collect(Collectors.toMap(Option::getKey, o -> o, (o1, o2) -> o1, LinkedHashMap::new)); // Need to ignore duplicate keys?? + ProviderManager providerManager = Providers.getProviderManager(Thread.currentThread().getContextClassLoader()); + + for (Spi loadSpi : providerManager.loadSpis().stream().sorted(Comparator.comparing(Spi::getName)).collect(Collectors.toList())) { + for (ProviderFactory providerFactory : providerManager.load(loadSpi).stream().sorted(Comparator.comparing(ProviderFactory::getId)).collect(Collectors.toList())) { + List configMetadata = providerFactory.getConfigMetadata(); + + if (configMetadata == null) { + continue; + } + + String optionPrefix = NS_KEYCLOAK_PREFIX + String.join(OPTION_PART_SEPARATOR, ArrayUtils.insert(0, new String[] {loadSpi.getName(), providerFactory.getId()}, "spi")); + List