AI Service CORS 설정 추가로 Swagger UI 테스트 지원
- SecurityConfig에 CORS 설정 추가 - 모든 Origin 허용 (AllowedOriginPatterns: *) - 모든 HTTP Method 허용 (GET, POST, PUT, DELETE, OPTIONS, PATCH) - 모든 Header 허용 - Credentials 지원 - Swagger UI에서 API 테스트 시 CORS 에러 해결 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a23b4eb505
commit
29285d8576
@ -34,6 +34,9 @@ public class SecurityConfig {
|
|||||||
// CSRF 비활성화 (REST API는 CSRF 불필요)
|
// CSRF 비활성화 (REST API는 CSRF 불필요)
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
|
|
||||||
|
// CORS 설정
|
||||||
|
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||||
|
|
||||||
// 세션 사용 안 함 (JWT 기반 인증)
|
// 세션 사용 안 함 (JWT 기반 인증)
|
||||||
.sessionManagement(session ->
|
.sessionManagement(session ->
|
||||||
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
@ -47,6 +50,26 @@ public class SecurityConfig {
|
|||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CORS 설정
|
||||||
|
* - 모든 Origin 허용 (Swagger UI 테스트를 위해)
|
||||||
|
* - 모든 HTTP Method 허용
|
||||||
|
* - 모든 Header 허용
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
|
configuration.setAllowedOriginPatterns(List.of("*")); // 모든 Origin 허용
|
||||||
|
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
|
||||||
|
configuration.setAllowedHeaders(List.of("*"));
|
||||||
|
configuration.setAllowCredentials(true);
|
||||||
|
configuration.setMaxAge(3600L);
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chrome DevTools 요청 등 정적 리소스 요청을 Spring Security에서 제외
|
* Chrome DevTools 요청 등 정적 리소스 요청을 Spring Security에서 제외
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user