Skip to content

Commit a2c2bcb

Browse files
committed
refactor: 라벨 제거,헬스체크 단축 외에 원복
1 parent 36fe822 commit a2c2bcb

6 files changed

Lines changed: 7 additions & 36 deletions

File tree

src/main/java/store/lastdance/config/SecurityConfig.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package store.lastdance.config;
22

3-
import lombok.extern.slf4j.Slf4j;
4-
53

64
import lombok.RequiredArgsConstructor;
75
import org.springframework.context.annotation.Bean;
@@ -21,7 +19,6 @@
2119
import store.lastdance.security.oauth.OAuth2LoginSuccessHandler;
2220
import store.lastdance.util.CookieUtils;
2321

24-
@Slf4j
2522
@Configuration
2623
@RequiredArgsConstructor
2724
public class SecurityConfig {
@@ -57,7 +54,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
5754
// Actuator 경로 허용 (필요시)
5855
.requestMatchers("/actuator/**").permitAll()
5956
// 기타 공개 경로들
60-
.requestMatchers("/error").permitAll()
57+
.requestMatchers("/error", "/favicon.ico").permitAll()
58+
.requestMatchers("/api/v1/notifications/stream").permitAll()
6159
// /api/v1/expenses/analyze 요청은 인증이 필요함 AOP 프록시
6260
.requestMatchers("/api/v1/expenses/analyze").authenticated()
6361
// 나머지 요청은 인증 필요
@@ -70,23 +68,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
7068
// API 요청에 대해서는 401 응답 (로그인 페이지로 리다이렉트 안함)
7169
.exceptionHandling(exceptions -> exceptions
7270
.authenticationEntryPoint((request, response, authException) -> {
73-
if (response.isCommitted()) {
74-
log.debug("Response already committed, cannot send 401 Unauthorized for AuthenticationException.");
75-
return;
76-
}
7771
response.setStatus(HttpStatus.UNAUTHORIZED.value());
7872
response.setContentType("application/json;charset=UTF-8");
7973
response.getWriter().write("{\"error\":\"Unauthorized\",\"message\":\"인증이 필요합니다.\"}");
8074
})
81-
.accessDeniedHandler((request, response, accessDeniedException) -> {
82-
if (response.isCommitted()) {
83-
log.debug("Response already committed, cannot send 403 Forbidden for AccessDeniedException.");
84-
return;
85-
}
86-
response.setStatus(HttpStatus.FORBIDDEN.value());
87-
response.setContentType("application/json;charset=UTF-8");
88-
response.getWriter().write("{\"error\":\"Forbidden\",\"message\":\"접근 권한이 없습니다.\"}");
89-
})
9075
)
9176
.addFilterBefore(new JwtAuthenticationFilter(cookieUtils, authenticationProcessor),
9277
UsernamePasswordAuthenticationFilter.class);

src/main/java/store/lastdance/controller/notification/SSEController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package store.lastdance.controller.notification;
22

3-
import jakarta.servlet.http.HttpServletResponse;
4-
53
import io.swagger.v3.oas.annotations.Operation;
64
import io.swagger.v3.oas.annotations.responses.ApiResponse;
75
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -29,8 +27,8 @@ public class SSEController {
2927
@Operation(summary = "실시간 알림 스트림 연결", description = "SSE를 통한 실시간 알림 수신 연결을 생성합니다.")
3028
@ApiResponse(responseCode = "200", description = "스트림 연결 성공")
3129
@GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
32-
public ResponseEntity<SseEmitter> streamNotifications(@AuthenticationPrincipal CustomOAuth2User user, HttpServletResponse response) {
33-
SseEmitter emitter = sseService.createConnection(user.getUserId(), response);
30+
public ResponseEntity<SseEmitter> streamNotifications(@AuthenticationPrincipal CustomOAuth2User user) {
31+
SseEmitter emitter = sseService.createConnection(user.getUserId());
3432

3533
return ResponseEntity.ok()
3634
.header("Cache-Control", "no-cache")

src/main/java/store/lastdance/exception/GlobalExceptionHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ public ResponseEntity<ErrorResponseDTO> handleMethodArgumentNotValidException(
100100

101101
@ExceptionHandler(RuntimeException.class)
102102
public ResponseEntity<ErrorResponseDTO> handleRuntimeException(RuntimeException e, WebRequest request) {
103-
if (e instanceof org.springframework.security.core.AuthenticationException || e instanceof org.springframework.security.access.AccessDeniedException) {
104-
throw e; // Re-throw to let Spring Security handle it
105-
}
106103
log.error("RuntimeException occurred: {}", e.getMessage(), e);
107104

108105
ErrorResponseDTO errorResponseDTO = ErrorResponseDTO.builder()
@@ -116,10 +113,7 @@ public ResponseEntity<ErrorResponseDTO> handleRuntimeException(RuntimeException
116113
}
117114

118115
@ExceptionHandler(Exception.class)
119-
public ResponseEntity<ErrorResponseDTO> handleGeneralException(Exception e, WebRequest request) throws Exception {
120-
if (e instanceof org.springframework.security.core.AuthenticationException || e instanceof org.springframework.security.access.AccessDeniedException) {
121-
throw e;
122-
}
116+
public ResponseEntity<ErrorResponseDTO> handleGeneralException(Exception e, WebRequest request) {
123117
log.error("Unexpected exception occurred: {}", e.getMessage(), e);
124118

125119
ErrorResponseDTO errorResponseDTO = ErrorResponseDTO.builder()

src/main/java/store/lastdance/service/notification/SSENotificationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.UUID;
77

88
public interface SSENotificationService {
9-
SseEmitter createConnection(UUID userId, jakarta.servlet.http.HttpServletResponse response);
9+
SseEmitter createConnection(UUID userId);
1010
void disconnectUser(UUID userId);
1111
boolean sendNotification(UUID userId, String title, String content, NotificationType type, String relatedId);
1212
boolean isUserOnline(UUID userId);

src/main/java/store/lastdance/service/notification/SSENotificationServiceImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void init() {
5151
private final Map<UUID, ScheduledFuture<?>> heartbeatTasks = new ConcurrentHashMap<>();
5252

5353
@Override
54-
public SseEmitter createConnection(UUID userId, jakarta.servlet.http.HttpServletResponse response) {
54+
public SseEmitter createConnection(UUID userId) {
5555
synchronized (userId.toString().intern()) {
5656
disconnectUser(userId);
5757

@@ -61,12 +61,10 @@ public SseEmitter createConnection(UUID userId, jakarta.servlet.http.HttpServlet
6161
emitter.onCompletion(() -> disconnectUser(userId));
6262
emitter.onTimeout(() -> {
6363
log.warn("SSE 연결 타임아웃: userId={}", userId);
64-
log.debug("SSE Timeout: Response committed status: {}", response.isCommitted());
6564
disconnectUser(userId);
6665
});
6766
emitter.onError(e -> {
6867
log.warn("SSE 연결 오류: userId={}, error={}", userId, e.getMessage());
69-
log.debug("SSE Error: Response committed status: {}", response.isCommitted());
7068
disconnectUser(userId);
7169
});
7270

src/main/resources/application-prod.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ jwt:
164164

165165
logging:
166166
level:
167-
org.springframework.security: DEBUG
168-
org.apache.catalina.connector.Response: DEBUG
169-
org.apache.coyote.Response: DEBUG
170-
org.apache.catalina.connector.CoyoteAdapter: DEBUG
171167
root: WARN
172168
store.lastdance: WARN
173169

0 commit comments

Comments
 (0)