Upgrade to Spring Framework 6.
Closes gh-695
This commit is contained in:
16
pom.xml
16
pom.xml
@@ -27,7 +27,7 @@
|
||||
<kotlin-coroutines.version>1.6.0</kotlin-coroutines.version>
|
||||
<mockk.version>1.10.3-jdk8</mockk.version>
|
||||
<mockito-core.version>3.8.0</mockito-core.version>
|
||||
<spring.version>6.0.0-SNAPSHOT</spring.version>
|
||||
<spring.version>6.0.0-M4</spring.version>
|
||||
<spring-data-bom.version>2022.0.0-SNAPSHOT</spring-data-bom.version>
|
||||
<spring-security-bom.version>5.4.5</spring-security-bom.version>
|
||||
<reactor.version>2020.0.13</reactor.version>
|
||||
@@ -537,7 +537,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jfrog.buildinfo</groupId>
|
||||
<artifactId>artifactory-maven-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
@@ -570,12 +570,6 @@
|
||||
<version>1.2.7</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.jfrog.buildinfo</groupId>
|
||||
<artifactId>artifactory-maven-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
@@ -753,7 +747,7 @@
|
||||
<profile>
|
||||
|
||||
<!--
|
||||
Profile to be activated when building the distribution atrifacts.
|
||||
Profile to be activated when building the distribution artifacts.
|
||||
|
||||
Generates reference documentation, aggregates JavaDoc etc. Has to be combined with
|
||||
profiles "release" or "milestone" to deploy artifacts into the appropriate places.
|
||||
@@ -808,5 +802,9 @@
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-libs-milestone</id>
|
||||
<url>https://repo.spring.io/libs-milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
||||
@@ -135,7 +135,7 @@ public class AuthenticationStepsExecutor implements ClientAuthentication {
|
||||
catch (HttpStatusCodeException e) {
|
||||
throw new VaultLoginException(
|
||||
String.format("HTTP request %s in state %s failed with Status %s and body %s", o, state,
|
||||
e.getRawStatusCode(), VaultResponses.getError(e.getResponseBodyAsString())),
|
||||
e.getStatusCode().value(), VaultResponses.getError(e.getResponseBodyAsString())),
|
||||
e);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
|
||||
@@ -357,7 +357,7 @@ public class LifecycleAwareSessionManager extends LifecycleAwareSessionManagerSu
|
||||
if (e instanceof HttpStatusCodeException) {
|
||||
|
||||
HttpStatusCodeException hsce = (HttpStatusCodeException) e;
|
||||
return String.format("%s: Status %s %s %s", message, hsce.getRawStatusCode(), hsce.getStatusText(),
|
||||
return String.format("%s: Status %s %s %s", message, hsce.getStatusCode().value(), hsce.getStatusText(),
|
||||
VaultResponses.getError(hsce.getResponseBodyAsString()));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ public class LoginTokenAdapter implements ClientAuthentication {
|
||||
return entity.getBody().getData();
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
throw new VaultTokenLookupException(String.format("Token self-lookup failed: %s %s", e.getRawStatusCode(),
|
||||
throw new VaultTokenLookupException(String.format("Token self-lookup failed: %s %s", e.getStatusCode(),
|
||||
VaultResponses.getError(e.getResponseBodyAsString())));
|
||||
}
|
||||
catch (RestClientException e) {
|
||||
|
||||
@@ -402,7 +402,7 @@ public class ReactiveLifecycleAwareSessionManager extends LifecycleAwareSessionM
|
||||
if (e instanceof WebClientResponseException) {
|
||||
|
||||
WebClientResponseException wce = (WebClientResponseException) e;
|
||||
return String.format("%s: Status %s %s %s", message, wce.getRawStatusCode(), wce.getStatusText(),
|
||||
return String.format("%s: Status %s %s %s", message, wce.getStatusCode().value(), wce.getStatusText(),
|
||||
VaultResponses.getError(wce.getResponseBodyAsString()));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -61,10 +61,10 @@ public abstract class VaultResponses {
|
||||
|
||||
if (StringUtils.hasText(message)) {
|
||||
return new VaultException(
|
||||
String.format("Status %s %s: %s", e.getRawStatusCode(), e.getStatusText(), message), e);
|
||||
String.format("Status %s %s: %s", renderStatus(e.getStatusCode()), e.getStatusText(), message), e);
|
||||
}
|
||||
|
||||
return new VaultException(String.format("Status %s %s", e.getRawStatusCode(), e.getStatusText()), e);
|
||||
return new VaultException(String.format("Status %s %s", renderStatus(e.getStatusCode()), e.getStatusText()), e);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,20 +81,21 @@ public abstract class VaultResponses {
|
||||
String message = VaultResponses.getError(e.getResponseBodyAsString());
|
||||
|
||||
if (StringUtils.hasText(message)) {
|
||||
return new VaultException(
|
||||
String.format("Status %s %s [%s]: %s", e.getRawStatusCode(), e.getStatusText(), path, message), e);
|
||||
return new VaultException(String.format("Status %s %s [%s]: %s", renderStatus(e.getStatusCode()),
|
||||
e.getStatusText(), path, message), e);
|
||||
}
|
||||
|
||||
return new VaultException(String.format("Status %s %s [%s]", e.getRawStatusCode(), e.getStatusText(), path), e);
|
||||
return new VaultException(
|
||||
String.format("Status %s %s [%s]", renderStatus(e.getStatusCode()), e.getStatusText(), path), e);
|
||||
}
|
||||
|
||||
public static VaultException buildException(HttpStatus statusCode, String path, String message) {
|
||||
public static VaultException buildException(HttpStatusCode statusCode, String path, String message) {
|
||||
|
||||
if (StringUtils.hasText(message)) {
|
||||
return new VaultException(String.format("Status %s [%s]: %s", statusCode, path, message));
|
||||
return new VaultException(String.format("Status %s [%s]: %s", renderStatus(statusCode), path, message));
|
||||
}
|
||||
|
||||
return new VaultException(String.format("Status %s [%s]", statusCode, path));
|
||||
return new VaultException(String.format("Status %s [%s]", renderStatus(statusCode), path));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,4 +194,8 @@ public abstract class VaultResponses {
|
||||
}
|
||||
}
|
||||
|
||||
private static int renderStatus(HttpStatusCode s) {
|
||||
return s.value();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2022 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.vault.core;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class HttpStatusUtil {
|
||||
|
||||
public static boolean isNotFound(HttpStatusCode status) {
|
||||
return status.value() == HttpStatus.NOT_FOUND.value();
|
||||
}
|
||||
|
||||
public static boolean isBadRequest(HttpStatusCode status) {
|
||||
return status.value() == HttpStatus.BAD_REQUEST.value();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -335,7 +335,7 @@ public class ReactiveVaultTemplate implements ReactiveVaultOperations {
|
||||
|
||||
private static <T> Mono<T> mapOtherwise(ClientResponse response, String path, HttpMethod method) {
|
||||
|
||||
if (response.statusCode() == HttpStatus.NOT_FOUND && method == HttpMethod.GET) {
|
||||
if (HttpStatusUtil.isNotFound(response.statusCode()) && method == HttpMethod.GET) {
|
||||
return response.releaseBody().then(Mono.empty());
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ abstract class VaultKeyValueAccessor implements VaultKeyValueOperationsSupport {
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ class VaultKeyValueMetadataTemplate implements VaultKeyValueMetadataOperations {
|
||||
return this.basePath + "/metadata/" + path;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "ConstantConditions", "unchecked", "rawtypes" })
|
||||
private static VaultMetadataResponse fromMap(Map<String, Object> metadataResponse) {
|
||||
|
||||
Duration duration = DurationParser.parseDuration((String) metadataResponse.get("delete_version_after"));
|
||||
@@ -118,7 +119,6 @@ class VaultKeyValueMetadataTemplate implements VaultKeyValueMetadataOperations {
|
||||
|
||||
@Nullable
|
||||
private static Instant toInstant(String date) {
|
||||
|
||||
return StringUtils.hasText(date) ? Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(date)) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ public class VaultPkiTemplate implements VaultPkiOperations {
|
||||
try {
|
||||
ResponseEntity<byte[]> response = restOperations.getForEntity(requestPath, byte[].class, this.path);
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
if (response.getStatusCode().is2xxSuccessful() && response.hasBody()) {
|
||||
return new ByteArrayInputStream(response.getBody());
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ public class VaultTemplate implements InitializingBean, VaultOperations, Disposa
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ public class VaultTemplate implements InitializingBean, VaultOperations, Disposa
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ public class VaultTemplate implements InitializingBean, VaultOperations, Disposa
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public class VaultVersionedKeyValueTemplate extends VaultKeyValue2Accessor imple
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
if (e.getResponseBodyAsString().contains("deletion_time")) {
|
||||
|
||||
return VaultResponses.unwrap(e.getResponseBodyAsString(), VersionedResponse.class);
|
||||
|
||||
@@ -118,11 +118,11 @@ public class VaultWrappingTemplate implements VaultWrappingOperations {
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
if (HttpStatusUtil.isNotFound(e.getStatusCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.BAD_REQUEST
|
||||
if (HttpStatusUtil.isBadRequest(e.getStatusCode())
|
||||
&& e.getResponseBodyAsString().contains("does not exist")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -661,13 +661,13 @@ public class SecretLeaseContainer extends SecretLeaseEventPublisher implements I
|
||||
Exception exceptionToUse;
|
||||
if (httpException != null) {
|
||||
|
||||
if (httpException.getStatusCode() == HttpStatus.BAD_REQUEST) {
|
||||
if (httpException.getStatusCode().value() == HttpStatus.BAD_REQUEST.value()) {
|
||||
expired = true;
|
||||
onLeaseExpired(requestedSecret, lease);
|
||||
}
|
||||
|
||||
exceptionToUse = new VaultException(String.format("Cannot renew lease: Status %s %s %s",
|
||||
httpException.getRawStatusCode(), httpException.getStatusText(),
|
||||
httpException.getStatusCode().value(), httpException.getStatusText(),
|
||||
VaultResponses.getError(httpException.getResponseBodyAsString())), e);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -37,7 +37,6 @@ public class VaultApp {
|
||||
vaultTemplate.write("secret/myapp", secrets);
|
||||
|
||||
VaultResponseSupport<Secrets> response = vaultTemplate.read("secret/myapp", Secrets.class);
|
||||
System.out.println(response.getRequiredData().getUsername());
|
||||
|
||||
vaultTemplate.delete("secret/myapp");
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jfrog.buildinfo</groupId>
|
||||
<artifactId>artifactory-maven-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>deploy-docs</id>
|
||||
|
||||
Reference in New Issue
Block a user