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;
}
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;
}
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);
}
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";
}
Aggregations