Skip to content

Commit

Permalink
3.0.x: Bump io.spring.javaformat from 0.0.35 to 0.0.39 (#149)
Browse files Browse the repository at this point in the history
* 3.0.x: Bump io.spring.javaformat from 0.0.35 to 0.0.39

Bumps [io.spring.javaformat](https://github.com/spring-io/spring-javaformat) from 0.0.35 to 0.0.39.
- [Release notes](https://github.com/spring-io/spring-javaformat/releases)
- [Commits](spring-io/spring-javaformat@v0.0.35...v0.0.39)

---
updated-dependencies:
- dependency-name: io.spring.javaformat
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Dependabot/gradle/3.0.x/io.spring.javaformat 0.0.39 (#161)

* 3.0.x: Bump io.spring.javaformat from 0.0.35 to 0.0.39

Bumps [io.spring.javaformat](https://github.com/spring-io/spring-javaformat) from 0.0.35 to 0.0.39.
- [Release notes](https://github.com/spring-io/spring-javaformat/releases)
- [Commits](spring-io/spring-javaformat@v0.0.35...v0.0.39)

---
updated-dependencies:
- dependency-name: io.spring.javaformat
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Formatting with new version

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alberto C. Ríos <albertoimpl@gmail.com>
  • Loading branch information
dependabot[bot] and Albertoimpl authored Sep 14, 2023
1 parent 2e22ff9 commit f9573e6
Show file tree
Hide file tree
Showing 54 changed files with 1,111 additions and 784 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pluginManagement {
plugins {
id 'io.spring.nohttp' version '0.0.11'
id 'io.spring.javaformat' version '0.0.35'
id 'io.spring.javaformat' version '0.0.39'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'org.springframework.boot' version '3.0.10'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ public static ClientHttpConnector create(ClientOptions options) {

if (usingCustomCerts(options)) {
TrustManagerFactory trustManagerFactory = sslCertificateUtils
.createTrustManagerFactory(options.getCaCertFiles());
.createTrustManagerFactory(options.getCaCertFiles());

httpClient = httpClient.secure((sslContextSpec) -> {
try {
sslContextSpec.sslContext(SslContextBuilder.forClient().sslProvider(SslProvider.JDK)
.trustManager(trustManagerFactory).build());
sslContextSpec.sslContext(SslContextBuilder.forClient()
.sslProvider(SslProvider.JDK)
.trustManager(trustManagerFactory)
.build());
}
catch (SSLException ex) {
logger.error("Error configuring HTTP connections using custom certs", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,29 @@ static ClientHttpRequestFactory usingHttpComponents(ClientOptions options) throw
SSLContext sslContext = sslCertificateUtils.getSSLContext(options.getCaCertFiles());
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder
.create().setSSLSocketFactory(sslSocketFactory).setDefaultSocketConfig(socketConfig).build();
.create()
.setSSLSocketFactory(sslSocketFactory)
.setDefaultSocketConfig(socketConfig)
.build();
httpClientBuilder.setConnectionManager(connectionManager);
}
else {
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);
PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder
.create().useSystemProperties().setSSLSocketFactory(sslSocketFactory)
.setDefaultSocketConfig(socketConfig).build();
.create()
.useSystemProperties()
.setSSLSocketFactory(sslSocketFactory)
.setDefaultSocketConfig(socketConfig)
.build();
httpClientBuilder.setConnectionManager(connectionManager);
}

RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setAuthenticationEnabled(true);

if (options.getConnectionTimeout() != null) {
requestConfigBuilder
.setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis()));
.setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis()));
}
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());

Expand All @@ -187,7 +193,7 @@ static ClientHttpRequestFactory usingOkHttp3(ClientOptions options) throws Gener

if (usingCustomCerts(options)) {
SSLSocketFactory socketFactory = sslCertificateUtils.getSSLContext(options.getCaCertFiles())
.getSocketFactory();
.getSocketFactory();
X509TrustManager trustManager = sslCertificateUtils.createTrustManager(options.getCaCertFiles());

builder.sslSocketFactory(socketFactory, trustManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SslCertificateUtils {
X509TrustManager getDefaultX509TrustManager() {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);

TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
Expand Down Expand Up @@ -86,7 +86,7 @@ TrustManagerFactory createTrustManagerFactory(String[] caCertFiles) {
KeyStore trustStore = loadCertificateStore(caCertFiles);

TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);

return trustManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp

private OAuth2AuthorizedClient authorizeClient() {
OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest
.withClientRegistrationId(this.clientRegistration.getRegistrationId())
.principal(new OAuth2ClientCredentialsGrantAuthenticationToken(this.clientRegistration)).build();
.withClientRegistrationId(this.clientRegistration.getRegistrationId())
.principal(new OAuth2ClientCredentialsGrantAuthenticationToken(this.clientRegistration))
.build();
return this.clientManager.authorize(authorizeRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private static void configureRestTemplate(RestTemplate restTemplate, String base
restTemplate.setRequestFactory(clientHttpRequestFactory);
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(baseUri));
restTemplate.getInterceptors().add(new CredHubRequestInterceptor());
restTemplate.setMessageConverters(
Arrays.asList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
new MappingJackson2HttpMessageConverter(JsonUtils.buildObjectMapper())));
restTemplate
.setMessageConverters(Arrays.asList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
new MappingJackson2HttpMessageConverter(JsonUtils.buildObjectMapper())));
}

/**
Expand Down Expand Up @@ -168,9 +168,9 @@ private static OAuth2AuthorizedClientManager buildClientManager(
ClientHttpRequestFactory clientHttpRequestFactory) {

OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
.authorizationCode().clientCredentials(
(b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpRequestFactory)))
.build();
.authorizationCode()
.clientCredentials((b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpRequestFactory)))
.build();

DefaultOAuth2AuthorizedClientManager authorizedClientManager = new DefaultOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ static WebClient createWebClient(CredHubProperties properties, ClientHttpConnect
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServerOAuth2AuthorizedClientExchangeFilterFunction(
clientManager);

return buildWebClient(properties.getUrl(), clientHttpConnector).filter(oauth).defaultRequest(
(requestHeadersSpec) -> requestHeadersSpec.attributes(ServerOAuth2AuthorizedClientExchangeFilterFunction
.clientRegistrationId(properties.getOauth2().getRegistrationId())))
.build();
return buildWebClient(properties.getUrl(), clientHttpConnector).filter(oauth)
.defaultRequest((requestHeadersSpec) -> requestHeadersSpec
.attributes(ServerOAuth2AuthorizedClientExchangeFilterFunction
.clientRegistrationId(properties.getOauth2().getRegistrationId())))
.build();
}

private static ReactiveOAuth2AuthorizedClientProvider buildClientProvider(ClientHttpConnector clientHttpConnector) {
return ReactiveOAuth2AuthorizedClientProviderBuilder.builder().authorizationCode()
.clientCredentials((b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpConnector)))
.build();
return ReactiveOAuth2AuthorizedClientProviderBuilder.builder()
.authorizationCode()
.clientCredentials((b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpConnector)))
.build();
}

private static WebClientReactiveClientCredentialsTokenResponseClient buildTokenResponseClient(
Expand Down Expand Up @@ -131,10 +133,12 @@ private static WebClient.Builder buildWebClient(String baseUri, ClientHttpConnec
dc.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
}).build();

return WebClient.builder().clientConnector(clientHttpConnector).baseUrl(baseUri)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.exchangeStrategies(strategies);
return WebClient.builder()
.clientConnector(clientHttpConnector)
.baseUrl(baseUri)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.exchangeStrategies(strategies);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public List<CredentialName> regenerate(final CredentialName certificateName) {
request.put(SIGNED_BY_REQUEST_FIELD, certificateName.getName());

ResponseEntity<Map<String, List<CredentialName>>> response = restOperations
.exchange(BULK_REGENERATE_URL_PATH, HttpMethod.POST, new HttpEntity<>(request), ref);
.exchange(BULK_REGENERATE_URL_PATH, HttpMethod.POST, new HttpEntity<>(request), ref);

ExceptionUtils.throwExceptionOnError(response);

Expand All @@ -146,7 +146,7 @@ public List<CertificateCredentialDetails> updateTransitionalVersion(final String
request.put(VERSION_REQUEST_FIELD, versionId);

ResponseEntity<List<CertificateCredentialDetails>> response = restOperations
.exchange(UPDATE_TRANSITIONAL_URL_PATH, HttpMethod.PUT, new HttpEntity<Object>(request), ref, id);
.exchange(UPDATE_TRANSITIONAL_URL_PATH, HttpMethod.PUT, new HttpEntity<Object>(request), ref, id);

ExceptionUtils.throwExceptionOnError(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,26 @@ public ReactiveCredHubCertificateTemplate(ReactiveCredHubOperations credHubOpera

@Override
public Flux<CertificateSummary> getAll() {
return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(BASE_URL_PATH).retrieve()
.onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CertificateSummaryData.class)
.flatMapMany((data) -> Flux.fromIterable(data.getCertificates())));
return this.credHubOperations.doWithWebClient((webClient) -> webClient.get()
.uri(BASE_URL_PATH)
.retrieve()
.onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
.bodyToMono(CertificateSummaryData.class)
.flatMapMany((data) -> Flux.fromIterable(data.getCertificates())));
}

@Override
public Mono<CertificateSummary> getByName(final CredentialName name) {
Assert.notNull(name, "certificate name must not be null");

return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(NAME_URL_QUERY, name.getName())
.retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
return this.credHubOperations
.doWithWebClient((webClient) -> webClient.get()
.uri(NAME_URL_QUERY, name.getName())
.retrieve()
.onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
.bodyToMono(CertificateSummaryData.class)
.flatMapMany((data) -> Flux.fromIterable(data.getCertificates()))).single();
.flatMapMany((data) -> Flux.fromIterable(data.getCertificates())))
.single();
}

@Override
Expand All @@ -97,9 +104,12 @@ public Mono<CertificateCredentialDetails> regenerate(final String id, final bool
Map<String, Boolean> request = new HashMap<>(1);
request.put(TRANSITIONAL_REQUEST_FIELD, setAsTransitional);

return this.credHubOperations
.doWithWebClient((webClient) -> webClient.post().uri(REGENERATE_URL_PATH, id).bodyValue(request)
.retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref));
return this.credHubOperations.doWithWebClient((webClient) -> webClient.post()
.uri(REGENERATE_URL_PATH, id)
.bodyValue(request)
.retrieve()
.onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
.bodyToMono(ref));
}

@Override
Expand All @@ -112,10 +122,13 @@ public Flux<CredentialName> regenerate(final CredentialName certificateName) {
Map<String, Object> request = new HashMap<>(1);
request.put(SIGNED_BY_REQUEST_FIELD, certificateName.getName());

return this.credHubOperations
.doWithWebClient((webClient) -> webClient.post().uri(BULK_REGENERATE_URL_PATH).bodyValue(request)
.retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToFlux(ref)
.flatMap((body) -> Flux.fromIterable(body.get(REGENERATED_CREDENTIALS_RESPONSE_FIELD))));
return this.credHubOperations.doWithWebClient((webClient) -> webClient.post()
.uri(BULK_REGENERATE_URL_PATH)
.bodyValue(request)
.retrieve()
.onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
.bodyToFlux(ref)
.flatMap((body) -> Flux.fromIterable(body.get(REGENERATED_CREDENTIALS_RESPONSE_FIELD))));
}

public Flux<CertificateCredentialDetails> updateTransitionalVersion(final String id, final String versionId) {
Expand All @@ -124,10 +137,12 @@ public Flux<CertificateCredentialDetails> updateTransitionalVersion(final String
Map<String, String> request = new HashMap<>(1);
request.put(VERSION_REQUEST_FIELD, versionId);

return this.credHubOperations
.doWithWebClient((webClient) -> webClient.put().uri(UPDATE_TRANSITIONAL_URL_PATH, id).bodyValue(request)
.retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
.bodyToFlux(CertificateCredentialDetails.class));
return this.credHubOperations.doWithWebClient((webClient) -> webClient.put()
.uri(UPDATE_TRANSITIONAL_URL_PATH, id)
.bodyValue(request)
.retrieve()
.onStatus(HttpStatusCode::isError, ExceptionUtils::buildError)
.bodyToFlux(CertificateCredentialDetails.class));
}

}
Loading

0 comments on commit f9573e6

Please sign in to comment.