Fix new Sonar smells
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2020 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.
|
||||
@@ -37,7 +37,7 @@ import org.springframework.integration.http.inbound.IntegrationRequestMappingHan
|
||||
*/
|
||||
public class HttpIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class);
|
||||
private static final Log LOGGER = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class);
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
@@ -45,7 +45,7 @@ public class HttpIntegrationConfigurationInitializer implements IntegrationConfi
|
||||
registerRequestMappingHandlerMappingIfNecessary((BeanDefinitionRegistry) beanFactory);
|
||||
}
|
||||
else {
|
||||
logger.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" +
|
||||
LOGGER.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" +
|
||||
" isn't an instance of `BeanDefinitionRegistry`.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,45 +172,49 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
|
||||
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
|
||||
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
|
||||
if (crossOrigin != null) {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
|
||||
config.addAllowedMethod(requestMethod.name());
|
||||
}
|
||||
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
|
||||
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
|
||||
Boolean allowCredentials = crossOrigin.getAllowCredentials();
|
||||
config.setAllowCredentials(allowCredentials);
|
||||
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
|
||||
if (Boolean.TRUE.equals(allowCredentials)
|
||||
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
|
||||
config.setAllowedOriginPatterns(allowedOrigins);
|
||||
}
|
||||
else {
|
||||
config.setAllowedOrigins(allowedOrigins);
|
||||
}
|
||||
|
||||
if (crossOrigin.getMaxAge() != -1) {
|
||||
config.setMaxAge(crossOrigin.getMaxAge());
|
||||
}
|
||||
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
|
||||
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
|
||||
config.addAllowedMethod(allowedMethod.name());
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
|
||||
for (NameValueExpression<String> headerExpression :
|
||||
mappingInfo.getHeadersCondition().getExpressions()) {
|
||||
|
||||
if (!headerExpression.isNegated()) {
|
||||
config.addAllowedHeader(headerExpression.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return config.applyPermitDefaultValues();
|
||||
return buildCorsConfiguration(crossOrigin, mappingInfo);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static CorsConfiguration buildCorsConfiguration(CrossOrigin crossOrigin, RequestMappingInfo mappingInfo) {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
for (RequestMethod requestMethod : crossOrigin.getMethod()) {
|
||||
config.addAllowedMethod(requestMethod.name());
|
||||
}
|
||||
config.setAllowedHeaders(Arrays.asList(crossOrigin.getAllowedHeaders()));
|
||||
config.setExposedHeaders(Arrays.asList(crossOrigin.getExposedHeaders()));
|
||||
Boolean allowCredentials = crossOrigin.getAllowCredentials();
|
||||
config.setAllowCredentials(allowCredentials);
|
||||
List<String> allowedOrigins = Arrays.asList(crossOrigin.getOrigin());
|
||||
if (Boolean.TRUE.equals(allowCredentials)
|
||||
&& CollectionUtils.contains(allowedOrigins.iterator(), CorsConfiguration.ALL)) {
|
||||
config.setAllowedOriginPatterns(allowedOrigins);
|
||||
}
|
||||
else {
|
||||
config.setAllowedOrigins(allowedOrigins);
|
||||
}
|
||||
|
||||
if (crossOrigin.getMaxAge() != -1) {
|
||||
config.setMaxAge(crossOrigin.getMaxAge());
|
||||
}
|
||||
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
|
||||
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
|
||||
config.addAllowedMethod(allowedMethod.name());
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isEmpty(config.getAllowedHeaders())) {
|
||||
for (NameValueExpression<String> headerExpression :
|
||||
mappingInfo.getHeadersCondition().getExpressions()) {
|
||||
|
||||
if (!headerExpression.isNegated()) {
|
||||
config.addAllowedHeader(headerExpression.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return config.applyPermitDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Created a {@link RequestMappingInfo} from a
|
||||
* 'Spring Integration HTTP Inbound Endpoint' {@link RequestMapping}.
|
||||
|
||||
Reference in New Issue
Block a user