Skip to content

Commit 32b3bfc

Browse files
committed
fix : 웹소켓 연결 헤더 검증에서 첫 메시지 페이로드로 검증으로 수정
1 parent 61d1d26 commit 32b3bfc

File tree

8 files changed

+163
-147
lines changed

8 files changed

+163
-147
lines changed
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.jungppo.bambooforest.chat.dto;
22

3+
import org.jungppo.bambooforest.chat.exception.ChatMessageValidationException;
4+
35
import com.fasterxml.jackson.annotation.JsonCreator;
46
import com.fasterxml.jackson.annotation.JsonProperty;
57

@@ -13,20 +15,47 @@
1315
@AllArgsConstructor(access = AccessLevel.PRIVATE)
1416
public class ChatMessageDto {
1517
@NotNull(message = "Message type cannot be null")
16-
private MessageType type;
18+
private ChatMessageType type;
1719

1820
@NotBlank(message = "Message cannot be blank")
1921
private String message;
2022

21-
public enum MessageType {
22-
ENTER, TALK, LEAVE //입장, 채팅, 퇴장
23+
private String token; // 인증 토큰
24+
25+
private String roomId; // 룸 ID
26+
27+
private Long memberId; // 멤버 ID
28+
29+
public enum ChatMessageType {
30+
AUTH, ENTER, TALK, LEAVE //인증, 입장, 채팅, 퇴장
2331
}
2432

2533
@JsonCreator
2634
public static ChatMessageDto of(
27-
@JsonProperty("type") MessageType type,
28-
@JsonProperty("message") String message
35+
@JsonProperty("type") ChatMessageType type,
36+
@JsonProperty("message") String message,
37+
@JsonProperty("token") String token,
38+
@JsonProperty("roomId") String roomId,
39+
@JsonProperty("memberId") Long memberId
2940
) {
30-
return new ChatMessageDto(type, message);
41+
ChatMessageDto dto = new ChatMessageDto(type, message, token, roomId, memberId);
42+
dto.validate();
43+
return dto;
44+
}
45+
46+
private void validate() {
47+
if (this.type == ChatMessageType.AUTH) {
48+
validateField(this.token);
49+
validateField(this.roomId);
50+
validateField(this.memberId);
51+
}
52+
}
53+
54+
private void validateField(String field) {
55+
if (field == null || field.isBlank()) throw new ChatMessageValidationException();
56+
}
57+
58+
private void validateField(Long field) {
59+
if (field == null) throw new ChatMessageValidationException();
3160
}
3261
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jungppo.bambooforest.chat.exception;
2+
3+
import static org.jungppo.bambooforest.global.exception.domain.ExceptionType.BIND_EXCEPTION;
4+
5+
public class ChatMessageValidationException extends ChatBusinessException {
6+
public ChatMessageValidationException() {
7+
super(BIND_EXCEPTION);
8+
}
9+
}

src/main/java/org/jungppo/bambooforest/chat/handler/CustomHandshakeInterceptor.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/main/java/org/jungppo/bambooforest/chat/handler/JwtHandshakeInterceptor.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)