Skip to content

Commit 71831e4

Browse files
committed
Move off deprecated API.
See gh-874
1 parent da138dd commit 71831e4

File tree

8 files changed

+41
-34
lines changed

8 files changed

+41
-34
lines changed

spring-vault-core/src/main/java/org/springframework/vault/authentication/DefaultGcpCredentialAccessors.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
1919

2020
import org.springframework.util.Assert;
21-
import org.springframework.util.StringUtils;
21+
import org.springframework.util.ObjectUtils;
2222

2323
/**
2424
* Default implementation of{@link GcpProjectIdAccessor} and
@@ -34,7 +34,7 @@ enum DefaultGcpCredentialAccessors implements GcpProjectIdAccessor, GcpServiceAc
3434
INSTANCE;
3535

3636
/**
37-
* Get a the service account id (email) to be placed in the signed JWT.
37+
* Get the service account id (email) to be placed in the signed JWT.
3838
* @param credential credential object to obtain the service account id from.
3939
* @return the service account id to use.
4040
*/
@@ -49,7 +49,7 @@ public String getServiceAccountId(GoogleCredential credential) {
4949
}
5050

5151
/**
52-
* Get a the GCP project id to used in Google Cloud IAM API calls.
52+
* Get the GCP project id to used in Google Cloud IAM API calls.
5353
* @param credential the credential object to obtain the project id from.
5454
* @return the service account id to use.
5555
*/
@@ -58,7 +58,7 @@ public String getProjectId(GoogleCredential credential) {
5858

5959
Assert.notNull(credential, "GoogleCredential must not be null");
6060

61-
return StringUtils.isEmpty(credential.getServiceAccountProjectId()) ? "-"
61+
return ObjectUtils.isEmpty(credential.getServiceAccountProjectId()) ? "-"
6262
: credential.getServiceAccountProjectId();
6363
}
6464

spring-vault-core/src/main/java/org/springframework/vault/client/ClientHttpConnectorFactory.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
import io.netty.channel.ChannelOption;
2727
import io.netty.handler.ssl.SslContextBuilder;
28+
import org.apache.hc.client5.http.config.ConnectionConfig;
2829
import org.apache.hc.client5.http.config.RequestConfig;
2930
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
3031
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
31-
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
3232
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
3333
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
3434
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
@@ -54,10 +54,8 @@
5454

5555
/**
5656
* Factory for {@link ClientHttpConnector} that supports
57-
* {@link ReactorClientHttpConnector} and {@link JettyClientHttpConnector}.
58-
*
59-
* This factory configures a {@link ClientHttpConnector} depending on the available
60-
* dependencies.
57+
* {@link ReactorClientHttpConnector} and {@link JettyClientHttpConnector}. This factory
58+
* configures a {@link ClientHttpConnector} depending on the available dependencies.
6159
*
6260
* @author Mark Paluch
6361
* @author Ryan Gow
@@ -208,6 +206,24 @@ public static HttpAsyncClientBuilder createHttpAsyncClientBuilder(ClientOptions
208206
httpClientBuilder.setRoutePlanner(
209207
new SystemDefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));
210208

209+
Timeout readTimeout = Timeout.ofMilliseconds(options.getReadTimeout().toMillis());
210+
Timeout connectTimeout = Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis());
211+
212+
ConnectionConfig connectionConfig = ConnectionConfig.custom()
213+
.setConnectTimeout(connectTimeout) //
214+
.setSocketTimeout(readTimeout) //
215+
.build();
216+
217+
RequestConfig requestConfig = RequestConfig.custom()
218+
.setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis()))
219+
.setAuthenticationEnabled(true) //
220+
.setRedirectsEnabled(true)
221+
.build();
222+
223+
PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder //
224+
.create()
225+
.setDefaultConnectionConfig(connectionConfig);
226+
211227
if (hasSslConfiguration(sslConfiguration)) {
212228

213229
SSLContext sslContext = getSSLContext(sslConfiguration);
@@ -229,21 +245,11 @@ public static HttpAsyncClientBuilder createHttpAsyncClientBuilder(ClientOptions
229245
}
230246
}, null);
231247

232-
PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder //
233-
.create()
234-
.setTlsStrategy(tlsStrategy) //
235-
.build(); //
236-
httpClientBuilder.setConnectionManager(connectionManager);
248+
connectionManagerBuilder.setTlsStrategy(tlsStrategy);
237249
}
238250

239-
RequestConfig requestConfig = RequestConfig.custom()
240-
.setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis()))
241-
.setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis()))
242-
.setAuthenticationEnabled(true) //
243-
.setRedirectsEnabled(true)
244-
.build();
245-
246251
httpClientBuilder.setDefaultRequestConfig(requestConfig);
252+
httpClientBuilder.setConnectionManager(connectionManagerBuilder.build());
247253

248254
return httpClientBuilder;
249255
}

spring-vault-core/src/main/java/org/springframework/vault/repository/convert/MappingVaultConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ private <S> S read(VaultPersistentEntity<S> entity, SecretDocument source) {
176176
Object idValue;
177177

178178
if (entity.requiresPropertyPopulation()) {
179-
if (idProperty != null && !entity.isConstructorArgument(idProperty)
180-
&& documentAccessor.hasValue(idProperty)) {
179+
if (idProperty != null && !entity.isCreatorArgument(idProperty) && documentAccessor.hasValue(idProperty)) {
181180

182181
idValue = readIdValue(idProperty, documentAccessor);
183182
accessor.setProperty(idProperty, idValue);
@@ -210,7 +209,7 @@ private void readProperties(VaultPersistentEntity<?> entity, PersistentPropertyA
210209
continue;
211210
}
212211

213-
if (entity.isConstructorArgument(prop) || !documentAccessor.hasValue(prop)) {
212+
if (entity.isCreatorArgument(prop) || !documentAccessor.hasValue(prop)) {
214213
continue;
215214
}
216215

spring-vault-core/src/test/java/org/springframework/vault/client/ReactiveVaultClientsIntegrationTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ void shouldUseVaultEndpointProvider() {
5151

5252
client.get()
5353
.uri("/sys/health")
54-
.exchange()
55-
.flatMap(it -> it.bodyToMono(String.class))
54+
.exchangeToMono(it -> it.bodyToMono(String.class))
5655
.as(StepVerifier::create)
5756
.consumeNextWith(actual -> {
5857
assertThat(actual).contains("initialized").contains("standby");
@@ -61,8 +60,7 @@ void shouldUseVaultEndpointProvider() {
6160

6261
client.get()
6362
.uri("sys/health")
64-
.exchange()
65-
.flatMap(it -> it.bodyToMono(String.class))
63+
.exchangeToMono(it -> it.bodyToMono(String.class))
6664
.as(StepVerifier::create)
6765
.consumeNextWith(actual -> {
6866
assertThat(actual).contains("initialized").contains("standby");

spring-vault-core/src/test/java/org/springframework/vault/config/AbstractReactiveVaultConfigurationUnitTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ void shouldApplyCustomizerToWebClientFactory() {
4848
WebClientFactory factory = context.getBean(WebClientFactory.class);
4949
WebClient webClient = factory.create();
5050

51-
webClient.get().uri("/foo").exchange().as(StepVerifier::create).verifyError(CustomizedSignal.class);
51+
webClient.get()
52+
.uri("/foo")
53+
.exchangeToMono(it -> it.bodyToMono(String.class))
54+
.as(StepVerifier::create)
55+
.verifyError(CustomizedSignal.class);
5256
}
5357

5458
@Test

spring-vault-core/src/test/java/org/springframework/vault/core/VaultNamespaceSecretIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ void shouldReportReactiveInitialized() {
213213
return webClient.get()
214214
.uri("sys/init")
215215
.header(VaultHttpHeaders.VAULT_NAMESPACE, "")
216-
.exchange()
217-
.flatMap(it -> it.bodyToMono(Map.class));
216+
.exchangeToMono(it -> it.bodyToMono(Map.class));
218217
})
219218
.as(StepVerifier::create)
220219
.assertNext(actual -> assertThat(actual).containsEntry("initialized", true))

spring-vault-core/src/test/java/org/springframework/vault/support/CertificateUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ void getX509CertificateShouldReturnCertificate() {
5151

5252
X509Certificate x509Certificate = this.certificate.getX509Certificate();
5353

54-
assertThat(x509Certificate.getSubjectDN().getName()).isEqualTo("CN=hello.example.com");
54+
assertThat(x509Certificate.getSubjectX500Principal().getName()).isEqualTo("CN=hello.example.com");
5555
}
5656

5757
@Test
5858
void getX509IssuerCertificateShouldReturnCertificate() {
5959

6060
X509Certificate x509Certificate = this.certificate.getX509IssuerCertificate();
6161

62-
assertThat(x509Certificate.getSubjectDN().getName()).startsWith("CN=Intermediate CA Certificate");
62+
assertThat(x509Certificate.getSubjectX500Principal().getName()).startsWith("CN=Intermediate CA Certificate");
6363
}
6464

6565
@Test

spring-vault-core/src/test/java/org/springframework/vault/support/PemObjectUnitTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void shouldDecodeX509Certificate() throws IOException {
111111
PemObject pemObject = PemObject.parseFirst(content);
112112

113113
assertThat(pemObject.isCertificate()).isTrue();
114-
assertThat(pemObject.getCertificate().getSubjectDN().getName()).contains("O=spring-cloud-vault-config");
114+
assertThat(pemObject.getCertificate().getSubjectX500Principal().getName())
115+
.contains("O=spring-cloud-vault-config");
115116
}
116117

117118
}

0 commit comments

Comments
 (0)