Remove support for Netty4ClientHttpRequestFactory.

Closes gh-680
This commit is contained in:
Mark Paluch
2022-01-05 09:54:04 +01:00
parent e25423716c
commit 2c708e8835
4 changed files with 3 additions and 141 deletions

View File

@@ -43,8 +43,6 @@ import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509ExtendedKeyManager;
import javax.net.ssl.X509TrustManager;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient.Builder;
import org.apache.commons.logging.Log;
@@ -59,7 +57,6 @@ import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.lang.Nullable;
@@ -91,9 +88,6 @@ public class ClientHttpRequestFactoryFactory {
private static final boolean OKHTTP3_PRESENT = isPresent("okhttp3.OkHttpClient");
private static final boolean NETTY_PRESENT = isPresent("io.netty.channel.nio.NioEventLoopGroup",
"io.netty.handler.ssl.SslContext", "io.netty.handler.codec.http.HttpClientCodec");
/**
* Checks for presence of all {@code classNames} using this class' classloader.
* @param classNames
@@ -133,10 +127,6 @@ public class ClientHttpRequestFactoryFactory {
if (OKHTTP3_PRESENT) {
return OkHttp3.usingOkHttp3(options, sslConfiguration);
}
if (NETTY_PRESENT) {
return Netty.usingNetty(options, sslConfiguration);
}
}
catch (GeneralSecurityException | IOException e) {
throw new IllegalStateException(e);
@@ -387,55 +377,6 @@ public class ClientHttpRequestFactoryFactory {
}
/**
* {@link ClientHttpRequestFactory} for Netty.
*
* @author Mark Paluch
*/
static class Netty {
static ClientHttpRequestFactory usingNetty(ClientOptions options, SslConfiguration sslConfiguration)
throws GeneralSecurityException, IOException {
Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();
if (hasSslConfiguration(sslConfiguration)) {
SslContextBuilder sslContextBuilder = SslContextBuilder //
.forClient();
if (sslConfiguration.getTrustStoreConfiguration().isPresent()) {
sslContextBuilder
.trustManager(createTrustManagerFactory(sslConfiguration.getTrustStoreConfiguration()));
}
if (sslConfiguration.getKeyStoreConfiguration().isPresent()) {
sslContextBuilder.keyManager(createKeyManagerFactory(sslConfiguration.getKeyStoreConfiguration(),
sslConfiguration.getKeyConfiguration()));
}
if (!sslConfiguration.getEnabledProtocols().isEmpty()) {
sslContextBuilder.protocols(sslConfiguration.getEnabledProtocols());
}
if (!sslConfiguration.getEnabledCipherSuites().isEmpty()) {
sslContextBuilder.ciphers(sslConfiguration.getEnabledCipherSuites());
}
requestFactory.setSslContext(sslContextBuilder.sslProvider(SslProvider.JDK).build());
}
requestFactory.setConnectTimeout(Math.toIntExact(options.getConnectionTimeout().toMillis()));
requestFactory.setReadTimeout(Math.toIntExact(options.getReadTimeout().toMillis()));
// eagerly initialize to ensure SSL context
requestFactory.afterPropertiesSet();
return requestFactory;
}
}
static class KeySelectingKeyManagerFactory extends KeyManagerFactory {
KeySelectingKeyManagerFactory(KeyManagerFactory factory, KeyConfiguration keyConfiguration) {

View File

@@ -28,11 +28,9 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.vault.client.ClientHttpRequestFactoryFactory.HttpComponents;
import org.springframework.vault.client.ClientHttpRequestFactoryFactory.Netty;
import org.springframework.vault.client.ClientHttpRequestFactoryFactory.OkHttp3;
import org.springframework.vault.support.ClientOptions;
import org.springframework.vault.support.SslConfiguration;
@@ -122,68 +120,6 @@ class ClientHttpRequestFactoryFactoryIntegrationTests {
((DisposableBean) factory).destroy();
}
@Test
void nettyClientWithoutSslConfigShouldWork() throws Exception {
ClientHttpRequestFactory factory = Netty.usingNetty(new ClientOptions(), SslConfiguration.unconfigured());
assertThat(ReflectionTestUtils.getField(factory, "sslContext")).isNotNull();
}
@Test
void nettyClientShouldWork() throws Exception {
ClientHttpRequestFactory factory = Netty.usingNetty(new ClientOptions(), Settings.createSslConfiguration());
((InitializingBean) factory).afterPropertiesSet();
RestTemplate template = new RestTemplate(factory);
String response = request(template);
assertThat(factory).isInstanceOf(Netty4ClientHttpRequestFactory.class);
assertThat(response).isNotNull().contains("initialized");
((DisposableBean) factory).destroy();
}
@Test
void nettyClientWithExplicitEnabledCipherSuitesShouldWork() throws Exception {
List<String> enabledCipherSuites = new ArrayList<String>();
enabledCipherSuites.add("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384");
enabledCipherSuites.add("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
ClientHttpRequestFactory factory = Netty.usingNetty(new ClientOptions(),
Settings.createSslConfiguration().withEnabledCipherSuites(enabledCipherSuites));
((InitializingBean) factory).afterPropertiesSet();
RestTemplate template = new RestTemplate(factory);
String response = request(template);
assertThat(factory).isInstanceOf(Netty4ClientHttpRequestFactory.class);
assertThat(response).isNotNull().contains("initialized");
((DisposableBean) factory).destroy();
}
@Test
void nettyClientWithExplicitEnabledProtocolsShouldWork() throws Exception {
List<String> enabledProtocols = new ArrayList<String>();
enabledProtocols.add("TLSv1.2");
ClientHttpRequestFactory factory = Netty.usingNetty(new ClientOptions(),
Settings.createSslConfiguration().withEnabledProtocols(enabledProtocols));
((InitializingBean) factory).afterPropertiesSet();
RestTemplate template = new RestTemplate(factory);
String response = request(template);
assertThat(factory).isInstanceOf(Netty4ClientHttpRequestFactory.class);
assertThat(response).isNotNull().contains("initialized");
((DisposableBean) factory).destroy();
}
@Test
void okHttp3ClientShouldWork() throws Exception {

View File

@@ -89,21 +89,18 @@ class EnvironmentVaultConfigurationUnitTests {
SslConfiguration sslConfiguration = this.configuration.sslConfiguration();
assertThat(sslConfiguration.getKeyStore()).isInstanceOf(ClassPathResource.class);
assertThat(new String(sslConfiguration.getKeyStoreConfiguration()
.getStorePassword()))
assertThat(new String(sslConfiguration.getKeyStoreConfiguration().getStorePassword()))
.isEqualTo("key store password");
assertThat(sslConfiguration.getTrustStore()).isInstanceOf(ClassPathResource.class);
assertThat(new String(sslConfiguration.getTrustStoreConfiguration()
.getStorePassword()))
assertThat(new String(sslConfiguration.getTrustStoreConfiguration().getStorePassword()))
.isEqualTo("trust store password");
assertThat(sslConfiguration.getEnabledProtocols()).containsExactly("TLSv1.2", "TLSv1.1");
assertThat(sslConfiguration.getEnabledCipherSuites()).containsExactly("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
this.configurableEnvironment.getPropertySources()
.remove(propertySource.getName());
this.configurableEnvironment.getPropertySources().remove(propertySource.getName());
}
}

View File

@@ -10,7 +10,6 @@ Spring Vault supports following HTTP imperative clients:
* Java's builtin `HttpURLConnection` (default client)
* Apache Http Components
* Netty
* OkHttp 3
Spring Vault's reactive integration supports the following reactive HTTP clients:
@@ -50,17 +49,6 @@ dependencies to your project. You can omit the version number if using
NOTE: Apache HttpClient's https://hc.apache.org/httpcomponents-client-4.5.x/logging.html[wire logging] can be enabled through logging configuration. Make sure to not accidentally enable wire logging as logs may expose traffic (tokens and secrets) between your application and Vault in plain text.
.Netty Dependency
====
[source, xml]
----
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
----
====
.Square OkHttp 3
====
[source, xml]