Search in sources :

Example 6 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class PropertyMapper method getConfigValue.

ConfigValue getConfigValue(String name, ConfigSourceInterceptorContext context) {
    String from = this.from;
    if (to != null && to.endsWith(OPTION_PART_SEPARATOR)) {
        // in case mapping is based on prefixes instead of full property names
        from = name.replace(to.substring(0, to.lastIndexOf('.')), from.substring(0, from.lastIndexOf(OPTION_PART_SEPARATOR_CHAR)));
    }
    // try to obtain the value for the property we want to map first
    ConfigValue config = context.proceed(from);
    if (config == null) {
        if (mapFrom != null) {
            // if the property we want to map depends on another one, we use the value from the other property to call the mapper
            String parentKey = MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + mapFrom;
            ConfigValue parentValue = context.proceed(parentKey);
            if (parentValue == null) {
                // parent value not explicitly set, try to resolve the default value set to the parent property
                PropertyMapper parentMapper = PropertyMappers.getMapper(parentKey);
                if (parentMapper != null) {
                    parentValue = ConfigValue.builder().withValue(parentMapper.getDefaultValue()).build();
                }
            }
            if (parentValue != null) {
                return transformValue(parentValue.getValue(), context);
            }
        }
        if (defaultValue != null) {
            return transformValue(defaultValue, context);
        }
        // now tries any defaults from quarkus
        ConfigValue current = context.proceed(name);
        if (current != null) {
            return transformValue(current.getValue(), context);
        }
        return current;
    }
    if (config.getName().equals(name)) {
        return config;
    }
    ConfigValue value = transformValue(config.getValue(), context);
    // we always fallback to the current value from the property we are mapping
    if (value == null) {
        return context.proceed(name);
    }
    return value;
}
Also used : ConfigValue(io.smallrye.config.ConfigValue)

Example 7 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class Picocli method hasConfigChanges.

private static boolean hasConfigChanges() {
    Optional<String> currentProfile = Optional.ofNullable(Environment.getProfile());
    Optional<String> persistedProfile = getBuildTimeProperty("kc.profile");
    if (!persistedProfile.orElse("").equals(currentProfile.orElse(""))) {
        return true;
    }
    for (String propertyName : getConfig().getPropertyNames()) {
        // only check keycloak build-time properties
        if (!isBuildTimeProperty(propertyName)) {
            continue;
        }
        ConfigValue configValue = getConfig().getConfigValue(propertyName);
        if (configValue == null || configValue.getConfigSourceName() == null) {
            continue;
        }
        // try to resolve any property set using profiles
        if (propertyName.startsWith("%")) {
            propertyName = propertyName.substring(propertyName.indexOf('.') + 1);
        }
        String persistedValue = getBuildTimeProperty(propertyName).orElse("");
        String runtimeValue = getRuntimeProperty(propertyName).orElse(null);
        if (runtimeValue == null && isNotBlank(persistedValue)) {
            PropertyMapper mapper = PropertyMappers.getMapper(propertyName);
            if (mapper != null && persistedValue.equals(mapper.getDefaultValue())) {
                // same as default
                continue;
            }
            // probably because it was unset
            return true;
        }
        // changes to a single property is enough to indicate changes to configuration
        if (!persistedValue.equals(runtimeValue)) {
            return true;
        }
    }
    return false;
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)

Example 8 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class DatabasePropertyMappers method getXaOrNonXaDriver.

private static String getXaOrNonXaDriver(String db, ConfigSourceInterceptorContext context) {
    ConfigValue xaEnabledConfigValue = context.proceed("kc.transaction-xa-enabled");
    boolean isXaEnabled = xaEnabledConfigValue == null || Boolean.parseBoolean(xaEnabledConfigValue.getValue());
    return Database.getDriver(db, isXaEnabled).orElse(db);
}
Also used : ConfigValue(io.smallrye.config.ConfigValue)

Example 9 with ConfigValue

use of io.smallrye.config.ConfigValue in project keycloak by keycloak.

the class HttpPropertyMappers method getHttpEnabledTransformer.

private static String getHttpEnabledTransformer(String value, ConfigSourceInterceptorContext context) {
    boolean enabled = Boolean.parseBoolean(value);
    ConfigValue proxy = context.proceed(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX + "proxy");
    if (Environment.isDevMode() || Environment.isImportExportMode() || (proxy != null && "edge".equalsIgnoreCase(proxy.getValue()))) {
        enabled = true;
    }
    if (!enabled) {
        ConfigValue proceed = context.proceed("kc.https-certificate-file");
        if (proceed == null || proceed.getValue() == null) {
            proceed = getMapper("quarkus.http.ssl.certificate.key-store-file").getConfigValue(context);
        }
        if (proceed == null || proceed.getValue() == null) {
            addInitializationException(Messages.httpsConfigurationNotSet());
        }
    }
    return enabled ? "enabled" : "disabled";
}
Also used : ConfigValue(io.smallrye.config.ConfigValue)

Aggregations

ConfigValue (io.smallrye.config.ConfigValue)9 Configuration.getConfigValue (org.keycloak.quarkus.runtime.configuration.Configuration.getConfigValue)2 PropertyMapper (org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper)2 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 FileSystemException (java.nio.file.FileSystemException)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 JarFile (java.util.jar.JarFile)1