From 4379d5bd16f03bb93e1a635f811ca34c1f03ac74 Mon Sep 17 00:00:00 2001 From: Jae Date: Thu, 11 Dec 2025 15:04:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Fix]=20=ED=94=84=EB=A1=A0=ED=8A=B8=20api?= =?UTF-8?q?=20=EC=97=B0=EB=8F=99=EC=97=90=20=EB=94=B0=EB=A5=B8=20SecurityC?= =?UTF-8?q?onfig=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/handler/OAuth2LoginSuccessHandler.java | 2 +- .../techpost/domain/chat/controller/StompController.java | 7 +++++-- .../com/ureka/techpost/global/config/SecurityConfig.java | 2 +- .../global/config/websocket/StompChannelInterceptor.java | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ureka/techpost/domain/auth/handler/OAuth2LoginSuccessHandler.java b/src/main/java/com/ureka/techpost/domain/auth/handler/OAuth2LoginSuccessHandler.java index 7e46c61..3217b79 100644 --- a/src/main/java/com/ureka/techpost/domain/auth/handler/OAuth2LoginSuccessHandler.java +++ b/src/main/java/com/ureka/techpost/domain/auth/handler/OAuth2LoginSuccessHandler.java @@ -52,7 +52,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo // 액세스 토큰을 쿼리 파라미터에 담아 프론트엔드 URL로 리다이렉트 // vue.js 에서 지원하는 포트 번호로 변경해야 함 - String targetUrl = UriComponentsBuilder.fromUriString("http://localhost:5173/") + String targetUrl = UriComponentsBuilder.fromUriString("http://localhost:3000/post/list") .queryParam("accessToken", access) .build().toUriString(); diff --git a/src/main/java/com/ureka/techpost/domain/chat/controller/StompController.java b/src/main/java/com/ureka/techpost/domain/chat/controller/StompController.java index 8534674..6df66ed 100644 --- a/src/main/java/com/ureka/techpost/domain/chat/controller/StompController.java +++ b/src/main/java/com/ureka/techpost/domain/chat/controller/StompController.java @@ -17,7 +17,9 @@ 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.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageSendingOperations; +import org.springframework.security.core.Authentication; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; @@ -29,8 +31,9 @@ public class StompController { private final ChatService chatService; @MessageMapping("/{roomId}") - public void sendMessage(@DestinationVariable Long roomId, @AuthenticationPrincipal CustomUserDetails userDetails, @Payload @Valid ChatMessageReq chatMessageReq) { - Long userId = userDetails.getUser().getUserId(); + public void sendMessage(@DestinationVariable Long roomId, SimpMessageHeaderAccessor accessor, @Payload @Valid ChatMessageReq chatMessageReq) { + CustomUserDetails customUserDetails = (CustomUserDetails) accessor.getSessionAttributes().get("user"); + Long userId = customUserDetails.getUser().getUserId(); chatService.saveMessage(roomId, userId, chatMessageReq); messageTemplate.convertAndSend("/topic/" + roomId, chatMessageReq); diff --git a/src/main/java/com/ureka/techpost/global/config/SecurityConfig.java b/src/main/java/com/ureka/techpost/global/config/SecurityConfig.java index acdf7be..5e895d5 100644 --- a/src/main/java/com/ureka/techpost/global/config/SecurityConfig.java +++ b/src/main/java/com/ureka/techpost/global/config/SecurityConfig.java @@ -56,7 +56,7 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration c @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(Collections.singletonList("http://localhost:5173")); + configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000")); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(Collections.singletonList("*")); configuration.setAllowCredentials(true); diff --git a/src/main/java/com/ureka/techpost/global/config/websocket/StompChannelInterceptor.java b/src/main/java/com/ureka/techpost/global/config/websocket/StompChannelInterceptor.java index d349da1..2b572f3 100644 --- a/src/main/java/com/ureka/techpost/global/config/websocket/StompChannelInterceptor.java +++ b/src/main/java/com/ureka/techpost/global/config/websocket/StompChannelInterceptor.java @@ -23,6 +23,7 @@ import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; // STOMP jwt 인증 처리 @@ -67,6 +68,7 @@ public Message preSend(Message message, MessageChannel channel) { Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); accessor.setUser(authentication); + accessor.getSessionAttributes().put("user", userDetails); } From 7974741011272bc3a38e26110a585be538b1e4f9 Mon Sep 17 00:00:00 2001 From: yechan <100present@naver.com> Date: Thu, 11 Dec 2025 15:07:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20:=20application-prod.yml=EC=97=90?= =?UTF-8?q?=EC=84=9C=20jpa.ddl-auto:none=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8cc932..d3de1e7 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# Tech-Post_BE. \ No newline at end of file +# Tech-Post_BE.. \ No newline at end of file