Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Tech-Post_BE.
# Tech-Post_BE..
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 인증 처리
Expand Down Expand Up @@ -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);

}

Expand Down