|
1 | 1 | package com.studybuddies.server.configuration; |
2 | 2 |
|
| 3 | +import lombok.extern.slf4j.Slf4j; |
| 4 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 5 | +import org.springframework.context.annotation.Bean; |
3 | 6 | import org.springframework.context.annotation.Configuration; |
4 | 7 | import org.springframework.context.annotation.Profile; |
| 8 | +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; |
5 | 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
6 | 10 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
7 | | -import org.springframework.security.config.annotation.web.configurers.CorsConfigurer; |
8 | 11 | import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; |
9 | 12 | import org.springframework.security.web.SecurityFilterChain; |
| 13 | +import org.springframework.web.cors.CorsConfigurationSource; |
10 | 14 |
|
11 | 15 | @Profile("dev") |
12 | 16 | @Configuration |
| 17 | +@Slf4j |
13 | 18 | @EnableWebSecurity |
| 19 | +@EnableMethodSecurity(securedEnabled = true) |
14 | 20 | public class DevConfig { |
15 | | - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { |
16 | | - http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); |
| 21 | + |
| 22 | + @Qualifier("cors") |
| 23 | + private CorsConfigurationSource corsConfigurationSource; |
| 24 | + |
| 25 | + @Bean |
| 26 | + public SecurityFilterChain devChain(HttpSecurity http) throws Exception { |
| 27 | + log.info("Dev configuring SecurityFilterChain"); |
| 28 | + http.cors(c -> c.configurationSource(corsConfigurationSource)); |
| 29 | + http.securityMatcher("/**"); |
17 | 30 | http.csrf(CsrfConfigurer::disable); |
18 | | - http.cors(CorsConfigurer::disable); |
| 31 | + http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); |
19 | 32 | return http.build(); |
20 | 33 | } |
21 | 34 | } |
0 commit comments