Skip to content
Snippets Groups Projects
Commit 7b54c81e authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Merge branch 'fix-public-cors' into '2.x'

Only enable full CORS config if a domain is specified

See merge request !85
parents c58cd000 e3915655
Branches
Tags
1 merge request!85Only enable full CORS config if a domain is specified
Pipeline #15249 passed with stages
in 1 minute and 45 seconds
......@@ -36,30 +36,31 @@ public class CorsFilter extends org.springframework.web.filter.CorsFilter {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config;
/* Grant full access from specified origins */
config = new CorsConfiguration();
config.setAllowedOrigins(origins);
config.addAllowedHeader("Accept");
config.addAllowedHeader("Content-Type");
config.addAllowedHeader("X-Requested-With");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("DELETE");
config.setAllowCredentials(true);
source.registerCorsConfiguration("/**", config);
/* Grant limited access from all origins */
config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("Accept");
config.addAllowedHeader("X-Requested-With");
config.addAllowedMethod("GET");
config.setAllowCredentials(true);
source.registerCorsConfiguration("/", config);
source.registerCorsConfiguration("/arsnova-config", config);
source.registerCorsConfiguration("/configuration/", config);
source.registerCorsConfiguration("/statistics", config);
if (!origins.isEmpty()) {
/* Grant full access from specified origins */
config = new CorsConfiguration();
config.setAllowedOrigins(origins);
config.addAllowedHeader("Accept");
config.addAllowedHeader("Content-Type");
config.addAllowedHeader("X-Requested-With");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("DELETE");
config.setAllowCredentials(true);
source.registerCorsConfiguration("/**", config);
} else {
/* Grant limited access from all origins */
config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.addAllowedHeader("Accept");
config.addAllowedHeader("X-Requested-With");
config.addAllowedMethod("GET");
source.registerCorsConfiguration("/", config);
source.registerCorsConfiguration("/arsnova-config", config);
source.registerCorsConfiguration("/configuration/", config);
source.registerCorsConfiguration("/statistics", config);
}
return source;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment