From 27381479476236b94f2540545aa35e9708277957 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 28 Dec 2017 11:01:14 +0100 Subject: [PATCH] Polish "Move CorsEndpointProperties to the parent package" Closes gh-11439 --- .../endpoint/web/CorsEndpointProperties.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java index 9b3e756bc0..6d3c551d1c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit; import org.springframework.util.CollectionUtils; import org.springframework.web.cors.CorsConfiguration; @@ -121,23 +122,19 @@ public class CorsEndpointProperties { if (CollectionUtils.isEmpty(this.allowedOrigins)) { return null; } + PropertyMapper map = PropertyMapper.get(); CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(this.allowedOrigins); - if (!CollectionUtils.isEmpty(this.allowedHeaders)) { - configuration.setAllowedHeaders(this.allowedHeaders); - } - if (!CollectionUtils.isEmpty(this.allowedMethods)) { - configuration.setAllowedMethods(this.allowedMethods); - } - if (!CollectionUtils.isEmpty(this.exposedHeaders)) { - configuration.setExposedHeaders(this.exposedHeaders); - } - if (this.maxAge != null) { - configuration.setMaxAge(this.maxAge.getSeconds()); - } - if (this.allowCredentials != null) { - configuration.setAllowCredentials(this.allowCredentials); - } + map.from(this::getAllowedOrigins).to(configuration::setAllowedOrigins); + map.from(this::getAllowedHeaders).whenNot(CollectionUtils::isEmpty) + .to(configuration::setAllowedHeaders); + map.from(this::getAllowedMethods).whenNot(CollectionUtils::isEmpty) + .to(configuration::setAllowedMethods); + map.from(this::getExposedHeaders).whenNot(CollectionUtils::isEmpty) + .to(configuration::setExposedHeaders); + map.from(this::getMaxAge).whenNonNull().as(Duration::getSeconds) + .to(configuration::setMaxAge); + map.from(this::getAllowCredentials).whenNonNull() + .to(configuration::setAllowCredentials); return configuration; }