-
Notifications
You must be signed in to change notification settings - Fork 2
[BE] SICS1-212 [FIX] cookie 저장 실패 수정 #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "SISC1-212-BE-\uCFE0\uD0A4-\uC800\uC7A5-\uC2E4\uD328-\uC624\uB958-\uC218\uC815"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import org.sejongisc.backend.common.auth.springsecurity.JwtAuthenticationFilter; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.core.env.Environment; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.security.config.Customizer; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
|
|
@@ -38,6 +39,12 @@ public class SecurityConfig { | |
| private final CustomOidcUserService customOidcUserService; | ||
| private final OAuth2SuccessHandler oAuth2SuccessHandler; | ||
|
|
||
| private final Environment env; | ||
|
|
||
| private boolean isProd() { | ||
| return List.of(env.getActiveProfiles()).contains("prod"); | ||
| } | ||
|
|
||
| @Bean | ||
| public AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository() { | ||
| return new HttpSessionOAuth2AuthorizationRequestRepository(); | ||
|
|
@@ -63,9 +70,13 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti | |
| } | ||
| ) | ||
| .successHandler(oAuth2SuccessHandler) | ||
| .failureHandler((req, res, ex) -> | ||
| res.sendRedirect("http://localhost:5173/oauth/fail") | ||
| ) | ||
| .failureHandler((req, res, ex) -> { | ||
| if (isProd()) { | ||
| res.sendRedirect("https://sisc-web.duckdns.org/oauth/fail"); | ||
| } else { | ||
| res.sendRedirect("http://localhost:5173/oauth/fail"); | ||
| } | ||
| }) | ||
| ) | ||
|
|
||
| .authorizeHttpRequests(auth -> { | ||
|
|
@@ -110,8 +121,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti | |
| @Bean | ||
| public CorsConfigurationSource corsConfigurationSource() { | ||
| CorsConfiguration config = new CorsConfiguration(); | ||
| config.setAllowedOrigins(List.of( | ||
| "http://localhost:5173", // 허용할 프론트 주소 | ||
| config.setAllowedOriginPatterns(List.of( | ||
| "http://localhost:5173", | ||
| "https://sisc-web.duckdns.org" | ||
| )); | ||
|
Comment on lines
+124
to
127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainsetAllowedOriginPatterns 사용을 확인하세요.
현재 구현은 정상 작동하지만, 와일드카드를 사용하지 않는다면 다음 스크립트로 CORS 설정이 올바르게 작동하는지 확인하세요: 🏁 Script executed: #!/bin/bash
# Description: 두 출처에서 CORS preflight 요청 테스트
echo "Testing localhost origin..."
curl -X OPTIONS http://localhost:8080/api/auth/login \
-H "Origin: http://localhost:5173" \
-H "Access-Control-Request-Method: POST" \
-v 2>&1 | grep -i "access-control"
echo -e "\n\nTesting production origin..."
curl -X OPTIONS https://sisc-web.duckdns.org/api/auth/login \
-H "Origin: https://sisc-web.duckdns.org" \
-H "Access-Control-Request-Method: POST" \
-v 2>&1 | grep -i "access-control"Length of output: 425 로컬호스트 CORS 요청이 실패하고 있습니다. 추가 정보가 필요합니다. 🏁 Script executed: #!/bin/bash
# SecurityConfig 파일의 전체 CORS 설정 확인
echo "=== SecurityConfig.java 전체 내용 확인 ==="
find . -name "SecurityConfig.java" -type f | head -5
echo -e "\n=== CORS 관련 설정 확인 ==="
find . -name "SecurityConfig.java" -exec grep -A 20 -B 5 "setAllowedOriginPatterns\|setAllowedOrigins\|CORS\|cors" {} +
echo -e "\n=== 프로젝트에서 CorsConfigurationSource 검색 ==="
rg -n "CorsConfigurationSource|cors" --type=java -A 3 -B 3Length of output: 7691 🏁 Script executed: #!/bin/bash
# 전체 SecurityConfig.java 파일 확인 및 CORS 설정 검증
echo "=== SecurityConfig.java 파일 위치 찾기 ==="
find . -name "SecurityConfig.java" -type f
echo -e "\n=== SecurityConfig.java 전체 내용 ==="
cat ./backend/src/main/java/org/sejongisc/backend/common/auth/config/SecurityConfig.java
echo -e "\n\n=== 프로젝트 전체에서 CORS 관련 설정 검색 ==="
rg -n "CorsConfigurationSource|setAllowedOrigin|allowCredentials" --type=java -B 2 -A 2Length of output: 9264 localhost CORS 프리플라이트 요청이 실패하고 있습니다. 즉시 수정 필요. setAllowedOriginPatterns은 와일드카드 패턴을 위한 것("*" 및 포트 범위)이며 정확한 문자열 매칭을 위한 것이 아닙니다. 현재 코드는 문자열 리터럴로 이 메서드를 사용하고 있어서 localhost 요청이 CORS 필터링을 통과하지 못합니다.
config.setAllowedOrigins(List.of(
"http://localhost:5173",
"https://sisc-web.duckdns.org"
));🤖 Prompt for AI Agents |
||
| config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
isProd() 메서드가 깔끔하게 구현되었습니다.
환경 판별 로직이 잘 캡슐화되어 있습니다. 하지만 OAuth2SuccessHandler에서 중복 구현되고 있으니, 공통 유틸리티로 추출하는 것을 고려하세요.
🤖 Prompt for AI Agents