diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java index 9dec3de6..6231533b 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java @@ -99,7 +99,8 @@ public ForwardedDevServerBuildItem prepareDevService( devServerConfig.host(), devServerConfig.port().get(), checkPath); - return new ForwardedDevServerBuildItem(resolvedDevServerHost, devServerConfig.port().get()); + return new ForwardedDevServerBuildItem(devServerConfig.tls(), devServerConfig.tlsAllowInsecure(), + resolvedDevServerHost, devServerConfig.port().get()); } shutdownDevService(); } @@ -125,7 +126,7 @@ public ForwardedDevServerBuildItem prepareDevService( final String resolvedHostIPAddress = PackageManagerRunner.isDevServerUp(configuredTls, configuredTlsAllowInsecure, configuredDevServerHost, port, checkPath); if (resolvedHostIPAddress != null) { - return new ForwardedDevServerBuildItem(resolvedHostIPAddress, port); + return new ForwardedDevServerBuildItem(configuredTls, configuredTlsAllowInsecure, resolvedHostIPAddress, port); } else { throw new IllegalStateException( "The Web UI dev server (configured as not managed by Quinoa) is not started on port: " + port); @@ -161,7 +162,7 @@ public ForwardedDevServerBuildItem prepareDevService( devService = new DevServicesResultBuildItem.RunningDevService( DEV_SERVICE_NAME, null, onClose, devServerConfigMap); devServices.produce(devService.toBuildItem()); - return new ForwardedDevServerBuildItem(devServer.hostIPAddress(), port); + return new ForwardedDevServerBuildItem(configuredTls, configuredTlsAllowInsecure, devServer.hostIPAddress(), port); } catch (Throwable t) { packageManagerRunner.stopDev(dev.get()); if (devServer != null) { @@ -206,7 +207,8 @@ public void runtimeInit( LOG.infof("Quinoa is forwarding unhandled requests to port: %d", devProxy.get().getPort()); final QuinoaHandlerConfig handlerConfig = toHandlerConfig(quinoaConfig, true, httpBuildTimeConfig); routes.produce(RouteBuildItem.builder().orderedRoute("/*", QUINOA_ROUTE_ORDER) - .handler(recorder.quinoaProxyDevHandler(handlerConfig, vertx.getVertx(), devProxy.get().getHost(), + .handler(recorder.quinoaProxyDevHandler(handlerConfig, vertx.getVertx(), devProxy.get().isTls(), + devProxy.get().isTlsAllowInsecure(), devProxy.get().getHost(), devProxy.get().getPort(), quinoaConfig.devServer().websocket())) .build()); diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/config/DevServerConfig.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/config/DevServerConfig.java index 1bb75901..89d2f530 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/config/DevServerConfig.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/config/DevServerConfig.java @@ -41,13 +41,13 @@ public interface DevServerConfig { String host(); /** - * Protocol of the server to forward requests to. + * If true, request will be forwarded with tls enabled. */ @WithDefault("false") boolean tls(); /** - * Protocol of the server to forward requests to. + * If true, any certificate with any hostname will be accepted. */ @WithDefault("false") boolean tlsAllowInsecure(); diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java index 71ea8458..a202cb3d 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java @@ -4,14 +4,26 @@ public final class ForwardedDevServerBuildItem extends SimpleBuildItem { + private final boolean tls; + private final boolean tlsAllowInsecure; private final String host; private final Integer port; - public ForwardedDevServerBuildItem(String host, Integer port) { + public ForwardedDevServerBuildItem(boolean tls, boolean tlsAllowInsecure, String host, Integer port) { + this.tls = tls; + this.tlsAllowInsecure = tlsAllowInsecure; this.host = host; this.port = port; } + public boolean isTls() { + return tls; + } + + public boolean isTlsAllowInsecure() { + return tlsAllowInsecure; + } + public String getHost() { return host; } diff --git a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java index 268be9bd..4b692132 100644 --- a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java +++ b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java @@ -7,6 +7,8 @@ import java.util.List; +import io.vertx.core.net.JdkSSLEngineOptions; +import io.vertx.ext.web.client.WebClientOptions; import org.jboss.logging.Logger; import io.vertx.core.AsyncResult; @@ -36,11 +38,19 @@ class QuinoaDevProxyHandler implements Handler { private final ClassLoader currentClassLoader; private final QuinoaHandlerConfig config; - QuinoaDevProxyHandler(final QuinoaHandlerConfig config, final Vertx vertx, String host, int port, + QuinoaDevProxyHandler(final QuinoaHandlerConfig config, final Vertx vertx, boolean tls, boolean tlsAllowInsecure, String host, int port, boolean websocket) { this.host = host; this.port = port; - this.client = WebClient.create(vertx); + WebClientOptions options = new WebClientOptions(); + if(tls){ + options.setSsl(true); + if(tlsAllowInsecure){ + options.setTrustAll(true); + options.setVerifyHost(false); + } + } + this.client = WebClient.create(vertx, options); this.wsUpgradeHandler = websocket ? new QuinoaDevWebSocketProxyHandler(vertx, host, port) : null; this.config = config; currentClassLoader = Thread.currentThread().getContextClassLoader(); diff --git a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java index c57ffa32..5ec4cd85 100644 --- a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java +++ b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java @@ -1,14 +1,5 @@ package io.quarkiverse.quinoa; -import static io.quarkus.vertx.http.runtime.RouteConstants.ROUTE_ORDER_DEFAULT; - -import java.io.IOException; -import java.util.List; -import java.util.Set; -import java.util.function.Supplier; - -import org.jboss.logging.Logger; - import io.quarkus.runtime.annotations.Recorder; import io.vertx.core.Handler; import io.vertx.core.Vertx; @@ -16,6 +7,14 @@ import io.vertx.core.http.HttpMethod; import io.vertx.core.http.impl.MimeMapping; import io.vertx.ext.web.RoutingContext; +import org.jboss.logging.Logger; + +import java.io.IOException; +import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +import static io.quarkus.vertx.http.runtime.RouteConstants.ROUTE_ORDER_DEFAULT; @Recorder public class QuinoaRecorder { @@ -26,9 +25,9 @@ public class QuinoaRecorder { public static final Set HANDLED_METHODS = Set.of(HttpMethod.HEAD, HttpMethod.OPTIONS, HttpMethod.GET); public Handler quinoaProxyDevHandler(final QuinoaHandlerConfig handlerConfig, Supplier vertx, - String host, int port, boolean websocket) { + boolean tls, boolean tlsAllowInsecure, String host, int port, boolean websocket) { logIgnoredPathPrefixes(handlerConfig.ignoredPathPrefixes); - return new QuinoaDevProxyHandler(handlerConfig, vertx.get(), host, port, websocket); + return new QuinoaDevProxyHandler(handlerConfig, vertx.get(), tls, tlsAllowInsecure, host, port, websocket); } public Handler quinoaSPARoutingHandler(final QuinoaHandlerConfig handlerConfig) throws IOException { @@ -36,7 +35,7 @@ public Handler quinoaSPARoutingHandler(final QuinoaHandlerConfig } public Handler quinoaHandler(final QuinoaHandlerConfig handlerConfig, final String directory, - final Set uiResources) { + final Set uiResources) { logIgnoredPathPrefixes(handlerConfig.ignoredPathPrefixes); return new QuinoaUIResourceHandler(handlerConfig, directory, uiResources); } @@ -44,9 +43,9 @@ public Handler quinoaHandler(final QuinoaHandlerConfig handlerCo static String resolvePath(RoutingContext ctx) { return (ctx.mountPoint() == null) ? ctx.normalizedPath() : ctx.normalizedPath().substring( - // let's be extra careful here in case Vert.x normalizes the mount points at - // some point - ctx.mountPoint().endsWith("/") ? ctx.mountPoint().length() - 1 : ctx.mountPoint().length()); + // let's be extra careful here in case Vert.x normalizes the mount points at + // some point + ctx.mountPoint().endsWith("/") ? ctx.mountPoint().length() - 1 : ctx.mountPoint().length()); } static boolean isIgnored(final String path, final List ignoredPathPrefixes) {