Skip to content

Commit 7438c44

Browse files
authored
[BACKEND] SSE 비동기 요청에서 AccessDeniedException 발생 문제 수정 (#115)
## #️⃣연관된 이슈 > ex) #이슈번호, #이슈번호 ## 📝작업 내용 > 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능) ### 스크린샷 (선택) ## 💬리뷰 요구사항(선택) > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요 > > ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?
1 parent 14de567 commit 7438c44

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

backend/src/main/java/com/cmg/comtogether/common/security/config/SecurityConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import com.cmg.comtogether.common.security.CustomAccessDeniedHandler;
44
import com.cmg.comtogether.common.security.CustomAuthenticationEntryPoint;
55
import com.cmg.comtogether.jwt.filter.JwtAuthenticationFilter;
6+
import jakarta.annotation.PostConstruct;
67
import lombok.RequiredArgsConstructor;
78
import org.springframework.context.annotation.Bean;
89
import org.springframework.context.annotation.Configuration;
910
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1011
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1112
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
1213
import org.springframework.security.config.http.SessionCreationPolicy;
14+
import org.springframework.security.core.context.SecurityContextHolder;
1315
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1416
import org.springframework.security.crypto.password.PasswordEncoder;
1517
import org.springframework.security.web.SecurityFilterChain;
1618
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1719
import org.springframework.web.cors.CorsConfigurationSource;
20+
import jakarta.servlet.DispatcherType;
1821

1922
@Configuration
2023
@EnableWebSecurity
@@ -25,9 +28,17 @@ public class SecurityConfig {
2528
private final CustomAuthenticationEntryPoint authenticationEntryPoint;
2629
private final CustomAccessDeniedHandler accessDeniedHandler;
2730

31+
@PostConstruct
32+
public void enableThreadSecurityContextPropagation() {
33+
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
34+
}
35+
2836
@Bean
2937
public SecurityFilterChain securityFilterChain(HttpSecurity http, CorsConfigurationSource corsConfigurationSource) throws Exception {
3038
http
39+
// async dispatch는 Security 필터 적용 대상에서 제외
40+
.securityMatcher(request -> request.getDispatcherType() != DispatcherType.ASYNC)
41+
3142
.csrf(AbstractHttpConfigurer::disable) // CSRF 비활성화
3243
.httpBasic(AbstractHttpConfigurer::disable) // Basic Auth 비활성화
3344
.formLogin(AbstractHttpConfigurer::disable) // Form Login 비활성화

backend/src/main/java/com/cmg/comtogether/compatibility/service/CompatibilityCheckService.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ private void checkCpuMotherboardCompatibility(
152152
response, 1, "CPU ↔ 메인보드 호환성"
153153
);
154154

155-
sendResultWithDelay(result, resultCallback);
156155

157156
} catch (Exception e) {
158157
log.error("CPU ↔ 메인보드 호환성 검사 중 오류 발생", e);
@@ -623,19 +622,6 @@ private void checkOsCompatibility(
623622
}
624623
}
625624

626-
/**
627-
* 결과 전송 전 딜레이 추가 (테스트용: 실시간 스트리밍 확인)
628-
* 체크 ID * 0.5초씩 딜레이를 추가하여 순차적으로 결과가 오는 것을 확인 가능
629-
*/
630-
private void sendResultWithDelay(CompatibilityCheckResultDto result, Consumer<CompatibilityCheckResultDto> resultCallback) {
631-
// 테스트용: 실시간 스트리밍 확인을 위한 딜레이 (체크 ID * 0.5초)
632-
try {
633-
Thread.sleep(500 * result.getCheckId());
634-
} catch (InterruptedException e) {
635-
Thread.currentThread().interrupt();
636-
}
637-
resultCallback.accept(result);
638-
}
639625

640626
/**
641627
* 카테고리에서 아이템 가져오기 (헬퍼 메서드)

0 commit comments

Comments
 (0)