Commit 27381479 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Move CorsEndpointProperties to the parent package"

Closes gh-11439
parent 8383b761
...@@ -22,6 +22,7 @@ import java.util.ArrayList; ...@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; 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.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
...@@ -121,23 +122,19 @@ public class CorsEndpointProperties { ...@@ -121,23 +122,19 @@ public class CorsEndpointProperties {
if (CollectionUtils.isEmpty(this.allowedOrigins)) { if (CollectionUtils.isEmpty(this.allowedOrigins)) {
return null; return null;
} }
PropertyMapper map = PropertyMapper.get();
CorsConfiguration configuration = new CorsConfiguration(); CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(this.allowedOrigins); map.from(this::getAllowedOrigins).to(configuration::setAllowedOrigins);
if (!CollectionUtils.isEmpty(this.allowedHeaders)) { map.from(this::getAllowedHeaders).whenNot(CollectionUtils::isEmpty)
configuration.setAllowedHeaders(this.allowedHeaders); .to(configuration::setAllowedHeaders);
} map.from(this::getAllowedMethods).whenNot(CollectionUtils::isEmpty)
if (!CollectionUtils.isEmpty(this.allowedMethods)) { .to(configuration::setAllowedMethods);
configuration.setAllowedMethods(this.allowedMethods); map.from(this::getExposedHeaders).whenNot(CollectionUtils::isEmpty)
} .to(configuration::setExposedHeaders);
if (!CollectionUtils.isEmpty(this.exposedHeaders)) { map.from(this::getMaxAge).whenNonNull().as(Duration::getSeconds)
configuration.setExposedHeaders(this.exposedHeaders); .to(configuration::setMaxAge);
} map.from(this::getAllowCredentials).whenNonNull()
if (this.maxAge != null) { .to(configuration::setAllowCredentials);
configuration.setMaxAge(this.maxAge.getSeconds());
}
if (this.allowCredentials != null) {
configuration.setAllowCredentials(this.allowCredentials);
}
return configuration; return configuration;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment