From 0e9e59169845ddaa98d2cdb17d4591971c66278f Mon Sep 17 00:00:00 2001 From: codeforkjeff Date: Sun, 24 May 2020 18:26:04 -0700 Subject: [PATCH] #19: add CORS support --- pom.xml | 4 ++++ .../java/com/codefork/refine/Application.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pom.xml b/pom.xml index 3110d42..0bb76fc 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,10 @@ org.springframework.boot spring-boot-starter-cache + + org.springframework.boot + spring-boot-starter-security + org.ehcache ehcache diff --git a/src/main/java/com/codefork/refine/Application.java b/src/main/java/com/codefork/refine/Application.java index da7845b..dea0f81 100644 --- a/src/main/java/com/codefork/refine/Application.java +++ b/src/main/java/com/codefork/refine/Application.java @@ -15,10 +15,16 @@ import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.filter.CommonsRequestLoggingFilter; import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -95,4 +101,18 @@ public CommonsRequestLoggingFilter logFilter() { return filter; } + @EnableWebSecurity + public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.headers().disable(); + http.csrf().disable(); + http.cors().configurationSource(request -> { + CorsConfiguration c = new CorsConfiguration(); + c.setAllowedOrigins(new ArrayList(Arrays.asList("*"))); + return c; + }); + } + } } \ No newline at end of file