diff --git a/skill-tree/pom.xml b/skill-tree/pom.xml index b33f4826..3d5716bc 100644 --- a/skill-tree/pom.xml +++ b/skill-tree/pom.xml @@ -85,6 +85,10 @@ junit-jupiter test + + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-actuator diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Config/SecurityConfig.java b/skill-tree/src/main/java/com/RDS/skilltree/Config/SecurityConfig.java new file mode 100644 index 00000000..f45b8f41 --- /dev/null +++ b/skill-tree/src/main/java/com/RDS/skilltree/Config/SecurityConfig.java @@ -0,0 +1,39 @@ +package com.RDS.skilltree.Config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +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.configurers.AbstractHttpConfigurer; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; + +import java.util.Arrays; +import java.util.List; + +@EnableWebSecurity +@Configuration +public class SecurityConfig { + + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http.csrf(AbstractHttpConfigurer::disable) + .cors(httpSecurityCorsConfigurer -> httpSecurityCorsConfigurer.configurationSource(corsConfigurationSource())); + return http.build(); + } + @Bean + public CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowedOriginPatterns(List.of("https://*.realdevsquad.com", "http://localhost:[*]")); + configuration.setAllowedMethods(Arrays.asList(HttpMethod.HEAD.name(), HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.DELETE.name(), HttpMethod.PUT.name())); + configuration.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type")); + configuration.setAllowCredentials(true); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + return source; + } +} diff --git a/skill-tree/src/main/resources/application.properties b/skill-tree/src/main/resources/application.properties index 693cd87d..e52bc361 100644 --- a/skill-tree/src/main/resources/application.properties +++ b/skill-tree/src/main/resources/application.properties @@ -8,4 +8,4 @@ jwt.rds.public.key=${RDS_PUBLIC_KEY} API_V1_PREFIX=/api/v1 spring.datasource.version=8.1.0 management.endpoints.web.exposure.include=health,info,metrics - +logging.level.root=ERROR