Rename CorsConfigurationMapping to UrlBasedCorsConfigurationSource
Issue: SPR-13192
This commit is contained in:
@@ -36,7 +36,7 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.2
|
||||
*/
|
||||
public class CorsConfigurationMapping implements CorsConfigurationSource {
|
||||
public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource {
|
||||
|
||||
private final Map<String, CorsConfiguration> corsConfigurations =
|
||||
new LinkedHashMap<String, CorsConfiguration>();
|
||||
@@ -24,18 +24,19 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationMapping;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.CorsProcessor;
|
||||
import org.springframework.web.cors.CorsUtils;
|
||||
import org.springframework.web.cors.DefaultCorsProcessor;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
/**
|
||||
* {@link javax.servlet.Filter} that handles CORS preflight requests and intercepts CORS
|
||||
* simple and actual requests thanks to a {@link CorsProcessor} implementation
|
||||
* ({@link DefaultCorsProcessor} by default) in order to add the relevant CORS response
|
||||
* headers (like {@code Access-Control-Allow-Origin}) using the provided
|
||||
* {@link CorsConfigurationSource} (for example a {@link CorsConfigurationMapping} instance.
|
||||
* {@link CorsConfigurationSource} (for example an {@link UrlBasedCorsConfigurationSource}
|
||||
* instance.
|
||||
*
|
||||
* <p>This filter could be used in conjunction with {@link DelegatingFilterProxy} in order
|
||||
* to help with its initialization.
|
||||
@@ -48,16 +49,16 @@ public class CorsFilter extends OncePerRequestFilter {
|
||||
|
||||
private CorsProcessor processor = new DefaultCorsProcessor();
|
||||
|
||||
private final CorsConfigurationSource source;
|
||||
private final CorsConfigurationSource configSource;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor accepting a {@link CorsConfigurationSource}, this source will be used
|
||||
* by the filter to find the {@link CorsConfiguration} to use for each incoming request.
|
||||
* @see CorsConfigurationMapping
|
||||
* Constructor accepting a {@link CorsConfigurationSource} used by the filter to find
|
||||
* the {@link CorsConfiguration} to use for each incoming request.
|
||||
* @see UrlBasedCorsConfigurationSource
|
||||
*/
|
||||
public CorsFilter(CorsConfigurationSource source) {
|
||||
this.source = source;
|
||||
public CorsFilter(CorsConfigurationSource configSource) {
|
||||
this.configSource = configSource;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +76,7 @@ public class CorsFilter extends OncePerRequestFilter {
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
|
||||
if (CorsUtils.isCorsRequest(request)) {
|
||||
CorsConfiguration corsConfiguration = this.source.getCorsConfiguration(request);
|
||||
CorsConfiguration corsConfiguration = this.configSource.getCorsConfiguration(request);
|
||||
if (corsConfiguration != null) {
|
||||
boolean isValid = this.processor.processRequest(corsConfiguration, request, response);
|
||||
if (!isValid || CorsUtils.isPreFlightRequest(request)) {
|
||||
|
||||
Reference in New Issue
Block a user