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

The following examples show how to use org.springframework.web.cors.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: flowable-engine   Source File: PropertyBasedCorsFilter.java    License: Apache License 2.0 7 votes vote down vote up
protected CorsFilter corsFilter(RestAppProperties.Cors cors) {
    CorsConfiguration config = new CorsConfiguration();
    if (cors.isAllowCredentials()) {
        config.setAllowCredentials(true);
    }

    for (String origin : cors.getAllowedOrigins()) {
        config.addAllowedOrigin(origin);
    }
    for (String header : cors.getAllowedHeaders()) {
        config.addAllowedHeader(header);
    }
    for (String exposedHeader : cors.getExposedHeaders()) {
        config.addExposedHeader(exposedHeader);
    }
    for (String method : cors.getAllowedMethods()) {
        config.addAllowedMethod(method);
    }

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 2
Source Project: spring-boot-plus   Source File: SpringBootPlusCorsConfig.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * CORS跨域设置
 *
 * @return
 */
@Bean
public FilterRegistrationBean corsFilter(SpringBootPlusCorsProperties corsProperties) {
    log.debug("corsProperties:{}", corsProperties);
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    // 跨域配置
    corsConfiguration.setAllowedOrigins(corsProperties.getAllowedOrigins());
    corsConfiguration.setAllowedHeaders(corsProperties.getAllowedHeaders());
    corsConfiguration.setAllowedMethods(corsProperties.getAllowedMethods());
    corsConfiguration.setAllowCredentials(corsProperties.isAllowCredentials());
    corsConfiguration.setExposedHeaders(corsProperties.getExposedHeaders());
    corsConfiguration.setMaxAge(corsConfiguration.getMaxAge());

    source.registerCorsConfiguration(corsProperties.getPath(), corsConfiguration);
    FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    bean.setEnabled(corsProperties.isEnable());
    return bean;
}
 
Example 3
Source Project: mall   Source File: MallZuulApplication.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public CorsFilter corsFilter() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true); // 允许cookies跨域
    config.addAllowedOrigin("*");// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
    config.addAllowedHeader("*");// #允许访问的头信息,*表示全部
    config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
    config.addAllowedMethod("OPTIONS");// 允许提交请求的方法,*表示全部允许
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");// 允许Get的请求方法
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 4
/**
 * 允许跨域调用的过滤器
 */
@Bean
public CorsFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    //允许所有域名进行跨域调用
    config.addAllowedOrigin("*");
    //允许跨越发送cookie
    config.setAllowCredentials(true);
    //放行全部原始头信息
    config.addAllowedHeader("*");
    //允许所有请求方法跨域调用
    config.addAllowedMethod("*");
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 5
Source Project: spring-analysis-note   Source File: MvcNamespaceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testCorsMinimal() throws Exception {
	loadBeanDefinitions("mvc-config-cors-minimal.xml");

	String[] beanNames = appContext.getBeanNamesForType(AbstractHandlerMapping.class);
	assertEquals(2, beanNames.length);
	for (String beanName : beanNames) {
		AbstractHandlerMapping handlerMapping = (AbstractHandlerMapping)appContext.getBean(beanName);
		assertNotNull(handlerMapping);
		DirectFieldAccessor accessor = new DirectFieldAccessor(handlerMapping);
		Map<String, CorsConfiguration> configs = ((UrlBasedCorsConfigurationSource) accessor
				.getPropertyValue("corsConfigurationSource")).getCorsConfigurations();
		assertNotNull(configs);
		assertEquals(1, configs.size());
		CorsConfiguration config = configs.get("/**");
		assertNotNull(config);
		assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
		assertArrayEquals(new String[]{"GET", "HEAD", "POST"}, config.getAllowedMethods().toArray());
		assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
		assertNull(config.getExposedHeaders());
		assertNull(config.getAllowCredentials());
		assertEquals(Long.valueOf(1800), config.getMaxAge());
	}
}
 
Example 6
Source Project: Microservices-Building-Scalable-Software   Source File: EdgeApp.java    License: MIT License 6 votes vote down vote up
/**
 *
 * @return
 */
@Bean
public CorsFilter corsFilter() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 7
Source Project: api-gateway-old   Source File: CustomZuulConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 解决跨域问题
 *
 * @return 跨域声明
 */
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.setAllowedOrigins(allowedOrigins);
    config.addAllowedHeader("*");
    config.setMaxAge(18000L);
    config.addAllowedMethod("*");
    //添加response暴露的header
    String[] responseHeader =
            {"date", "content-encoding", "server", "etag", "vary", "Cache-Control", "Last-Modified",
                    "content-type", "transfer-encoding", "connection", "x-application-context"};
    config.setExposedHeaders(Arrays.asList(responseHeader));
    source.registerCorsConfiguration("/**", config);

    FilterRegistrationBean bean = new FilterRegistrationBean<>(new CorsFilter(source));
    bean.setOrder(0);
    return bean;
}
 
Example 8
Source Project: tutorials   Source File: WebConfigurer.java    License: MIT License 6 votes vote down vote up
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = jHipsterProperties.getCors();
    if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
        log.debug("Registering CORS filter");
        source.registerCorsConfiguration("/api/**", config);
        source.registerCorsConfiguration("/management/**", config);
        source.registerCorsConfiguration("/v2/api-docs", config);
        source.registerCorsConfiguration("/auth/**", config);
        source.registerCorsConfiguration("/*/api/**", config);
        source.registerCorsConfiguration("/*/management/**", config);
        source.registerCorsConfiguration("/*/oauth/**", config);
    }
    return new CorsFilter(source);
}
 
Example 9
Source Project: mall-tiny   Source File: GlobalCorsConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 允许跨域调用的过滤器
 */
@Bean
public CorsFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    //允许所有域名进行跨域调用
    config.addAllowedOrigin("*");
    //允许跨越发送cookie
    config.setAllowCredentials(true);
    //放行全部原始头信息
    config.addAllowedHeader("*");
    //允许所有请求方法跨域调用
    config.addAllowedMethod("*");
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 10
@Bean
public CorsFilter corsFilter() {
	final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	final CorsConfiguration config = new CorsConfiguration();
	// 允许cookies跨域
	config.setAllowCredentials(true);
	// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
	config.addAllowedOrigin("*");
	// #允许访问的头信息,*表示全部
	config.addAllowedHeader("*");
	// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
	config.setMaxAge(18000L);
	// 允许提交请求的方法,*表示全部允许
	config.addAllowedMethod("OPTIONS");
	config.addAllowedMethod("HEAD");
	// 允许Get的请求方法
	config.addAllowedMethod("GET");
	config.addAllowedMethod("PUT");
	config.addAllowedMethod("POST");
	config.addAllowedMethod("DELETE");
	config.addAllowedMethod("PATCH");
	source.registerCorsConfiguration("/**", config);
	return new CorsFilter(source);
}
 
Example 11
Source Project: entref-spring-boot   Source File: CORSConfig.java    License: MIT License 6 votes vote down vote up
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();

    config.addAllowedOrigin(env.getProperty(Constants.ENV_ALLOWED_ORIGIN));
    config.addAllowedHeader("*");
    config.addAllowedMethod(HttpMethod.GET);
    config.addAllowedMethod(HttpMethod.HEAD);
    config.addAllowedMethod(HttpMethod.POST);
    config.addAllowedMethod(HttpMethod.PUT);
    config.addAllowedMethod(HttpMethod.PATCH);
    config.addAllowedMethod(HttpMethod.DELETE);
    config.addAllowedMethod(HttpMethod.OPTIONS);
    config.addAllowedMethod(HttpMethod.TRACE);

    source.registerCorsConfiguration("/**", config);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return bean;
}
 
Example 12
Source Project: yue-library   Source File: WebAutoConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "yue.cors", name = "allow", havingValue = "true", matchIfMissing = true)
public CorsFilter corsFilter(CorsProperties corsProperties) {
	final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	final CorsConfiguration config = new CorsConfiguration();
	
	config.setAllowCredentials(true);
	config.setAllowedHeaders(Arrays.asList("*"));
	config.setAllowedMethods(Arrays.asList("*"));
	config.setAllowedOrigins(Arrays.asList("*"));
	config.setMaxAge(3600L);
	
	// 设置response允许暴露的Headers
	List<String> exposedHeaders = corsProperties.getExposedHeaders();
	if (exposedHeaders != null) {
		config.setExposedHeaders(exposedHeaders);
	} else {
		config.addExposedHeader("token");
	}
	
	source.registerCorsConfiguration("/**", config);
	
	log.info("【初始化配置-跨域】默认配置为true,当前环境为true:默认任何情况下都允许跨域访问 ... 已初始化完毕。");
	return new CorsFilter(source);
}
 
Example 13
Source Project: mall   Source File: GlobalCorsConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 允许跨域调用的过滤器
 */
@Bean
public CorsFilter corsFilter() {
    CorsConfiguration config = new CorsConfiguration();
    //允许所有域名进行跨域调用
    config.addAllowedOrigin("*");
    //允许跨越发送cookie
    config.setAllowCredentials(true);
    //放行全部原始头信息
    config.addAllowedHeader("*");
    //允许所有请求方法跨域调用
    config.addAllowedMethod("*");
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 14
Source Project: zuihou-admin-boot   Source File: CorsConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * attention:简单跨域就是GET,HEAD和POST请求,但是POST请求的"Content-Type"只能是application/x-www-form-urlencoded, multipart/form-data 或 text/plain
 * 反之,就是非简单跨域,此跨域有一个预检机制,说直白点,就是会发两次请求,一次OPTIONS请求,一次真正的请求
 */
@Bean
public CorsFilter corsFilter() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final org.springframework.web.cors.CorsConfiguration config = new org.springframework.web.cors.CorsConfiguration();
    // 允许cookies跨域
    config.setAllowCredentials(true);
    // #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
    config.addAllowedOrigin("*");
    // #允许访问的头信息,*表示全部
    config.addAllowedHeader("*");
    // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
    config.setMaxAge(18000L);
    // 允许提交请求的方法,*表示全部允许
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    // 允许Get的请求类型
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 15
Source Project: Mastering-Microservices-with-Java   Source File: EdgeApp.java    License: MIT License 6 votes vote down vote up
/**
 *
 * @return
 */
@Bean
public CorsFilter corsFilter() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("OPTIONS");
    config.addAllowedMethod("HEAD");
    config.addAllowedMethod("GET");
    config.addAllowedMethod("PUT");
    config.addAllowedMethod("POST");
    config.addAllowedMethod("DELETE");
    config.addAllowedMethod("PATCH");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 16
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
    val config = new CorsConfiguration();
    config.setAllowCredentials(allowCredentials);
    config.setAllowedHeaders(allowedHeaders);
    config.setAllowedOrigins(corsAllowedOrigins);
    config.setAllowedMethods(allowedMethods);
    config.setMaxAge(maxAge);

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

    val bean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(source));
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return bean;
}
 
Example 17
Source Project: sk-admin   Source File: ConfigurerAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("*");
    source.registerCorsConfiguration("/**", config);
    return new CorsFilter(source);
}
 
Example 18
@Bean
CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.setAllowedOrigins(Arrays.asList("http://localhost:8080"));
    config.addAllowedHeader("*");
    config.addAllowedMethod("*");
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return source;
}
 
Example 19
Source Project: hsweb-framework   Source File: CorsAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsFilter corsFilter(CorsProperties corsProperties) {
    UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();

    Optional.ofNullable(corsProperties.getConfigs())
            .orElse(Collections.singletonList(Collections.singletonMap(CORS_PATH_ALL,
                    new CorsProperties.CorsConfiguration().applyPermitDefaultValues())))
            .forEach((map) ->
                    map.forEach((path, config) ->
                            corsConfigurationSource.registerCorsConfiguration(path, buildConfiguration(config))
                    )
            );

    return new CorsFilter(corsConfigurationSource);
}
 
Example 20
Source Project: e-commerce-microservice   Source File: WebConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = jHipsterProperties.getCors();
    if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
        log.debug("Registering CORS filter");
        source.registerCorsConfiguration("/api/**", config);
        source.registerCorsConfiguration("/management/**", config);
        source.registerCorsConfiguration("/v2/api-docs", config);
        source.registerCorsConfiguration("/*/api/**", config);
        source.registerCorsConfiguration("/*/management/**", config);
    }
    return new CorsFilter(source);
}
 
Example 21
Source Project: taskana   Source File: WebSecurityConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
  final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  CorsConfiguration config = new CorsConfiguration();
  config.setAllowCredentials(true);
  config.addAllowedOrigin("*");
  config.addAllowedHeader("*");
  config.addAllowedMethod("*");
  config.addAllowedMethod("POST");
  source.registerCorsConfiguration("/**", config);
  FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
  bean.setOrder(0);
  return bean;
}
 
Example 22
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = jHipsterProperties.getCors();
    if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
        log.debug("Registering CORS filter");
        source.registerCorsConfiguration("/api/**", config);
        source.registerCorsConfiguration("/management/**", config);
        source.registerCorsConfiguration("/v2/api-docs", config);
        source.registerCorsConfiguration("/*/api/**", config);
        source.registerCorsConfiguration("/*/management/**", config);
    }
    return new CorsFilter(source);
}
 
Example 23
Source Project: cubeai   Source File: WebConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = jHipsterProperties.getCors();
    if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
        log.debug("Registering CORS filter");
        source.registerCorsConfiguration("/api/**", config);
        source.registerCorsConfiguration("/management/**", config);
        source.registerCorsConfiguration("/v2/api-docs", config);
    }
    return new CorsFilter(source);
}
 
Example 24
Source Project: java-technology-stack   Source File: AbstractHandlerMapping.java    License: MIT License 5 votes vote down vote up
/**
 * Set the UrlPathHelper to use for resolution of lookup paths.
 * <p>Use this to override the default UrlPathHelper with a custom subclass,
 * or to share common UrlPathHelper settings across multiple HandlerMappings
 * and MethodNameResolvers.
 */
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
	Assert.notNull(urlPathHelper, "UrlPathHelper must not be null");
	this.urlPathHelper = urlPathHelper;
	if (this.corsConfigurationSource instanceof UrlBasedCorsConfigurationSource) {
		((UrlBasedCorsConfigurationSource)this.corsConfigurationSource).setUrlPathHelper(urlPathHelper);
	}
}
 
Example 25
Source Project: spring-analysis-note   Source File: AbstractHandlerMapping.java    License: MIT License 5 votes vote down vote up
/**
 * Shortcut to same property on underlying {@link #setUrlPathHelper UrlPathHelper}.
 * @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath(boolean)
 */
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
	this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath);
	if (this.corsConfigurationSource instanceof UrlBasedCorsConfigurationSource) {
		((UrlBasedCorsConfigurationSource) this.corsConfigurationSource).setAlwaysUseFullPath(alwaysUseFullPath);
	}
}
 
Example 26
Source Project: Showcase   Source File: CorsConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add CORS filter to application context.
 *
 * @param corsProperties the CORS properties to use for CORS configuration
 * @return the configured CORS filter
 */
@Bean
public CorsFilter corsFilter(CorsProperties corsProperties) {
    org.springframework.web.cors.CorsConfiguration config = corsProperties.getConfig();
    config.setAllowedMethods(corsProperties.getAllowedMethods());

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration(corsProperties.getUrlMapping(), config);
    return new CorsFilter(source);
}
 
Example 27
Source Project: spring-analysis-note   Source File: AbstractHandlerMapping.java    License: MIT License 5 votes vote down vote up
/**
 * Shortcut to same property on underlying {@link #setUrlPathHelper UrlPathHelper}.
 * @see org.springframework.web.util.UrlPathHelper#setRemoveSemicolonContent(boolean)
 */
public void setRemoveSemicolonContent(boolean removeSemicolonContent) {
	this.urlPathHelper.setRemoveSemicolonContent(removeSemicolonContent);
	if (this.corsConfigurationSource instanceof UrlBasedCorsConfigurationSource) {
		((UrlBasedCorsConfigurationSource) this.corsConfigurationSource).setRemoveSemicolonContent(removeSemicolonContent);
	}
}
 
Example 28
Source Project: spring-oauth-example   Source File: ResourceServerMain.java    License: MIT License 5 votes vote down vote up
/**
 * This special filter is needed so unauthorized request that are rejected by Spring security
 * still have CORS headers.
 * For some reason he {@code bean.setOrder} call is not enough, the configuration also needs
 * {@code security.filter-order=5} for the CORS filter to be in front of the Spring Security
 * filter.
 */
@Bean
public FilterRegistrationBean corsFilter() {
    //based on https://github.com/spring-projects/spring-boot/issues/5834
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.setAllowedOrigins(Collections.singletonList("*"));
    config.setAllowedMethods(Collections.singletonList("*"));
    config.setAllowedHeaders(Collections.singletonList("*"));
    source.registerCorsConfiguration("/**", config);
    FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setOrder(0);
    return bean;
}
 
Example 29
Source Project: spring-analysis-note   Source File: AbstractHandlerMapping.java    License: MIT License 5 votes vote down vote up
/**
 * Set the PathMatcher implementation to use for matching URL paths
 * against registered URL patterns. Default is AntPathMatcher.
 * @see org.springframework.util.AntPathMatcher
 */
public void setPathMatcher(PathMatcher pathMatcher) {
	Assert.notNull(pathMatcher, "PathMatcher must not be null");
	this.pathMatcher = pathMatcher;
	if (this.corsConfigurationSource instanceof UrlBasedCorsConfigurationSource) {
		((UrlBasedCorsConfigurationSource) this.corsConfigurationSource).setPathMatcher(pathMatcher);
	}
}
 
Example 30
Source Project: jwt-security   Source File: SecurityConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public CorsConfigurationSource corsConfigurationSource() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());

    return source;
}