Move off deprecated API.

See gh-874
This commit is contained in:
Mark Paluch
2024-08-07 08:56:36 +02:00
parent 48c904e3a0
commit 183b983558
9 changed files with 44 additions and 37 deletions

View File

@@ -18,7 +18,7 @@ package org.springframework.vault.authentication;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;
/**
* Default implementation of{@link GcpProjectIdAccessor} and
@@ -34,7 +34,7 @@ enum DefaultGcpCredentialAccessors implements GcpProjectIdAccessor, GcpServiceAc
INSTANCE;
/**
* Get a the service account id (email) to be placed in the signed JWT.
* Get the service account id (email) to be placed in the signed JWT.
* @param credential credential object to obtain the service account id from.
* @return the service account id to use.
*/
@@ -49,7 +49,7 @@ enum DefaultGcpCredentialAccessors implements GcpProjectIdAccessor, GcpServiceAc
}
/**
* Get a the GCP project id to used in Google Cloud IAM API calls.
* Get the GCP project id to used in Google Cloud IAM API calls.
* @param credential the credential object to obtain the project id from.
* @return the service account id to use.
*/
@@ -58,7 +58,7 @@ enum DefaultGcpCredentialAccessors implements GcpProjectIdAccessor, GcpServiceAc
Assert.notNull(credential, "GoogleCredential must not be null");
return StringUtils.isEmpty(credential.getServiceAccountProjectId()) ? "-"
return ObjectUtils.isEmpty(credential.getServiceAccountProjectId()) ? "-"
: credential.getServiceAccountProjectId();
}

View File

@@ -25,10 +25,10 @@ import javax.net.ssl.SSLParameters;
import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.SslContextBuilder;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
@@ -54,10 +54,8 @@ import static org.springframework.vault.client.ClientHttpRequestFactoryFactory.*
/**
* Factory for {@link ClientHttpConnector} that supports
* {@link ReactorClientHttpConnector} and {@link JettyClientHttpConnector}.
*
* This factory configures a {@link ClientHttpConnector} depending on the available
* dependencies.
* {@link ReactorClientHttpConnector} and {@link JettyClientHttpConnector}. This factory
* configures a {@link ClientHttpConnector} depending on the available dependencies.
*
* @author Mark Paluch
* @author Ryan Gow
@@ -208,6 +206,24 @@ public class ClientHttpConnectorFactory {
httpClientBuilder.setRoutePlanner(
new SystemDefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));
Timeout readTimeout = Timeout.ofMilliseconds(options.getReadTimeout().toMillis());
Timeout connectTimeout = Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis());
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setConnectTimeout(connectTimeout) //
.setSocketTimeout(readTimeout) //
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis()))
.setAuthenticationEnabled(true) //
.setRedirectsEnabled(true)
.build();
PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder //
.create()
.setDefaultConnectionConfig(connectionConfig);
if (hasSslConfiguration(sslConfiguration)) {
SSLContext sslContext = getSSLContext(sslConfiguration);
@@ -229,21 +245,11 @@ public class ClientHttpConnectorFactory {
}
}, null);
PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder //
.create()
.setTlsStrategy(tlsStrategy) //
.build(); //
httpClientBuilder.setConnectionManager(connectionManager);
connectionManagerBuilder.setTlsStrategy(tlsStrategy);
}
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis()))
.setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis()))
.setAuthenticationEnabled(true) //
.setRedirectsEnabled(true)
.build();
httpClientBuilder.setDefaultRequestConfig(requestConfig);
httpClientBuilder.setConnectionManager(connectionManagerBuilder.build());
return httpClientBuilder;
}

View File

@@ -176,8 +176,7 @@ public class MappingVaultConverter extends AbstractVaultConverter {
Object idValue;
if (entity.requiresPropertyPopulation()) {
if (idProperty != null && !entity.isConstructorArgument(idProperty)
&& documentAccessor.hasValue(idProperty)) {
if (idProperty != null && !entity.isCreatorArgument(idProperty) && documentAccessor.hasValue(idProperty)) {
idValue = readIdValue(idProperty, documentAccessor);
accessor.setProperty(idProperty, idValue);
@@ -210,7 +209,7 @@ public class MappingVaultConverter extends AbstractVaultConverter {
continue;
}
if (entity.isConstructorArgument(prop) || !documentAccessor.hasValue(prop)) {
if (entity.isCreatorArgument(prop) || !documentAccessor.hasValue(prop)) {
continue;
}

View File

@@ -51,8 +51,7 @@ class ReactiveVaultClientsIntegrationTests extends IntegrationTestSupport {
client.get()
.uri("/sys/health")
.exchange()
.flatMap(it -> it.bodyToMono(String.class))
.exchangeToMono(it -> it.bodyToMono(String.class))
.as(StepVerifier::create)
.consumeNextWith(actual -> {
assertThat(actual).contains("initialized").contains("standby");
@@ -61,8 +60,7 @@ class ReactiveVaultClientsIntegrationTests extends IntegrationTestSupport {
client.get()
.uri("sys/health")
.exchange()
.flatMap(it -> it.bodyToMono(String.class))
.exchangeToMono(it -> it.bodyToMono(String.class))
.as(StepVerifier::create)
.consumeNextWith(actual -> {
assertThat(actual).contains("initialized").contains("standby");

View File

@@ -48,7 +48,11 @@ class AbstractReactiveVaultConfigurationUnitTests {
WebClientFactory factory = context.getBean(WebClientFactory.class);
WebClient webClient = factory.create();
webClient.get().uri("/foo").exchange().as(StepVerifier::create).verifyError(CustomizedSignal.class);
webClient.get()
.uri("/foo")
.exchangeToMono(it -> it.bodyToMono(String.class))
.as(StepVerifier::create)
.verifyError(CustomizedSignal.class);
}
@Test

View File

@@ -213,8 +213,7 @@ class VaultNamespaceSecretIntegrationTests extends IntegrationTestSupport {
return webClient.get()
.uri("sys/init")
.header(VaultHttpHeaders.VAULT_NAMESPACE, "")
.exchange()
.flatMap(it -> it.bodyToMono(Map.class));
.exchangeToMono(it -> it.bodyToMono(Map.class));
})
.as(StepVerifier::create)
.assertNext(actual -> assertThat(actual).containsEntry("initialized", true))

View File

@@ -127,9 +127,9 @@ class CertificateBundleUnitTests {
}
@ParameterizedTest
@ValueSource(strings = {"certificate-response-rsa-pem.json", "certificate-response-rsa-der.json",
@ValueSource(strings = { "certificate-response-rsa-pem.json", "certificate-response-rsa-der.json",
"certificate-response-rsa-pembundle.json", "certificate-response-ec-pem.json",
"certificate-response-ec-der.json", "certificate-response-ec-pembundle.json"})
"certificate-response-ec-der.json", "certificate-response-ec-pembundle.json" })
void createKeystore(String path) {
CertificateBundle bundle = loadCertificateBundle(path);
@@ -144,7 +144,7 @@ class CertificateBundleUnitTests {
}
@ParameterizedTest
@ValueSource(strings = {"certificate-response-rsa-pem-pkcs8.json", "certificate-response-ec-pem-pkcs8.json"})
@ValueSource(strings = { "certificate-response-rsa-pem-pkcs8.json", "certificate-response-ec-pem-pkcs8.json" })
void shouldCreateKeystore(String path) {
CertificateBundle bundle = loadCertificateBundle(path);

View File

@@ -51,7 +51,7 @@ class CertificateUnitTests {
X509Certificate x509Certificate = this.certificate.getX509Certificate();
assertThat(x509Certificate.getSubjectDN().getName()).isEqualTo("CN=hello.example.com");
assertThat(x509Certificate.getSubjectX500Principal().getName()).isEqualTo("CN=hello.example.com");
}
@Test
@@ -59,7 +59,7 @@ class CertificateUnitTests {
X509Certificate x509Certificate = this.certificate.getX509IssuerCertificate();
assertThat(x509Certificate.getSubjectDN().getName()).startsWith("CN=Intermediate CA Certificate");
assertThat(x509Certificate.getSubjectX500Principal().getName()).startsWith("CN=Intermediate CA Certificate");
}
@Test

View File

@@ -111,7 +111,8 @@ class PemObjectUnitTests {
PemObject pemObject = PemObject.parseFirst(content);
assertThat(pemObject.isCertificate()).isTrue();
assertThat(pemObject.getCertificate().getSubjectDN().getName()).contains("O=spring-cloud-vault-config");
assertThat(pemObject.getCertificate().getSubjectX500Principal().getName())
.contains("O=spring-cloud-vault-config");
}
}