8000 fix: the transformed value should always be returned by shawkins · Pull Request #24758 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ ConfigValue getConfigValue(String name, ConfigSourceInterceptorContext context)
from = name.replace(to.substring(0, to.lastIndexOf('.')), from.substring(0, from.lastIndexOf(OPTION_PART_SEPARATOR_CHAR)));
}

if (isRebuild() && isRunTime() && name.startsWith(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX)) {
boolean isKcProperty = name.startsWith(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX);
boolean transform = !isKcProperty || !from.equals(name);
if (isRebuild() && isRunTime() && isKcProperty) {
// during re-aug do not resolve the server runtime properties and avoid they included by quarkus in the default value config source
return ConfigValue.builder().withName(name).build();
}
Expand All @@ -111,10 +113,10 @@ ConfigValue getConfigValue(String name, ConfigSourceInterceptorContext context)
}
}

return transformValue(ofNullable(parentValue == null ? null : parentValue.getValue()), context);
return transformValue(transform, ofNullable(parentValue == null ? null : parentValue.getValue()), context);
}

ConfigValue defaultValue = transformValue(this.option.getDefaultValue().map(Objects::toString), context);
ConfigValue defaultValue = transformValue(transform, this.option.getDefaultValue().map(Objects::toString), context);

if (defaultValue != null) {
return defaultValue;
Expand All @@ -124,7 +126,7 @@ ConfigValue getConfigValue(String name, ConfigSourceInterceptorContext context)
ConfigValue current = context.proceed(name);

if (current != null) {
return transformValue(ofNullable(current.getValue()), context);
return transformValue(transform, ofNullable(current.getValue()), context);
}

return current;
Expand All @@ -136,7 +138,7 @@ ConfigValue getConfigValue(String name, ConfigSourceInterceptorContext context)
return config;
}

ConfigValue transformedValue = transformValue(configValue, context);
ConfigValue transformedValue = transformValue(transform, configValue, context);

// we always fallback to the current value from the property we are mapping
if (transformedValue == null) {
Expand Down Expand Up @@ -196,12 +198,12 @@ boolean isMask() {
return mask;
}

private ConfigValue transformValue(Optional<String> value, ConfigSourceInterceptorContext context) {
private ConfigValue transformValue(boolean transform, Optional<String> value, ConfigSourceInterceptorContext context) {
if (value == null) {
return null;
}

if (mapper == null) {
if (mapper == null || !transform) {
return ConfigValue.builder().withName(to).withValue(value.orElse(null)).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

import java.util.Optional;

import static java.util.Optional.of;
import static org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper.fromOption;
import static org.keycloak.quarkus.runtime.integration.QuarkusPlatform.addInitializationException;

import org.keycloak.config.ProxyOptions;
import org.keycloak.quarkus.runtime.Messages;

final class ProxyPropertyMappers {
public final class ProxyPropertyMappers {

private ProxyPropertyMappers(){}

Expand Down Expand Up @@ -40,20 +39,23 @@ public static PropertyMapper[] getProxyPropertyMappers() {
};
}

private static Optional<String> getValidProxyModeValue(Optional<String> value, ConfigSourceInterceptorContext context) {
String mode = value.get();

switch (mode) {
case "none":
case "passthrough":
return of(Boolean.FALSE.toString());
case "edge":
case "reencrypt":
return of(Boolean.TRUE.toString());
default:
addInitializati 8000 onException(Messages.invalidProxyMode(mode));
return of(Boolean.FALSE.toString());
public static boolean getValidProxyModeValue(String mode) {
try {
switch (ProxyOptions.Mode.valueOf(mode)) {
case none:
case passthrough:
return false;
default:
return true;
}
} catch (IllegalArgumentException e) {
addInitializationException(Messages.invalidProxyMode(mode));
return false;
}
}

private static Optional<String> getValidProxyModeValue(Optional<String> value, ConfigSourceInterceptorContext context) {
return Optional.of(String.valueOf(getValidProxyModeValue(value.get())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@

package org.keycloak.quarkus.runtime.hostname;

import static org.keycloak.common.util.UriUtils.checkUrl;
import static org.keycloak.urls.UrlType.ADMIN;
import static org.keycloak.urls.UrlType.LOCAL_ADMIN;
import static org.keycloak.urls.UrlType.BACKEND;
import static org.keycloak.urls.UrlType.FRONTEND;
import static org.keycloak.utils.StringUtil.isNotBlank;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.function.BiFunction;
import java.util.function.Function;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.common.enums.SslRequired;
Expand All @@ -39,10 +25,27 @@
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.quarkus.runtime.configuration.Configuration;
import org.keycloak.quarkus.runtime.configuration.mappers.ProxyPropertyMappers;
import org.keycloak.urls.HostnameProvider;
import org.keycloak.urls.HostnameProviderFactory;
import org.keycloak.urls.UrlType;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.function.BiFunction;
import java.util.function.Function;

import jakarta.ws.rs.core.UriInfo;

import static org.keycloak.common.util.UriUtils.checkUrl;
import static org.keycloak.urls.UrlType.ADMIN;
import static org.keycloak.urls.UrlType.BACKEND;
import static org.keycloak.urls.UrlType.FRONTEND;
import static org.keycloak.urls.UrlType.LOCAL_ADMIN;
import static org.keycloak.utils.StringUtil.isNotBlank;

public final class DefaultHostnameProvider implements HostnameProvider, HostnameProviderFactory {

private static final Logger LOGGER = Logger.getLogger(DefaultHostnameProvider.class);
Expand Down Expand Up @@ -285,7 +288,7 @@ public void init(Config.Scope config) {
}

defaultPath = config.get("path", frontEndBaseUri == null ? null : frontEndBaseUri.getPath());
noProxy = Configuration.getConfigValue("kc.proxy").getValue().equals("false");
noProxy = ProxyPropertyMappers.getValidProxyModeValue(Configuration.getConfigValue("kc.proxy").getValue());
defaultTlsPort = Integer.parseInt(httpPort);

if (defaultTlsPort == DEFAULT_HTTPS_PORT_VALUE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ protected void waitForReadiness() throws MalformedURLException, LifecycleExcepti
URL contextRoot = new URL(getBaseUrl(suiteContext) + "/auth/realms/master/");
HttpURLConnection connection;
long startTime = System.currentTimeMillis();
Exception ex = null;

while (true) {
if (System.currentTimeMillis() - startTime > getStartTimeout()) {
stop();
throw new IllegalStateException("Timeout [" + getStartTimeout() + "] while waiting for Quarkus server");
throw new IllegalStateException("Timeout [" + getStartTimeout() + "] while waiting for Quarkus server", ex);
}

try {
Expand All @@ -275,6 +276,7 @@ protected void waitForReadiness() throws MalformedURLException, LifecycleExcepti

connection.disconnect();
} catch (Exception ignore) {
ex = ignore;
}
}

Expand Down Expand Up @@ -304,12 +306,15 @@ public boolean verify(String s, SSLSession sslSession) {

private SSLSocketFactory createInsecureSslSocketFactory() throws IOException {
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}

@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
Expand Down
0