From b4dc09de90a28ad9d42b206a2e390ddadf68355c Mon Sep 17 00:00:00 2001 From: Marek Skacelik Date: Fri, 20 Sep 2024 11:45:20 +0200 Subject: [PATCH] Added a (Key/Trust)StoreOptions configuration properties --- .../vertx/VertxClientOptionsHelper.java | 15 +++++++-- .../impl/GraphQLClientConfiguration.java | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/client/implementation-vertx/src/main/java/io/smallrye/graphql/client/vertx/VertxClientOptionsHelper.java b/client/implementation-vertx/src/main/java/io/smallrye/graphql/client/vertx/VertxClientOptionsHelper.java index cd6335991..8921289d4 100644 --- a/client/implementation-vertx/src/main/java/io/smallrye/graphql/client/vertx/VertxClientOptionsHelper.java +++ b/client/implementation-vertx/src/main/java/io/smallrye/graphql/client/vertx/VertxClientOptionsHelper.java @@ -6,12 +6,19 @@ import io.smallrye.graphql.client.vertx.ssl.SSLTools; import io.vertx.core.http.HttpClientOptions; import io.vertx.core.net.JksOptions; +import io.vertx.core.net.KeyCertOptions; import io.vertx.core.net.ProxyOptions; +import io.vertx.core.net.TrustOptions; public class VertxClientOptionsHelper { public static void applyConfigToVertxOptions(HttpClientOptions options, GraphQLClientConfiguration configuration) { - if (options.getTrustStoreOptions() == null && configuration.getTrustStore() != null) { + TrustOptions tlsTrustStoreOptions = (TrustOptions) configuration.getTlsTrustStoreOptions(); + KeyCertOptions tlsKeyStoreOptions = (KeyCertOptions) configuration.getTlsKeyStoreOptions(); + if (tlsTrustStoreOptions != null) { + options.setSsl(true); + options.setTrustOptions(tlsTrustStoreOptions); + } else if (options.getTrustStoreOptions() == null && configuration.getTrustStore() != null) { // deprecated in Quarkus options.setSsl(true); JksOptions trustStoreOptions = new JksOptions(); KeyStore trustStore = SSLTools.createKeyStore(configuration.getTrustStore(), @@ -21,8 +28,10 @@ public static void applyConfigToVertxOptions(HttpClientOptions options, GraphQLC trustStoreOptions.setPassword(new String(configuration.getTrustStorePassword())); options.setTrustStoreOptions(trustStoreOptions); } - - if (options.getKeyStoreOptions() == null && configuration.getKeyStore() != null) { + if (tlsKeyStoreOptions != null) { + options.setSsl(true); + options.setKeyCertOptions(tlsKeyStoreOptions); + } else if (options.getKeyStoreOptions() == null && configuration.getKeyStore() != null) { // deprecated in Quarkus options.setSsl(true); JksOptions keyStoreOptions = new JksOptions(); KeyStore keyStore = SSLTools.createKeyStore(configuration.getKeyStore(), diff --git a/client/implementation/src/main/java/io/smallrye/graphql/client/impl/GraphQLClientConfiguration.java b/client/implementation/src/main/java/io/smallrye/graphql/client/impl/GraphQLClientConfiguration.java index d2f087ec8..f3074d556 100644 --- a/client/implementation/src/main/java/io/smallrye/graphql/client/impl/GraphQLClientConfiguration.java +++ b/client/implementation/src/main/java/io/smallrye/graphql/client/impl/GraphQLClientConfiguration.java @@ -77,6 +77,16 @@ public class GraphQLClientConfiguration { */ private String keyStoreType; + /** + * The key store options, already contains key tore. + */ + private Object tlsKeyStoreOptions; + + /** + * The trust store options, already contains trust tore. + */ + private Object tlsTrustStoreOptions; + /** * Hostname of the proxy to use. */ @@ -273,6 +283,22 @@ public void setAllowUnexpectedResponseFields(Boolean allowUnexpectedResponseFiel this.allowUnexpectedResponseFields = allowUnexpectedResponseFields; } + public Object getTlsKeyStoreOptions() { + return tlsKeyStoreOptions; + } + + public void setTlsKeyStoreOptions(Object tlsKeyStoreOptions) { + this.tlsKeyStoreOptions = tlsKeyStoreOptions; + } + + public Object getTlsTrustStoreOptions() { + return tlsTrustStoreOptions; + } + + public void setTlsTrustStoreOptions(Object tlsTrustStoreOptions) { + this.tlsTrustStoreOptions = tlsTrustStoreOptions; + } + /** * Merge the `other` configuration into this one. Values in `other` take precedence. * This method has to be idempotent because it can be called multiple times to allow for changes in configuration. @@ -350,6 +376,12 @@ public GraphQLClientConfiguration merge(GraphQLClientConfiguration other) { if (other.allowUnexpectedResponseFields != null) { this.allowUnexpectedResponseFields = other.allowUnexpectedResponseFields; } + if (other.tlsKeyStoreOptions != null) { + this.tlsKeyStoreOptions = other.tlsKeyStoreOptions; + } + if (other.tlsTrustStoreOptions != null) { + this.tlsTrustStoreOptions = other.tlsTrustStoreOptions; + } return this; } }