use of org.springframework.web.filter.CorsFilter in project spring-security by spring-projects.
the class CorsConfigurer method getCorsFilter.
private CorsFilter getCorsFilter(ApplicationContext context) {
if (this.configurationSource != null) {
return new CorsFilter(this.configurationSource);
}
boolean containsCorsFilter = context.containsBeanDefinition(CORS_FILTER_BEAN_NAME);
if (containsCorsFilter) {
return context.getBean(CORS_FILTER_BEAN_NAME, CorsFilter.class);
}
boolean containsCorsSource = context.containsBean(CORS_CONFIGURATION_SOURCE_BEAN_NAME);
if (containsCorsSource) {
CorsConfigurationSource configurationSource = context.getBean(CORS_CONFIGURATION_SOURCE_BEAN_NAME, CorsConfigurationSource.class);
return new CorsFilter(configurationSource);
}
boolean mvcPresent = ClassUtils.isPresent(HANDLER_MAPPING_INTROSPECTOR, context.getClassLoader());
if (mvcPresent) {
return MvcCorsFilter.getMvcCorsFilter(context);
}
return null;
}
use of org.springframework.web.filter.CorsFilter in project spring-security by spring-projects.
the class CorsConfigurer method configure.
@Override
public void configure(H http) throws Exception {
ApplicationContext context = http.getSharedObject(ApplicationContext.class);
CorsFilter corsFilter = getCorsFilter(context);
if (corsFilter == null) {
throw new IllegalStateException("Please configure either a " + CORS_FILTER_BEAN_NAME + " bean or a " + CORS_CONFIGURATION_SOURCE_BEAN_NAME + "bean.");
}
http.addFilter(corsFilter);
}
use of org.springframework.web.filter.CorsFilter in project c4sg-services by Code4SocialGood.
the class RestConfig method corsFilter.
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("DELETE");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
use of org.springframework.web.filter.CorsFilter in project cas by apereo.
the class CasFiltersConfiguration method casCorsFilter.
@ConditionalOnProperty(prefix = "cas.httpWebRequest.cors", name = "enabled", havingValue = "true")
@Bean
@RefreshScope
public FilterRegistrationBean casCorsFilter() {
final HttpWebRequestProperties.Cors cors = casProperties.getHttpWebRequest().getCors();
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(cors.isEnabled());
config.setAllowedOrigins(cors.getAllowOrigins());
config.setAllowedMethods(cors.getAllowMethods());
config.setAllowedHeaders(cors.getAllowHeaders());
config.setMaxAge(cors.getMaxAge());
config.setExposedHeaders(cors.getExposedHeaders());
source.registerCorsConfiguration("/**", config);
final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setName("casCorsFilter");
bean.setAsyncSupported(true);
bean.setOrder(0);
return bean;
}
Aggregations