Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated CORS configuration #578

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions src/main/java/org/fairdatapoint/api/filter/CORSFilter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ public class FilterConfigurer extends

private final JwtTokenFilter jwtTokenFilter;

private final CORSFilter corsFilter;

private final LoggingFilter loggingFilter;

@Override
public void configure(HttpSecurity http) {
http.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
http.addFilterBefore(corsFilter, JwtTokenFilter.class);
http.addFilterBefore(loggingFilter, CORSFilter.class);
http.addFilterBefore(loggingFilter, JwtTokenFilter.class);
}

}
18 changes: 18 additions & 0 deletions src/main/java/org/fairdatapoint/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

Expand Down Expand Up @@ -85,4 +87,20 @@ public ObjectMapper objectMapper() {
public InternalResourceViewResolver defaultViewResolver() {
return new InternalResourceViewResolver();
}

// https://docs.spring.io/spring-framework/reference/web/webmvc-cors.html
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
// todo: what about OPTIONS?
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE")
.allowedHeaders(
HttpHeaders.ORIGIN,
HttpHeaders.AUTHORIZATION,
HttpHeaders.ACCEPT,
HttpHeaders.CONTENT_TYPE)
.exposedHeaders(HttpHeaders.LOCATION, HttpHeaders.LINK);
}

}
Loading