public CorsRegistration(String pathPattern) { this.pathPattern = pathPattern; // Same implicit default values as the @CrossOrigin annotation + allows simple methods this.config = new CorsConfiguration().applyPermitDefaultValues(); }
public CorsRegistration(String pathPattern) { this.pathPattern = pathPattern; this.config = new CorsConfiguration().applyPermitDefaultValues(); }
public CorsRegistration(String pathPattern) { this.pathPattern = pathPattern; // Same implicit default values as the @CrossOrigin annotation + allows simple methods this.config = new CorsConfiguration().applyPermitDefaultValues(); }
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues(); corsConfigurations.put("/**", config); config.setMaxAge(Long.parseLong(mapping.getAttribute("max-age"))); corsConfigurations.put(mapping.getAttribute("path"), config.applyPermitDefaultValues());
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues(); corsConfigurations.put("/**", config); config.setMaxAge(Long.parseLong(mapping.getAttribute("max-age"))); corsConfigurations.put(mapping.getAttribute("path"), config.applyPermitDefaultValues());
@Override protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { HandlerMethod handlerMethod = createHandlerMethod(handler, method); Class<?> beanType = handlerMethod.getBeanType(); CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class); CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class); if (typeAnnotation == null && methodAnnotation == null) { return null; } CorsConfiguration config = new CorsConfiguration(); updateCorsConfig(config, typeAnnotation); updateCorsConfig(config, methodAnnotation); if (CollectionUtils.isEmpty(config.getAllowedMethods())) { for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) { config.addAllowedMethod(allowedMethod.name()); } } return config.applyPermitDefaultValues(); }
@Override protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { HandlerMethod handlerMethod = createHandlerMethod(handler, method); Class<?> beanType = handlerMethod.getBeanType(); CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class); CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class); if (typeAnnotation == null && methodAnnotation == null) { return null; } CorsConfiguration config = new CorsConfiguration(); updateCorsConfig(config, typeAnnotation); updateCorsConfig(config, methodAnnotation); if (CollectionUtils.isEmpty(config.getAllowedMethods())) { for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) { config.addAllowedMethod(allowedMethod.name()); } } return config.applyPermitDefaultValues(); }
@Test // SPR-15772 public void changePermitDefaultValues() { CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues(); config.addAllowedOrigin("http://domain.com"); config.addAllowedHeader("header1"); config.addAllowedMethod("PATCH"); assertEquals(Arrays.asList("*", "http://domain.com"), config.getAllowedOrigins()); assertEquals(Arrays.asList("*", "header1"), config.getAllowedHeaders()); assertEquals(Arrays.asList("GET", "HEAD", "POST", "PATCH"), config.getAllowedMethods()); }
@Override protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { HandlerMethod handlerMethod = createHandlerMethod(handler, method); Class<?> beanType = handlerMethod.getBeanType(); CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class); CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class); if (typeAnnotation == null && methodAnnotation == null) { return null; } CorsConfiguration config = new CorsConfiguration(); updateCorsConfig(config, typeAnnotation); updateCorsConfig(config, methodAnnotation); if (CollectionUtils.isEmpty(config.getAllowedMethods())) { for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) { config.addAllowedMethod(allowedMethod.name()); } } return config.applyPermitDefaultValues(); }
@Test // SPR-15772 public void combineWithDefaultPermitValues() { CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues(); CorsConfiguration other = new CorsConfiguration(); other.addAllowedOrigin("http://domain.com"); other.addAllowedHeader("header1"); other.addAllowedMethod(HttpMethod.PUT.name()); CorsConfiguration combinedConfig = config.combine(other); assertEquals(Arrays.asList("http://domain.com"), combinedConfig.getAllowedOrigins()); assertEquals(Arrays.asList("header1"), combinedConfig.getAllowedHeaders()); assertEquals(Arrays.asList(HttpMethod.PUT.name()), combinedConfig.getAllowedMethods()); combinedConfig = other.combine(config); assertEquals(Arrays.asList("http://domain.com"), combinedConfig.getAllowedOrigins()); assertEquals(Arrays.asList("header1"), combinedConfig.getAllowedHeaders()); assertEquals(Arrays.asList(HttpMethod.PUT.name()), combinedConfig.getAllowedMethods()); combinedConfig = config.combine(new CorsConfiguration()); assertEquals(Arrays.asList("*"), config.getAllowedOrigins()); assertEquals(Arrays.asList("*"), config.getAllowedHeaders()); assertEquals(Arrays.asList(HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name()), combinedConfig.getAllowedMethods()); combinedConfig = new CorsConfiguration().combine(config); assertEquals(Arrays.asList("*"), config.getAllowedOrigins()); assertEquals(Arrays.asList("*"), config.getAllowedHeaders()); assertEquals(Arrays.asList(HttpMethod.GET.name(), HttpMethod.HEAD.name(), HttpMethod.POST.name()), combinedConfig.getAllowedMethods()); }
Map<String, String> configData = configComponent.getConfigData(site.getId(), CONFIG_CODE); config = new CorsConfiguration(); config.applyPermitDefaultValues(); if (null != configData) { config = new CorsConfiguration();
Map<String, String> configData = configComponent.getConfigData(site.getId(), CONFIG_CODE); config = new CorsConfiguration(); config.applyPermitDefaultValues(); if (null != configData) { config = new CorsConfiguration();
return config.applyPermitDefaultValues();
return config.applyPermitDefaultValues();
@Bean CorsConfigurationSource corsConfigurationSource() { final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues()); return source; } }
@Bean CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration().applyPermitDefaultValues(); configuration.setAllowedMethods(Arrays.asList("POST", "GET", "PUT", "DELETE", "OPTIONS")); final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; }
@Bean public FilterRegistrationBean corsFilterRegistrationBean() { CorsConfiguration config = new CorsConfiguration(); config.applyPermitDefaultValues(); config.setAllowCredentials(corsConfigProperties.getAllowCredentials()); config.setAllowedOrigins(corsConfigProperties.getAllowedOrigins()); config.setAllowedHeaders(corsConfigProperties.getAllowedHeaders()); config.setAllowedMethods(corsConfigProperties.getAllowedMethods()); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); return new FilterRegistrationBean(new CorsFilter(source)); } }
@Bean public FilterRegistrationBean corsFilterRegistrationBean() { CorsConfiguration config = new CorsConfiguration(); config.applyPermitDefaultValues(); config.setAllowCredentials(corsConfigProperties.getAllowCredentials()); config.setAllowedOrigins(corsConfigProperties.getAllowedOrigins()); config.setAllowedHeaders(corsConfigProperties.getAllowedHeaders()); config.setAllowedMethods(corsConfigProperties.getAllowedMethods()); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); return new FilterRegistrationBean(new CorsFilter(source)); } }
@Bean public FilterRegistrationBean corsFilterRegistrationBean() { CorsConfiguration config = new CorsConfiguration(); config.applyPermitDefaultValues(); config.setAllowCredentials(corsConfigProperties.getAllowCredentials()); config.setAllowedOrigins(corsConfigProperties.getAllowedOrigins()); config.setAllowedHeaders(corsConfigProperties.getAllowedHeaders()); config.setAllowedMethods(corsConfigProperties.getAllowedMethods()); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); return new FilterRegistrationBean(new CorsFilter(source)); } }
@Bean public FilterRegistrationBean corsFilterRegistrationBean() { CorsConfiguration config = new CorsConfiguration(); config.applyPermitDefaultValues(); config.setAllowCredentials(corsConfigProperties.getAllowCredentials()); config.setAllowedOrigins(corsConfigProperties.getAllowedOrigins()); config.setAllowedHeaders(corsConfigProperties.getAllowedHeaders()); config.setAllowedMethods(corsConfigProperties.getAllowedMethods()); config.setMaxAge(corsConfigProperties.getMaxAge()); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); return new FilterRegistrationBean(new CorsFilter(source)); }