Java Code Examples for org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource

The following examples show how to use org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: microservices-platform   Source File: CorsConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Order(Ordered.HIGHEST_PRECEDENCE)
@Bean
public CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    // cookie跨域
    config.setAllowCredentials(Boolean.TRUE);
    config.addAllowedMethod(ALL);
    config.addAllowedOrigin(ALL);
    config.addAllowedHeader(ALL);
    // 配置前端js允许访问的自定义响应头
    config.addExposedHeader("setToken");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", config);

    return new CorsWebFilter(source);
}
 
Example 2
@Bean
public CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    // cookie跨域
    config.setAllowCredentials(Boolean.TRUE);
    config.addAllowedMethod(CorsConfiguration.ALL);
    config.addAllowedOrigin(CorsConfiguration.ALL);
    config.addAllowedHeader(CorsConfiguration.ALL);
    // 配置前端js允许访问的自定义响应头
    config.addExposedHeader("x-token");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", config);

    return new CorsWebFilter(source);
}
 
Example 3
Source Project: influx-proxy   Source File: WebConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("*");
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return new CorsWebFilter(source);
}
 
Example 4
Source Project: spring-analysis-note   Source File: AbstractHandlerMapping.java    License: MIT License 5 votes vote down vote up
/**
 * Set the "global" CORS configurations based on URL patterns. By default the
 * first matching URL pattern is combined with handler-level CORS configuration if any.
 * @see #setCorsConfigurationSource(CorsConfigurationSource)
 */
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) {
	Assert.notNull(corsConfigurations, "corsConfigurations must not be null");
	if (!corsConfigurations.isEmpty()) {
		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(this.patternParser);
		source.setCorsConfigurations(corsConfigurations);
		this.corsConfigurationSource = source;
	}
	else {
		this.corsConfigurationSource = null;
	}
}
 
Example 5
Source Project: mall-swarm   Source File: GlobalCorsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedMethod("*");
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", config);

    return new CorsWebFilter(source);
}
 
Example 6
Source Project: sophia_scaffolding   Source File: CorsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedMethod("*");
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", config);

    return new CorsWebFilter(source);
}
 
Example 7
Source Project: sophia_scaffolding   Source File: CorsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedMethod("*");
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", config);

    return new CorsWebFilter(source);
}
 
Example 8
Source Project: sophia_scaffolding   Source File: CorsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsWebFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedMethod("*");
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", config);

    return new CorsWebFilter(source);
}
 
Example 9
@Bean
CorsWebFilter corsWebFilter() {
    CorsConfiguration corsConfig = new CorsConfiguration();
    corsConfig.setAllowedOrigins(List.of("*"));
    corsConfig.setMaxAge(3600L);
    corsConfig.addAllowedMethod("*");
    corsConfig.addAllowedHeader("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", corsConfig);

    return new CorsWebFilter(source);
}
 
Example 10
Source Project: vertx-spring-boot   Source File: HttpIT.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsWebFilter corsWebFilter() {
    CorsConfiguration config = new CorsConfiguration();

    config.addAllowedOrigin("http://snowdrop.dev");
    config.addAllowedHeader("TEST");
    config.addAllowedMethod(HttpMethod.POST);
    config.setMaxAge(1000L);

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/", config);

    return new CorsWebFilter(source);
}
 
Example 11
Source Project: streaming-file-server   Source File: CorsWebFluxCfg.java    License: MIT License 5 votes vote down vote up
@Bean
public CorsWebFilter corsWebFilter() {
  val corsConfig = new CorsConfiguration();
  corsConfig.addAllowedOrigin(ALLOWED_ORIGIN);
  corsConfig.addAllowedMethod(ALLOWED_METHODS);
  corsConfig.addAllowedHeader(ALLOWED_HEADERS);
  corsConfig.setMaxAge(MAX_AGE);

  val source = new UrlBasedCorsConfigurationSource();
  source.registerCorsConfiguration("/**", corsConfig);

  return new CorsWebFilter(source);
}
 
Example 12
Source Project: tutorials   Source File: CorsWebFilterConfig.java    License: MIT License 5 votes vote down vote up
@Bean
CorsWebFilter corsWebFilter() {
    CorsConfiguration corsConfig = new CorsConfiguration();
    corsConfig.setAllowedOrigins(Arrays.asList("http://allowed-origin.com"));
    corsConfig.setMaxAge(8000L);
    corsConfig.addAllowedMethod("PUT");
    corsConfig.addAllowedHeader("Baeldung-Allowed");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    source.registerCorsConfiguration("/**", corsConfig);

    return new CorsWebFilter(source);
}
 
Example 13
Source Project: codeway_service   Source File: CorsConfig.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Bean
public CorsWebFilter corsFilter(){
	UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
	source.registerCorsConfiguration("/**", buildConfig());
	return new CorsWebFilter(source);
}
 
Example 14
Source Project: java-technology-stack   Source File: AbstractHandlerMapping.java    License: MIT License 4 votes vote down vote up
public AbstractHandlerMapping() {
	this.patternParser = new PathPatternParser();
	this.corsConfigurationSource = new UrlBasedCorsConfigurationSource(this.patternParser);
}
 
Example 15
Source Project: java-technology-stack   Source File: AbstractHandlerMapping.java    License: MIT License 4 votes vote down vote up
/**
 * Set the "global" CORS configurations based on URL patterns. By default the
 * first matching URL pattern is combined with handler-level CORS configuration if any.
 * @see #setCorsConfigurationSource(CorsConfigurationSource)
 */
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) {
	Assert.notNull(corsConfigurations, "corsConfigurations must not be null");
	this.corsConfigurationSource = new UrlBasedCorsConfigurationSource(this.patternParser);
	((UrlBasedCorsConfigurationSource) this.corsConfigurationSource).setCorsConfigurations(corsConfigurations);
}
 
Example 16
Source Project: codeway_service   Source File: CorsConfig.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Bean
public CorsWebFilter corsFilter(){
	UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
	source.registerCorsConfiguration("/**", buildConfig());
	return new CorsWebFilter(source);
}