From 8bf706ece0e9b9f66a39e6fa438d82e5487f4530 Mon Sep 17 00:00:00 2001 From: Rajesh Vasa Date: Sun, 15 Nov 2026 11:13:21 -0600 Subject: [PATCH 1/3] Apply disable-ssl-validation to the HTTP/2 client spring.cloud.openfeign.httpclient.disable-ssl-validation was only applied to the Apache HttpClient 5 client. Http2ClientFeignConfiguration never read it, so with the JDK HTTP/2 client, calls to a server with an untrusted certificate still failed with an SSLHandshakeException. When the property is set, configure the HttpClient.Builder with an SSLContext whose trust manager accepts every certificate. It extends X509ExtendedTrustManager, so hostname verification is skipped as well, matching the Apache HttpClient 5 behavior. Fixes gh-1196 Signed-off-by: Rajesh Vasa --- .../Http2ClientFeignConfiguration.java | 68 +++++++++- ...nHttp2ClientDisableSslValidationTests.java | 123 ++++++++++++++++++ .../src/test/resources/http2-self-signed.p12 | Bin 0 -> 2584 bytes 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttp2ClientDisableSslValidationTests.java create mode 100644 spring-cloud-openfeign-core/src/test/resources/http2-self-signed.p12 diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java index 85d18facb..969379136 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java @@ -16,10 +16,23 @@ package org.springframework.cloud.openfeign.clientconfig; +import java.net.Socket; import java.net.http.HttpClient; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; import java.time.Duration; import java.util.List; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509ExtendedTrustManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.openfeign.clientconfig.http2client.Http2ClientCustomizer; import org.springframework.cloud.openfeign.support.FeignHttpClientProperties; @@ -31,19 +44,33 @@ * * @author changjin wei(魏昌进) * @author Luis Duarte + * @author Rajesh Vasa */ @Configuration(proxyBeanMethods = false) @ConditionalOnMissingBean(HttpClient.class) public class Http2ClientFeignConfiguration { + private static final Log LOG = LogFactory.getLog(Http2ClientFeignConfiguration.class); + @Bean @ConditionalOnMissingBean public HttpClient.Builder httpClientBuilder(FeignHttpClientProperties httpClientProperties) { - return HttpClient.newBuilder() + HttpClient.Builder builder = HttpClient.newBuilder() .followRedirects( httpClientProperties.isFollowRedirects() ? HttpClient.Redirect.ALWAYS : HttpClient.Redirect.NEVER) .version(HttpClient.Version.valueOf(httpClientProperties.getHttp2().getVersion())) .connectTimeout(Duration.ofMillis(httpClientProperties.getConnectionTimeout())); + if (httpClientProperties.isDisableSslValidation()) { + try { + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, new TrustManager[] { new DisabledValidationTrustManager() }, new SecureRandom()); + builder.sslContext(sslContext); + } + catch (NoSuchAlgorithmException | KeyManagementException e) { + LOG.warn("Error creating SSLContext", e); + } + } + return builder; } @Bean @@ -52,4 +79,43 @@ public HttpClient httpClient(HttpClient.Builder httpClientBuilder, List { + byte[] body = "ok".getBytes(StandardCharsets.UTF_8); + exchange.sendResponseHeaders(200, body.length); + exchange.getResponseBody().write(body); + exchange.close(); + }); + server.start(); + } + + @AfterAll + static void stopServer() { + if (server != null) { + server.stop(0); + } + } + + @Test + void connectsToSelfSignedServerWhenSslValidationIsDisabled() throws Exception { + try (ConfigurableApplicationContext context = createContext(true)) { + HttpResponse response = send(context.getBean(HttpClient.class)); + + assertThat(response.statusCode()).isEqualTo(200); + assertThat(response.body()).isEqualTo("ok"); + } + } + + @Test + void rejectsSelfSignedServerByDefault() { + try (ConfigurableApplicationContext context = createContext(false)) { + HttpClient httpClient = context.getBean(HttpClient.class); + + assertThatExceptionOfType(SSLHandshakeException.class).isThrownBy(() -> send(httpClient)); + } + } + + private static ConfigurableApplicationContext createContext(boolean disableSslValidation) { + return new SpringApplicationBuilder() + .properties("spring.cloud.openfeign.http2client.enabled=true", + "spring.cloud.openfeign.httpclient.http2.version=HTTP_1_1", + "spring.cloud.openfeign.httpclient.disable-ssl-validation=" + disableSslValidation) + .web(WebApplicationType.NONE) + .sources(FeignAutoConfiguration.class) + .run(); + } + + private static HttpResponse send(HttpClient httpClient) throws Exception { + URI uri = URI.create("https://localhost:" + server.getAddress().getPort() + "/"); + return httpClient.send(HttpRequest.newBuilder(uri).GET().build(), HttpResponse.BodyHandlers.ofString()); + } + +} diff --git a/spring-cloud-openfeign-core/src/test/resources/http2-self-signed.p12 b/spring-cloud-openfeign-core/src/test/resources/http2-self-signed.p12 new file mode 100644 index 0000000000000000000000000000000000000000..bc0f3d6d3a7cd9278cb5726676a9b1ae8d57f020 GIT binary patch literal 2584 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 SvM370)qcx}=+OS>#Qy~?gQRQ# literal 0 HcmV?d00001 From 100eee6f360126de1d4b2d5cae2c596de284894b Mon Sep 17 00:00:00 2001 From: Rajesh Vasa Date: Thu, 19 Nov 2026 20:05:07 -0600 Subject: [PATCH 2/3] Share the trust manager, warn when SSL validation is disabled, and document HTTP/2 support Address review feedback on gh-1196: - Move DisabledValidationTrustManager to its own package-private class, shared by HttpClient5FeignConfiguration and Http2ClientFeignConfiguration. It extends X509ExtendedTrustManager, so the JDK HttpClient also skips hostname verification; Apache HttpClient 5 already skipped it with its no-op hostname verifier. - Log a warning when the HTTP/2 client is created with disable-ssl-validation=true. - Document that the property applies to the HTTP/2 client too, in the property description and the HTTP clients section. Signed-off-by: Rajesh Vasa --- .../ROOT/pages/spring-cloud-openfeign.adoc | 2 + docs/modules/ROOT/partials/_configprops.adoc | 2 +- .../DisabledValidationTrustManager.java | 68 +++++++++++++++++++ .../Http2ClientFeignConfiguration.java | 46 +------------ .../HttpClient5FeignConfiguration.java | 19 ------ .../support/FeignHttpClientProperties.java | 5 ++ ...nHttp2ClientDisableSslValidationTests.java | 14 +++- 7 files changed, 90 insertions(+), 66 deletions(-) create mode 100644 spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java diff --git a/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc b/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc index 1aec17f0a..f0f73df7a 100644 --- a/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc @@ -177,6 +177,8 @@ Apache HttpClient 5 uses a connection pool to reuse persistent HTTP connections |=== +`spring.cloud.openfeign.httpclient.disable-ssl-validation` applies to both Apache HttpClient 5 and the HTTP/2 (Java `HttpClient`) client. When it is `true`, server certificates and host names are not verified, and the HTTP/2 client logs a warning when it is created. Use it only for testing, never in production. + If you can not configure Apache HttpClient 5 by using properties, there is an `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` interface for programmatic configuration. Similarly, to configure the `HttpClientConnectionManager`, you can use `HttpClient5FeignConfiguration.HttpClientConnectionManagerBuilderCustomizer`. Both usages are shown in the example below. TIP: Apache HTTP Components `5.4` have changed defaults in the HttpClient relating to HTTP/1.1 TLS upgrades. Most proxy servers handle upgrades without issue, however, you may encounter issues with Envoy or Istio. If you need to restore previous behaviour, you can use `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` to do it, as shown in the example below. diff --git a/docs/modules/ROOT/partials/_configprops.adoc b/docs/modules/ROOT/partials/_configprops.adoc index eb112d630..f87ba4dec 100644 --- a/docs/modules/ROOT/partials/_configprops.adoc +++ b/docs/modules/ROOT/partials/_configprops.adoc @@ -92,7 +92,7 @@ |spring.cloud.openfeign.http2client.enabled | `+++false+++` | Enables the use of the Java11 HTTP 2 Client by Feign. |spring.cloud.openfeign.httpclient.connection-timeout | `+++2000+++` | |spring.cloud.openfeign.httpclient.connection-timer-repeat | `+++3000+++` | -|spring.cloud.openfeign.httpclient.disable-ssl-validation | `+++false+++` | +|spring.cloud.openfeign.httpclient.disable-ssl-validation | `+++false+++` | Whether to disable SSL validation: server certificates and host names are not verified. Applies to the Apache HttpClient 5 and the HTTP/2 (Java HttpClient) clients. Use only for testing. |spring.cloud.openfeign.httpclient.follow-redirects | `+++true+++` | |spring.cloud.openfeign.httpclient.hc5.connection-request-timeout | `+++3+++` | Default value for connection request timeout. |spring.cloud.openfeign.httpclient.hc5.connection-request-timeout-unit | `+++minutes+++` | Default value for connection request timeout unit. diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java new file mode 100644 index 000000000..8abe4423a --- /dev/null +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.openfeign.clientconfig; + +import java.net.Socket; +import java.security.cert.X509Certificate; + +import javax.net.ssl.SSLEngine; +import javax.net.ssl.X509ExtendedTrustManager; + +/** + * Trusts every certificate, for + * {@code spring.cloud.openfeign.httpclient.disable-ssl-validation}. Shared by + * {@link HttpClient5FeignConfiguration} and {@link Http2ClientFeignConfiguration}. + *

+ * It extends {@link X509ExtendedTrustManager} because the JDK + * {@link java.net.http.HttpClient} delegates hostname verification to an extended trust + * manager, so this also skips hostname verification there, like the Apache HttpClient 5 + * configuration does with its no-op hostname verifier. + * + * @author Rajesh Vasa + */ +final class DisabledValidationTrustManager extends X509ExtendedTrustManager { + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) { + } + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) { + } + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + +} diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java index 969379136..d5122ae5d 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java @@ -16,19 +16,15 @@ package org.springframework.cloud.openfeign.clientconfig; -import java.net.Socket; import java.net.http.HttpClient; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.security.cert.X509Certificate; import java.time.Duration; import java.util.List; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; import javax.net.ssl.TrustManager; -import javax.net.ssl.X509ExtendedTrustManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -61,6 +57,9 @@ public HttpClient.Builder httpClientBuilder(FeignHttpClientProperties httpClient .version(HttpClient.Version.valueOf(httpClientProperties.getHttp2().getVersion())) .connectTimeout(Duration.ofMillis(httpClientProperties.getConnectionTimeout())); if (httpClientProperties.isDisableSslValidation()) { + LOG.warn("SSL validation is disabled for the HTTP/2 client " + + "(spring.cloud.openfeign.httpclient.disable-ssl-validation=true): server certificates and " + + "host names are not verified. Do not use this in production."); try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { new DisabledValidationTrustManager() }, new SecureRandom()); @@ -79,43 +78,4 @@ public HttpClient httpClient(HttpClient.Builder httpClientBuilder, List response = send(context.getBean(HttpClient.class)); assertThat(response.statusCode()).isEqualTo(200); assertThat(response.body()).isEqualTo("ok"); + assertThat(output).containsOnlyOnce(WARNING); } } @Test - void rejectsSelfSignedServerByDefault() { + void rejectsSelfSignedServerByDefault(CapturedOutput output) { try (ConfigurableApplicationContext context = createContext(false)) { HttpClient httpClient = context.getBean(HttpClient.class); assertThatExceptionOfType(SSLHandshakeException.class).isThrownBy(() -> send(httpClient)); + assertThat(output).doesNotContain(WARNING); } } From 88807c0fb8768c6ed8095a8f2d56712043fe95d1 Mon Sep 17 00:00:00 2001 From: Rajesh Vasa Date: Mon, 23 Nov 2026 23:06:03 -0600 Subject: [PATCH 3/3] Give the HTTP/2 client its own disable-ssl-validation property Address review feedback on gh-1196: to follow the documented httpclient.hc5.* / httpclient.http2.* convention, the HTTP/2 client now uses spring.cloud.openfeign.httpclient.http2.disable-ssl-validation instead of the top-level property. The top-level httpclient.disable-ssl-validation again applies only to Apache HttpClient 5, so existing users who set it do not silently lose validation on the HTTP/2 client. Update the docs and configuration properties table, and add a test that the top-level property does not affect the HTTP/2 client. Signed-off-by: Rajesh Vasa --- .../ROOT/pages/spring-cloud-openfeign.adoc | 2 +- docs/modules/ROOT/partials/_configprops.adoc | 3 ++- .../DisabledValidationTrustManager.java | 7 ++--- .../Http2ClientFeignConfiguration.java | 4 +-- .../support/FeignHttpClientProperties.java | 19 +++++++++---- ...nHttp2ClientDisableSslValidationTests.java | 27 ++++++++++++++----- 6 files changed, 44 insertions(+), 18 deletions(-) diff --git a/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc b/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc index f0f73df7a..6195cf615 100644 --- a/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc @@ -177,7 +177,7 @@ Apache HttpClient 5 uses a connection pool to reuse persistent HTTP connections |=== -`spring.cloud.openfeign.httpclient.disable-ssl-validation` applies to both Apache HttpClient 5 and the HTTP/2 (Java `HttpClient`) client. When it is `true`, server certificates and host names are not verified, and the HTTP/2 client logs a warning when it is created. Use it only for testing, never in production. +To disable SSL validation for the HTTP/2 (Java `HttpClient`) client, set `spring.cloud.openfeign.httpclient.http2.disable-ssl-validation` to `true`. Server certificates and host names are then not verified, and the client logs a warning when it is created. Use it only for testing, never in production. This property is separate from `spring.cloud.openfeign.httpclient.disable-ssl-validation`, which does not affect the HTTP/2 client. If you can not configure Apache HttpClient 5 by using properties, there is an `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` interface for programmatic configuration. Similarly, to configure the `HttpClientConnectionManager`, you can use `HttpClient5FeignConfiguration.HttpClientConnectionManagerBuilderCustomizer`. Both usages are shown in the example below. diff --git a/docs/modules/ROOT/partials/_configprops.adoc b/docs/modules/ROOT/partials/_configprops.adoc index f87ba4dec..6ef1600b8 100644 --- a/docs/modules/ROOT/partials/_configprops.adoc +++ b/docs/modules/ROOT/partials/_configprops.adoc @@ -92,7 +92,7 @@ |spring.cloud.openfeign.http2client.enabled | `+++false+++` | Enables the use of the Java11 HTTP 2 Client by Feign. |spring.cloud.openfeign.httpclient.connection-timeout | `+++2000+++` | |spring.cloud.openfeign.httpclient.connection-timer-repeat | `+++3000+++` | -|spring.cloud.openfeign.httpclient.disable-ssl-validation | `+++false+++` | Whether to disable SSL validation: server certificates and host names are not verified. Applies to the Apache HttpClient 5 and the HTTP/2 (Java HttpClient) clients. Use only for testing. +|spring.cloud.openfeign.httpclient.disable-ssl-validation | `+++false+++` | |spring.cloud.openfeign.httpclient.follow-redirects | `+++true+++` | |spring.cloud.openfeign.httpclient.hc5.connection-request-timeout | `+++3+++` | Default value for connection request timeout. |spring.cloud.openfeign.httpclient.hc5.connection-request-timeout-unit | `+++minutes+++` | Default value for connection request timeout unit. @@ -101,6 +101,7 @@ |spring.cloud.openfeign.httpclient.hc5.pool-reuse-policy | `+++fifo+++` | Pool connection re-use policies. |spring.cloud.openfeign.httpclient.hc5.socket-timeout | `+++5+++` | Default value for socket timeout. |spring.cloud.openfeign.httpclient.hc5.socket-timeout-unit | `+++seconds+++` | Default value for socket timeout unit. +|spring.cloud.openfeign.httpclient.http2.disable-ssl-validation | `+++false+++` | Whether to disable SSL validation for the HTTP/2 client: server certificates and host names are not verified. Use only for testing. |spring.cloud.openfeign.httpclient.http2.version | `+++HTTP_2+++` | Configure the protocols used by this client to communicate with remote servers. Uses {@link String} value of {@link HttpClient.Version}. |spring.cloud.openfeign.httpclient.max-connections | `+++200+++` | |spring.cloud.openfeign.httpclient.max-connections-per-route | `+++50+++` | diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java index 8abe4423a..e3b8ee5dc 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java @@ -23,9 +23,10 @@ import javax.net.ssl.X509ExtendedTrustManager; /** - * Trusts every certificate, for - * {@code spring.cloud.openfeign.httpclient.disable-ssl-validation}. Shared by - * {@link HttpClient5FeignConfiguration} and {@link Http2ClientFeignConfiguration}. + * Trusts every certificate. Used by {@link HttpClient5FeignConfiguration} for + * {@code spring.cloud.openfeign.httpclient.disable-ssl-validation} and by + * {@link Http2ClientFeignConfiguration} for + * {@code spring.cloud.openfeign.httpclient.http2.disable-ssl-validation}. *

* It extends {@link X509ExtendedTrustManager} because the JDK * {@link java.net.http.HttpClient} delegates hostname verification to an extended trust diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java index d5122ae5d..fa13c64aa 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/Http2ClientFeignConfiguration.java @@ -56,9 +56,9 @@ public HttpClient.Builder httpClientBuilder(FeignHttpClientProperties httpClient httpClientProperties.isFollowRedirects() ? HttpClient.Redirect.ALWAYS : HttpClient.Redirect.NEVER) .version(HttpClient.Version.valueOf(httpClientProperties.getHttp2().getVersion())) .connectTimeout(Duration.ofMillis(httpClientProperties.getConnectionTimeout())); - if (httpClientProperties.isDisableSslValidation()) { + if (httpClientProperties.getHttp2().isDisableSslValidation()) { LOG.warn("SSL validation is disabled for the HTTP/2 client " - + "(spring.cloud.openfeign.httpclient.disable-ssl-validation=true): server certificates and " + + "(spring.cloud.openfeign.httpclient.http2.disable-ssl-validation=true): server certificates and " + "host names are not verified. Do not use this in production."); try { SSLContext sslContext = SSLContext.getInstance("TLS"); diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/FeignHttpClientProperties.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/FeignHttpClientProperties.java index 7e0b0f391..af0386b2c 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/FeignHttpClientProperties.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/FeignHttpClientProperties.java @@ -72,11 +72,6 @@ public class FeignHttpClientProperties { */ public static final int DEFAULT_CONNECTION_TIMER_REPEAT = 3000; - /** - * Whether to disable SSL validation: server certificates and host names are not - * verified. Applies to the Apache HttpClient 5 and the HTTP/2 (Java HttpClient) - * clients. Use only for testing. - */ private boolean disableSslValidation = DEFAULT_DISABLE_SSL_VALIDATION; private int maxConnections = DEFAULT_MAX_CONNECTIONS; @@ -342,6 +337,12 @@ public static class Http2Properties { */ private String version = "HTTP_2"; + /** + * Whether to disable SSL validation for the HTTP/2 client: server certificates + * and host names are not verified. Use only for testing. + */ + private boolean disableSslValidation = DEFAULT_DISABLE_SSL_VALIDATION; + public String getVersion() { return version; } @@ -350,6 +351,14 @@ public void setVersion(String version) { this.version = version; } + public boolean isDisableSslValidation() { + return disableSslValidation; + } + + public void setDisableSslValidation(boolean disableSslValidation) { + this.disableSslValidation = disableSslValidation; + } + } } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttp2ClientDisableSslValidationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttp2ClientDisableSslValidationTests.java index 2c0324206..c0b162577 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttp2ClientDisableSslValidationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignHttp2ClientDisableSslValidationTests.java @@ -46,10 +46,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** - * Tests that {@code spring.cloud.openfeign.httpclient.disable-ssl-validation} applies to - * the HTTP/2 client. The server uses a self-signed certificate issued for - * {@code untrusted.invalid}, so both certificate validation and hostname verification - * fail unless SSL validation is disabled, and a warning is logged when it is. + * Tests for {@code spring.cloud.openfeign.httpclient.http2.disable-ssl-validation}. The + * server uses a self-signed certificate issued for {@code untrusted.invalid}, so both + * certificate validation and hostname verification fail unless SSL validation is + * disabled, and a warning is logged when it is. The top-level + * {@code spring.cloud.openfeign.httpclient.disable-ssl-validation} property does not + * affect the HTTP/2 client. * * @author Rajesh Vasa */ @@ -113,11 +115,24 @@ void rejectsSelfSignedServerByDefault(CapturedOutput output) { } } - private static ConfigurableApplicationContext createContext(boolean disableSslValidation) { + @Test + void ignoresTopLevelDisableSslValidationProperty(CapturedOutput output) { + try (ConfigurableApplicationContext context = createContext(false, + "spring.cloud.openfeign.httpclient.disable-ssl-validation=true")) { + HttpClient httpClient = context.getBean(HttpClient.class); + + assertThatExceptionOfType(SSLHandshakeException.class).isThrownBy(() -> send(httpClient)); + assertThat(output).doesNotContain(WARNING); + } + } + + private static ConfigurableApplicationContext createContext(boolean disableSslValidation, + String... extraProperties) { return new SpringApplicationBuilder() .properties("spring.cloud.openfeign.http2client.enabled=true", "spring.cloud.openfeign.httpclient.http2.version=HTTP_1_1", - "spring.cloud.openfeign.httpclient.disable-ssl-validation=" + disableSslValidation) + "spring.cloud.openfeign.httpclient.http2.disable-ssl-validation=" + disableSslValidation) + .properties(extraProperties) .web(WebApplicationType.NONE) .sources(FeignAutoConfiguration.class) .run();