|
|
|
|
@@ -3,6 +3,7 @@ package com.kamco.cd.training.config;
|
|
|
|
|
import com.kamco.cd.training.auth.CustomAuthenticationProvider;
|
|
|
|
|
import com.kamco.cd.training.auth.JwtAuthenticationFilter;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
@@ -25,6 +26,9 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
@EnableWebSecurity
|
|
|
|
|
public class SecurityConfig {
|
|
|
|
|
|
|
|
|
|
@Value("${cors.allowed-origins}")
|
|
|
|
|
private List<String> allowedOrigins;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public SecurityFilterChain securityFilterChain(
|
|
|
|
|
org.springframework.security.config.annotation.web.builders.HttpSecurity http,
|
|
|
|
|
@@ -104,15 +108,19 @@ public class SecurityConfig {
|
|
|
|
|
return new BCryptPasswordEncoder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** CORS 설정 */
|
|
|
|
|
/** CORS 설정 - application.yml에서 환경별로 관리 */
|
|
|
|
|
@Bean
|
|
|
|
|
public CorsConfigurationSource corsConfigurationSource() {
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); // CORS 객체 생성
|
|
|
|
|
config.setAllowedOriginPatterns(List.of("*")); // 도메인 허용
|
|
|
|
|
|
|
|
|
|
// application.yml에서 환경별로 설정된 도메인 사용
|
|
|
|
|
config.setAllowedOriginPatterns(allowedOrigins);
|
|
|
|
|
|
|
|
|
|
config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
|
|
|
|
|
config.setAllowedHeaders(List.of("*")); // 헤더요청 Authorization, Content-Type, X-Custom-Header
|
|
|
|
|
config.setAllowCredentials(true); // 쿠키, Authorization 헤더, Bearer Token 등 자격증명 포함 요청을 허용할지 설정
|
|
|
|
|
config.setExposedHeaders(List.of("Content-Disposition"));
|
|
|
|
|
config.setExposedHeaders(List.of("Content-Disposition", "Authorization"));
|
|
|
|
|
config.setMaxAge(3600L); // Preflight 요청 캐시 (1시간)
|
|
|
|
|
|
|
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
|
|
/** "/**" → 모든 API 경로에 대해 이 CORS 규칙을 적용 /api/** 같이 특정 경로만 지정 가능. */
|
|
|
|
|
|