/** * 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); } }
/** * 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); } }
@Bean @ConditionalOnClass(CorsFilter.class) @ConditionalOnProperty(value = "graphql.servlet.corsEnabled", havingValue = "true", matchIfMissing = true) public CorsFilter corsConfigurer() { UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource(); configurationSource.setCorsConfigurations(CorsRegistryWorkaround.getCorsConfiguration(graphQLServletProperties.getCorsMapping())); configurationSource.setAlwaysUseFullPath(true); return new CorsFilter(configurationSource); }
@Bean public CorsConfigurationSource corsConfigurationSource( @Value("${rest.cors.enabled:false}") boolean enabled, @Value("${rest.cors.allowedOrigins:}") List<String> allowedOrigins, @Value("${rest.cors.allowedMethods:PUT,POST,GET,OPTIONS,DELETE,HEAD}") List<String> allowedMethods, @Value("${rest.cors.allowedHeaders:content-type,x-requested-with,authorization}") List<String> allowedHeaders, @Value("${rest.cors.exposedHeaders:}") List<String> exposedHeaders, @Value("${rest.cors.allowCredentials:false}") boolean allowCredentials, @Value("${rest.cors.maxAge:3600}") long maxAge) { if (!enabled) return null; CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(allowedOrigins); configuration.setAllowedMethods(allowedMethods); configuration.setAllowedHeaders(allowedHeaders); configuration.setExposedHeaders(exposedHeaders); configuration.setAllowCredentials(allowCredentials); configuration.setMaxAge(maxAge); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.setAlwaysUseFullPath(true); //Don't chop off the starting /rest stuff source.registerCorsConfiguration("/rest/**", configuration); return source; }