Skip to content

Commit 5623727

Browse files
rjswjddnchw0912chcch529gffd94
authored
코드병합 (#115)
* feat: workflow에 EC2 자동 배포 추가 (#78) * feat: workflow에 EC2 자동 배포 추가 * chore: appleboy/ssh-action 최신버전으로 변경 * feat: 발표방 캐싱 및 인덱싱 적용 feat 새로운 기능 추가 (#80) * docs: 발표방 생성 요청 dto 스웨거 수정 * feat: Room secretCode Unique 설정 * feat: Room 캐시 적용 * test: Room 캐시 테스트 * test: 비밀코드 중복 문제 해결 * fix: 로그인 500에러 수정 * fix: 로그인 500에러 수정 * feat: 카카오 로그인 API (#86) * fix: cors disable 추가 * feat: 카카오 로그인 API * feat: 시큐리티에 카카오 로그인 url 추가 * docs: swagger 수정 * test: test yml 수정 * refactor: Presigned URL 업로드용, 조회용 로직 분리 (#84) * refactor: 기존 presigned-url 발급 로직을 업로드용, 조회용으로 분리 * docs: 발표자료 Swagger tag 추가 * refactor: profiles 환경 변수 주입으로 변경 (#90) * feat: 카카오 로그인 재시도 로직, 방 참가자 관리 동시성 수정 (#91) * feat: restTemplate 재시도 로직 추가 * feat: 방 참가자 관리 동시성 수정 및 비밀코드 방 참가 수정 * refactor,fix: 2회차 멘토링 기반 리팩토링 (#94) * fix: MemberController 수정 (#96) * fix: existsMemberByEmail에 RequestBody 추가 * fix: existsMemberByEmail 수정 * feat: 로그인 API 반환 수정 * 답변 조회 기능 수정 (#98) * feat: cors 설정 (#102) * Refactor/101 room detail (#104) * feat: cors 설정 * 웹소켓 * 웹소켓 * Refactor/101 room detail (#106) * feat: cors 설정 * 웹소켓 * 웹소켓 * 웹소켓 * Refactor/101 room detail (#108) * feat: cors 설정 * 웹소켓 * 웹소켓 * 웹소켓 * 웹소켓 * Refactor/101 room detail (#110) * feat: cors 설정 * 웹소켓 * 웹소켓 * 웹소켓 * 웹소켓 * Update WebSocketConfig.java * Refactor/101 room detail (#114) * feat: cors 설정 * 웹소켓 * 웹소켓 * 웹소켓 * 웹소켓 * 웹소켓 --------- Co-authored-by: Huiwoong Choi <[email protected]> Co-authored-by: chcch529 <[email protected]> Co-authored-by: SeungTae <[email protected]>
1 parent d7263ef commit 5623727

File tree

4 files changed

+62
-25
lines changed

4 files changed

+62
-25
lines changed

src/main/java/com/oronaminc/join/websocket/api/QuestionWebsocketController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import org.springframework.messaging.handler.annotation.MessageMapping;
77
import org.springframework.messaging.handler.annotation.Payload;
88
import org.springframework.messaging.handler.annotation.SendTo;
9+
import org.springframework.security.core.Authentication;
910
import org.springframework.stereotype.Controller;
1011

1112
import com.oronaminc.join.global.exception.ErrorCode;
1213
import com.oronaminc.join.global.exception.ErrorException;
1314
import com.oronaminc.join.global.ratelimit.RateLimitService;
1415
import com.oronaminc.join.global.ratelimit.RateLimitType;
16+
import com.oronaminc.join.member.security.MemberDetails;
1517
import com.oronaminc.join.question.domain.Question;
1618
import com.oronaminc.join.question.dto.QuestionCreateResponse;
1719
import com.oronaminc.join.question.dto.QuestionDeleteResponse;
@@ -42,7 +44,8 @@ public QuestionCreateResponse createQuestion(
4244
) {
4345
log.debug("수신한 메시지 = {}", request.content());
4446

45-
Long memberId = Long.valueOf(principal.getName());
47+
MemberDetails memberDetails = (MemberDetails)((Authentication)principal).getPrincipal();
48+
Long memberId = Long.valueOf(memberDetails.getId());
4649

4750
log.debug("회원 아이디 = {}", memberId);
4851

@@ -66,6 +69,7 @@ public QuestionUpdateResponse updateQuestion(
6669
@Payload @Valid QuestionRequest request,
6770
Principal principal
6871
) {
72+
6973
Long memberId = Long.valueOf(principal.getName());
7074

7175
Question updated = questionService.update(memberId, roomId, questionId, request);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.oronaminc.join.websocket.config;
2+
3+
import org.springframework.messaging.Message;
4+
import org.springframework.messaging.MessageChannel;
5+
import org.springframework.messaging.simp.stomp.StompCommand;
6+
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
7+
import org.springframework.messaging.support.ChannelInterceptor;
8+
import org.springframework.messaging.support.MessageHeaderAccessor;
9+
import org.springframework.security.core.Authentication;
10+
import org.springframework.security.core.context.SecurityContextHolder;
11+
import org.springframework.stereotype.Component;
12+
13+
@Component
14+
public class StompAuthChannelInterceptor implements ChannelInterceptor {
15+
@Override
16+
public Message<?> preSend(Message<?> message, MessageChannel channel) {
17+
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
18+
19+
if (StompCommand.CONNECT.equals(accessor.getCommand())) {
20+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
21+
22+
if (authentication != null && authentication.isAuthenticated()) {
23+
accessor.setUser(authentication);
24+
}
25+
}
26+
27+
return message;
28+
}
29+
}

src/main/java/com/oronaminc/join/websocket/config/WebSocketConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.springframework.context.ApplicationEventPublisher;
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.messaging.simp.config.ChannelRegistration;
67
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
78
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
89
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@@ -27,6 +28,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
2728
private final StompErrorHandler stompErrorHandler;
2829
private final WebsocketSessionManager sessionManager;
2930
private final ApplicationEventPublisher publisher;
31+
private final StompAuthChannelInterceptor stompAuthChannelInterceptor;
3032

3133
@Bean
3234
public WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory(
@@ -66,4 +68,9 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
6668
public void configureWebSocketTransport(WebSocketTransportRegistration registry) {
6769
registry.setDecoratorFactories(webSocketHandlerDecoratorFactory(sessionManager, publisher));
6870
}
71+
72+
@Override
73+
public void configureClientInboundChannel(ChannelRegistration registration) {
74+
registration.interceptors(stompAuthChannelInterceptor);
75+
}
6976
}

src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantEventHandler.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
import static com.oronaminc.join.global.exception.ErrorCode.*;
44

5-
import com.oronaminc.join.global.exception.ErrorCode;
65
import java.security.Principal;
76
import java.util.Set;
87

98
import org.springframework.context.event.EventListener;
10-
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
119
import org.springframework.stereotype.Component;
12-
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
1310

1411
import com.oronaminc.join.global.exception.ErrorException;
1512
import com.oronaminc.join.room.event.RoomExitEvent;
@@ -24,27 +21,27 @@ public class CurrentParticipantEventHandler {
2421
private static final String ROOM_PREFIX = "/topic/rooms/";
2522
private static final String JOIN_SUFFIX = "/join";
2623

27-
@EventListener
28-
public void handleSubscribe(SessionSubscribeEvent event) {
29-
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage());
30-
String destination = accessor.getDestination();
31-
Principal principal = accessor.getUser();
32-
33-
if (destination == null) {
34-
throw new ErrorException(STOMP_INVALID_DESTINATION);
35-
}
36-
37-
if (!destination.startsWith(ROOM_PREFIX)) {
38-
return;
39-
}
40-
41-
Long memberId = parseMemberId(principal);
42-
Long roomId = parseRoomId(destination);
43-
44-
if (!isRoomJoinPath(destination)) {
45-
validateParticipantRoomJoin(roomId, memberId);
46-
}
47-
}
24+
// @EventListener
25+
// public void handleSubscribe(SessionSubscribeEvent event) {
26+
// StompHeaderAccessor accessor = StompHeaderAccessor.wrap(event.getMessage());
27+
// String destination = accessor.getDestination();
28+
// Principal principal = accessor.getUser();
29+
//
30+
// if (destination == null) {
31+
// throw new ErrorException(STOMP_INVALID_DESTINATION);
32+
// }
33+
//
34+
// if (!destination.startsWith(ROOM_PREFIX)) {
35+
// return;
36+
// }
37+
//
38+
// Long memberId = parseMemberId(principal);
39+
// Long roomId = parseRoomId(destination);
40+
//
41+
// if (!isRoomJoinPath(destination)) {
42+
// validateParticipantRoomJoin(roomId, memberId);
43+
// }
44+
// }
4845

4946
@EventListener
5047
public void handleUnsubscribe(RoomExitEvent event) {

0 commit comments

Comments
 (0)