From da86542940257ecee58271b6cc84ae7f436b5820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Tue, 29 Jul 2025 17:07:43 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20cors=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../join/member/security/SecurityConfig.java | 20 ++++++++++++++++++- .../handshake/CustomHandshakeHandler.java | 1 - 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java b/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java index 582dac7..8332001 100644 --- a/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java +++ b/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java @@ -2,6 +2,8 @@ import static org.springframework.security.config.Customizer.*; +import java.util.List; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -9,6 +11,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import lombok.RequiredArgsConstructor; @@ -23,7 +28,7 @@ public class SecurityConfig { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .csrf(csrf -> csrf.disable()) - .cors(cors -> cors.disable()) + .cors(cors -> cors.configurationSource(corsConfigurationSource())) .authorizeHttpRequests(auth -> auth .requestMatchers( "/api/auth/guest", @@ -51,4 +56,17 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .logout(withDefaults()) .build(); } + + @Bean + public CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowCredentials(true); + configuration.setAllowedOriginPatterns(List.of("*")); + configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders(List.of("*")); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + return source; + } } diff --git a/src/main/java/com/oronaminc/join/websocket/handshake/CustomHandshakeHandler.java b/src/main/java/com/oronaminc/join/websocket/handshake/CustomHandshakeHandler.java index 2b5b78a..9910dae 100644 --- a/src/main/java/com/oronaminc/join/websocket/handshake/CustomHandshakeHandler.java +++ b/src/main/java/com/oronaminc/join/websocket/handshake/CustomHandshakeHandler.java @@ -58,5 +58,4 @@ protected Principal determineUser(ServerHttpRequest request, WebSocketHandler ws // fallback 경로로 전송 return null; } - } From ea7a8694140402c57d5ac5d116ad5b825486c20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 10:16:02 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../join/websocket/config/WebSocketConfig.java | 13 ++++++------- .../session/CurrentParticipantEventHandler.java | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java index a2afca6..0f1cfc2 100644 --- a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java +++ b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java @@ -9,7 +9,6 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory; -import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; import com.oronaminc.join.websocket.handshake.CustomHandshakeHandler; import com.oronaminc.join.websocket.session.CustomWebSocketHandlerDecorator; @@ -48,15 +47,15 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") // websocket 연결 전 쿠키 체크 - .addInterceptors(new HttpSessionHandshakeInterceptor()) + // .addInterceptors(new HttpSessionHandshakeInterceptor()) // websocket 연결 후 principal 생성 - .setHandshakeHandler(handshakeHandler) + // .setHandshakeHandler(handshakeHandler) .withSockJS(); - registry.addEndpoint("/ws") - .setAllowedOriginPatterns("*") - .addInterceptors(new HttpSessionHandshakeInterceptor()) - .setHandshakeHandler(handshakeHandler); + // registry.addEndpoint("/ws") + // .setAllowedOriginPatterns("*") + // .addInterceptors(new HttpSessionHandshakeInterceptor()) + // .setHandshakeHandler(handshakeHandler); registry.setErrorHandler(stompErrorHandler); } diff --git a/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java b/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java index c6b25c2..83d9bf3 100644 --- a/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java +++ b/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java @@ -2,7 +2,6 @@ import static com.oronaminc.join.global.exception.ErrorCode.*; -import com.oronaminc.join.global.exception.ErrorCode; import java.security.Principal; import java.util.Set; From 9ece1cc4dc9dece270fd405b7e4f819bdf08991d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 10:16:45 +0900 Subject: [PATCH 3/9] =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oronaminc/join/websocket/config/WebSocketConfig.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java index 0f1cfc2..797a0c9 100644 --- a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java +++ b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java @@ -52,10 +52,11 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { // .setHandshakeHandler(handshakeHandler) .withSockJS(); - // registry.addEndpoint("/ws") - // .setAllowedOriginPatterns("*") - // .addInterceptors(new HttpSessionHandshakeInterceptor()) - // .setHandshakeHandler(handshakeHandler); + registry.addEndpoint("/ws") + .setAllowedOriginPatterns("*") + // .addInterceptors(new HttpSessionHandshakeInterceptor()) + // .setHandshakeHandler(handshakeHandler) + ; registry.setErrorHandler(stompErrorHandler); } From b9b53ad59377e39358efc60d109347df9091ee22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 10:46:40 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/QuestionWebsocketController.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java b/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java index 7186fb2..a0fb291 100644 --- a/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java +++ b/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java @@ -1,5 +1,13 @@ package com.oronaminc.join.websocket.api; +import java.security.Principal; + +import org.springframework.messaging.handler.annotation.DestinationVariable; +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.messaging.handler.annotation.SendTo; +import org.springframework.stereotype.Controller; + import com.oronaminc.join.global.exception.ErrorCode; import com.oronaminc.join.global.exception.ErrorException; import com.oronaminc.join.global.ratelimit.RateLimitService; @@ -11,16 +19,11 @@ import com.oronaminc.join.question.dto.QuestionUpdateResponse; import com.oronaminc.join.question.service.QuestionService; import com.oronaminc.join.question.util.QuestionMapper; + import io.github.bucket4j.Bucket; import jakarta.validation.Valid; -import java.security.Principal; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.messaging.handler.annotation.DestinationVariable; -import org.springframework.messaging.handler.annotation.MessageMapping; -import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.messaging.handler.annotation.SendTo; -import org.springframework.stereotype.Controller; @Slf4j @Controller @@ -37,8 +40,12 @@ public QuestionCreateResponse createQuestion( @Payload @Valid QuestionRequest request, Principal principal ) { + log.debug("수신한 메시지 = {}", request.content()); + Long memberId = Long.valueOf(principal.getName()); + log.debug("회원 아이디 = {}", memberId); + Bucket bucket = rateLimitService.getBucket(RateLimitType.CREATE_QUESTION, roomId, memberId); if (!bucket.tryConsume(1)) { @@ -47,7 +54,6 @@ public QuestionCreateResponse createQuestion( Question question = questionService.create(roomId, memberId, request); - log.info("수신한 메시지 = {}", request.content()); return QuestionMapper.toQuestionCreateResponse(question); } From 63cd18c75b2b9d4e2ef37b3fad375c8942837dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 10:54:21 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oronaminc/join/websocket/config/WebSocketConfig.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java index 797a0c9..be7c913 100644 --- a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java +++ b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java @@ -9,6 +9,7 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory; +import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; import com.oronaminc.join.websocket.handshake.CustomHandshakeHandler; import com.oronaminc.join.websocket.session.CustomWebSocketHandlerDecorator; @@ -47,15 +48,15 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") // websocket 연결 전 쿠키 체크 - // .addInterceptors(new HttpSessionHandshakeInterceptor()) + .addInterceptors(new HttpSessionHandshakeInterceptor()) // websocket 연결 후 principal 생성 - // .setHandshakeHandler(handshakeHandler) + .setHandshakeHandler(handshakeHandler) .withSockJS(); registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") - // .addInterceptors(new HttpSessionHandshakeInterceptor()) - // .setHandshakeHandler(handshakeHandler) + .addInterceptors(new HttpSessionHandshakeInterceptor()) + .setHandshakeHandler(handshakeHandler) ; registry.setErrorHandler(stompErrorHandler); From 9ba25449161905463dffbe05880773f1200853c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 12:09:34 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/QuestionWebsocketController.java | 6 ++- .../config/StompAuthChannelInterceptor.java | 29 ++++++++++++ .../websocket/config/WebSocketConfig.java | 16 ++++--- .../CurrentParticipantEventHandler.java | 44 +++++++++---------- 4 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/oronaminc/join/websocket/config/StompAuthChannelInterceptor.java diff --git a/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java b/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java index a0fb291..773828b 100644 --- a/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java +++ b/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java @@ -6,12 +6,14 @@ import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.handler.annotation.SendTo; +import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import com.oronaminc.join.global.exception.ErrorCode; import com.oronaminc.join.global.exception.ErrorException; import com.oronaminc.join.global.ratelimit.RateLimitService; import com.oronaminc.join.global.ratelimit.RateLimitType; +import com.oronaminc.join.member.security.MemberDetails; import com.oronaminc.join.question.domain.Question; import com.oronaminc.join.question.dto.QuestionCreateResponse; import com.oronaminc.join.question.dto.QuestionDeleteResponse; @@ -42,7 +44,8 @@ public QuestionCreateResponse createQuestion( ) { log.debug("수신한 메시지 = {}", request.content()); - Long memberId = Long.valueOf(principal.getName()); + MemberDetails memberDetails = (MemberDetails)((Authentication)principal).getPrincipal(); + Long memberId = Long.valueOf(memberDetails.getId()); log.debug("회원 아이디 = {}", memberId); @@ -66,6 +69,7 @@ public QuestionUpdateResponse updateQuestion( @Payload @Valid QuestionRequest request, Principal principal ) { + Long memberId = Long.valueOf(principal.getName()); Question updated = questionService.update(memberId, roomId, questionId, request); diff --git a/src/main/java/com/oronaminc/join/websocket/config/StompAuthChannelInterceptor.java b/src/main/java/com/oronaminc/join/websocket/config/StompAuthChannelInterceptor.java new file mode 100644 index 0000000..0cc944d --- /dev/null +++ b/src/main/java/com/oronaminc/join/websocket/config/StompAuthChannelInterceptor.java @@ -0,0 +1,29 @@ +package com.oronaminc.join.websocket.config; + +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.simp.stomp.StompCommand; +import org.springframework.messaging.simp.stomp.StompHeaderAccessor; +import org.springframework.messaging.support.ChannelInterceptor; +import org.springframework.messaging.support.MessageHeaderAccessor; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; + +@Component +public class StompAuthChannelInterceptor implements ChannelInterceptor { + @Override + public Message preSend(Message message, MessageChannel channel) { + StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); + + if (StompCommand.CONNECT.equals(accessor.getCommand())) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + if (authentication != null && authentication.isAuthenticated()) { + accessor.setUser(authentication); + } + } + + return message; + } +} diff --git a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java index be7c913..5c8c2ad 100644 --- a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java +++ b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java @@ -3,13 +3,13 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory; -import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; import com.oronaminc.join.websocket.handshake.CustomHandshakeHandler; import com.oronaminc.join.websocket.session.CustomWebSocketHandlerDecorator; @@ -27,6 +27,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { private final StompErrorHandler stompErrorHandler; private final WebsocketSessionManager sessionManager; private final ApplicationEventPublisher publisher; + private final StompAuthChannelInterceptor stompAuthChannelInterceptor; @Bean public WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory( @@ -48,15 +49,15 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") // websocket 연결 전 쿠키 체크 - .addInterceptors(new HttpSessionHandshakeInterceptor()) + // .addInterceptors(new HttpSessionHandshakeInterceptor()) // websocket 연결 후 principal 생성 - .setHandshakeHandler(handshakeHandler) + // .setHandshakeHandler(handshakeHandler) .withSockJS(); registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") - .addInterceptors(new HttpSessionHandshakeInterceptor()) - .setHandshakeHandler(handshakeHandler) + // .addInterceptors(new HttpSessionHandshakeInterceptor()) + // .setHandshakeHandler(handshakeHandler) ; registry.setErrorHandler(stompErrorHandler); @@ -66,4 +67,9 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { public void configureWebSocketTransport(WebSocketTransportRegistration registry) { registry.setDecoratorFactories(webSocketHandlerDecoratorFactory(sessionManager, publisher)); } + + @Override + public void configureClientInboundChannel(ChannelRegistration registration) { + registration.interceptors(stompAuthChannelInterceptor); + } } diff --git a/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java b/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java index 83d9bf3..806c75d 100644 --- a/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java +++ b/src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java @@ -6,9 +6,7 @@ import java.util.Set; import org.springframework.context.event.EventListener; -import org.springframework.messaging.simp.stomp.StompHeaderAccessor; import org.springframework.stereotype.Component; -import org.springframework.web.socket.messaging.SessionSubscribeEvent; import com.oronaminc.join.global.exception.ErrorException; import com.oronaminc.join.room.event.RoomExitEvent; @@ -23,27 +21,27 @@ public class CurrentParticipantEventHandler { private static final String ROOM_PREFIX = "/topic/rooms/"; private static final String JOIN_SUFFIX = "/join"; - @EventListener - public void handleSubscribe(SessionSubscribeEvent event) { - StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage()); - String destination = accessor.getDestination(); - Principal principal = accessor.getUser(); - - if (destination == null) { - throw new ErrorException(STOMP_INVALID_DESTINATION); - } - - if (!destination.startsWith(ROOM_PREFIX)) { - return; - } - - Long memberId = parseMemberId(principal); - Long roomId = parseRoomId(destination); - - if (!isRoomJoinPath(destination)) { - validateParticipantRoomJoin(roomId, memberId); - } - } + // @EventListener + // public void handleSubscribe(SessionSubscribeEvent event) { + // StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage()); + // String destination = accessor.getDestination(); + // Principal principal = accessor.getUser(); + // + // if (destination == null) { + // throw new ErrorException(STOMP_INVALID_DESTINATION); + // } + // + // if (!destination.startsWith(ROOM_PREFIX)) { + // return; + // } + // + // Long memberId = parseMemberId(principal); + // Long roomId = parseRoomId(destination); + // + // if (!isRoomJoinPath(destination)) { + // validateParticipantRoomJoin(roomId, memberId); + // } + // } @EventListener public void handleUnsubscribe(RoomExitEvent event) { From 189c0cafa503a992fd7017eceb48fca91688d561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 13:25:50 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=EC=9B=B9=EC=86=8C=EC=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/oronaminc/join/member/security/SecurityConfig.java | 2 +- .../join/websocket/api/QuestionWebsocketController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java b/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java index 8332001..42067b2 100644 --- a/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java +++ b/src/main/java/com/oronaminc/join/member/security/SecurityConfig.java @@ -61,7 +61,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowCredentials(true); - configuration.setAllowedOriginPatterns(List.of("*")); + configuration.setAllowedOriginPatterns(List.of("http://localhost:5173")); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(List.of("*")); diff --git a/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java b/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java index 773828b..17f840b 100644 --- a/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java +++ b/src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java @@ -43,7 +43,7 @@ public QuestionCreateResponse createQuestion( Principal principal ) { log.debug("수신한 메시지 = {}", request.content()); - + log.debug("principal = {}", principal); MemberDetails memberDetails = (MemberDetails)((Authentication)principal).getPrincipal(); Long memberId = Long.valueOf(memberDetails.getId()); From b209c4c7e37fadb9d8d280b33a4948d9be763baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 13:41:50 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=EC=9D=B8=ED=84=B0=EC=85=89=ED=84=B0,=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=9E=AC=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/oronaminc/join/websocket/config/WebSocketConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java index 5c8c2ad..90f8bd3 100644 --- a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java +++ b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java @@ -10,6 +10,7 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory; +import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; import com.oronaminc.join.websocket.handshake.CustomHandshakeHandler; import com.oronaminc.join.websocket.session.CustomWebSocketHandlerDecorator; @@ -49,9 +50,9 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") // websocket 연결 전 쿠키 체크 - // .addInterceptors(new HttpSessionHandshakeInterceptor()) + .addInterceptors(new HttpSessionHandshakeInterceptor()) // websocket 연결 후 principal 생성 - // .setHandshakeHandler(handshakeHandler) + .setHandshakeHandler(handshakeHandler) .withSockJS(); registry.addEndpoint("/ws") From 8d3151cdeab4525fa01935e9860ae0fca17826ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B1=B4=EC=9A=B0?= Date: Wed, 30 Jul 2025 13:45:06 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=9F=AC=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/oronaminc/join/websocket/config/WebSocketConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java index 5c8c2ad..90f8bd3 100644 --- a/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java +++ b/src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java @@ -10,6 +10,7 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory; +import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; import com.oronaminc.join.websocket.handshake.CustomHandshakeHandler; import com.oronaminc.join.websocket.session.CustomWebSocketHandlerDecorator; @@ -49,9 +50,9 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws") .setAllowedOriginPatterns("*") // websocket 연결 전 쿠키 체크 - // .addInterceptors(new HttpSessionHandshakeInterceptor()) + .addInterceptors(new HttpSessionHandshakeInterceptor()) // websocket 연결 후 principal 생성 - // .setHandshakeHandler(handshakeHandler) + .setHandshakeHandler(handshakeHandler) .withSockJS(); registry.addEndpoint("/ws")