Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
description = "Spring CredHub"

ext {
springBootVersion = "3.5.8"
springBootVersion = "4.0.0"
javadocLinks = [
"https://docs.oracle.com/en/java/javase/17/docs/api/",
"https://docs.spring.io/spring-framework/docs/current/javadoc-api/"
Expand Down
3 changes: 2 additions & 1 deletion spring-credhub-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
api("org.springframework:spring-beans")
api("org.springframework:spring-context")
api("org.springframework:spring-web")
api("com.fasterxml.jackson.core:jackson-databind")
api("tools.jackson.core:jackson-databind")
api("org.springframework.security:spring-security-oauth2-client") {
exclude module: "spring-security-web"
}
Expand All @@ -37,6 +37,7 @@ dependencies {
}

testImplementation("org.springframework:spring-test")
testImplementation("org.springframework.boot:spring-boot-jackson2")
testImplementation("io.projectreactor:reactor-test")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
Expand Down Expand Up @@ -132,9 +132,8 @@ 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 JacksonJsonHttpMessageConverter(JsonUtils.buildJsonMapper())));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package org.springframework.credhub.core;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

import org.springframework.credhub.support.utils.JsonUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.codec.CodecConfigurer;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.codec.json.JacksonJsonDecoder;
import org.springframework.http.codec.json.JacksonJsonEncoder;
import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientProvider;
import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientProviderBuilder;
Expand Down Expand Up @@ -126,11 +126,11 @@ private static DefaultReactiveOAuth2AuthorizedClientManager buildClientManager(

private static WebClient.Builder buildWebClient(String baseUri, ClientHttpConnector clientHttpConnector) {
ExchangeStrategies strategies = ExchangeStrategies.builder().codecs((configurer) -> {
ObjectMapper mapper = JsonUtils.buildObjectMapper();
JsonMapper mapper = JsonUtils.buildJsonMapper();

CodecConfigurer.DefaultCodecs dc = configurer.defaultCodecs();
dc.jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
dc.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
dc.jacksonJsonDecoder(new JacksonJsonDecoder(mapper));
dc.jacksonJsonEncoder(new JacksonJsonEncoder(mapper));
}).build();

return WebClient.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package org.springframework.credhub.support.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.MapperFeature;
import tools.jackson.databind.PropertyNamingStrategies;
import tools.jackson.databind.cfg.EnumFeature;
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.databind.jsontype.NamedType;
import tools.jackson.databind.util.StdDateFormat;

import org.springframework.credhub.support.CredentialType;

Expand All @@ -40,40 +40,32 @@ private JsonUtils() {
}

/**
* Create and configure the {@link ObjectMapper} used for serializing and
* deserializing JSON requests and responses.
* @return a configured {@link ObjectMapper}
* Create and configure the {@link JsonMapper} used for serializing and deserializing
* JSON requests and responses.
* @return a configured {@link JsonMapper}
*/
public static ObjectMapper buildObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new StdDateFormat());
objectMapper.setPropertyNamingStrategy(new PropertyNamingStrategies.SnakeCaseStrategy());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);

configureCredentialDetailTypeMapping(objectMapper);

return objectMapper;
public static JsonMapper buildJsonMapper() {
return JsonMapper.builder()
.defaultDateFormat(new StdDateFormat())
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.changeDefaultPropertyInclusion((incl) -> incl.withValueInclusion(JsonInclude.Include.NON_EMPTY))
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(EnumFeature.READ_ENUMS_USING_TO_STRING, true)
.configure(EnumFeature.WRITE_ENUMS_USING_TO_STRING, true)
.configure(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS, true)
.registerSubtypes(credentialDetailTypeMappings())
.build();
}

/**
* Configure type mapping for the {@literal value} field in the
* {@literal CredentialDetails} object.
* @param objectMapper the {@link ObjectMapper} to configure
* Return type mappings for the {@literal value} field in the
* {@literal CredentialDetails} objects.
* @return array of {@link NamedType} for {@literal CredentialDetails}.
*/
private static void configureCredentialDetailTypeMapping(ObjectMapper objectMapper) {
List<NamedType> subtypes = new ArrayList<>();
for (CredentialType type : CredentialType.values()) {
subtypes.add(new NamedType(type.getModelClass(), type.getValueType()));
}

registerSubtypes(objectMapper, subtypes);
}

private static void registerSubtypes(ObjectMapper objectMapper, List<NamedType> subtypes) {
objectMapper.registerSubtypes(subtypes.toArray(new NamedType[] {}));
private static NamedType[] credentialDetailTypeMappings() {
return Arrays.stream(CredentialType.values())
.map((type) -> new NamedType(type.getModelClass(), type.getValueType()))
.toArray(NamedType[]::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.core.CredHubException;
import org.springframework.credhub.support.CredentialSummary;
Expand Down Expand Up @@ -93,7 +94,8 @@ private void assertResponseContainsExpectedCredentials(ResponseEntity<Credential
static class ResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return Stream.of(
Arguments.of(ResponseEntity.ok().body(new CredentialSummaryData(new CredentialSummary(NAME)))),
Arguments.of(ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new CredentialSummaryData())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -106,7 +107,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<Certifica
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.CERTIFICATE, CREDENTIAL);
}

Expand All @@ -115,7 +117,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.CERTIFICATE, CREDENTIAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -84,7 +85,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<JsonCrede
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.JSON, CREDENTIAL);
}

Expand All @@ -93,7 +95,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.JSON, CREDENTIAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -102,7 +103,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<PasswordC
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.PASSWORD, CREDENTIAL);
}

Expand All @@ -111,7 +113,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.PASSWORD, CREDENTIAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -103,7 +104,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<RsaCreden
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.RSA, CREDENTIAL);
}

Expand All @@ -112,7 +114,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.RSA, CREDENTIAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -103,7 +104,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<SshCreden
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.CERTIFICATE, CREDENTIAL);
}

Expand All @@ -112,7 +114,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.CERTIFICATE, CREDENTIAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -79,7 +80,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<UserCrede
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.USER, CREDENTIAL);
}

Expand All @@ -88,7 +90,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.USER, CREDENTIAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.support.ParameterDeclarations;

import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
Expand Down Expand Up @@ -79,7 +80,8 @@ public void getByNameWithVersions(ResponseEntity<CredentialDetailsData<ValueCred
static class DetailResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDetailArguments(CredentialType.VALUE, CREDENTIAL);
}

Expand All @@ -88,7 +90,8 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
static class DataResponseArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
public Stream<? extends Arguments> provideArguments(ParameterDeclarations parameters,
ExtensionContext context) {
return buildDataArguments(CredentialType.VALUE, CREDENTIAL);
}

Expand Down
Loading