Skip to content

Commit

Permalink
Merge pull request #171 from 1e5i-Shark/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
GiHoo authored May 6, 2024
2 parents 79c8990 + 7a8c98d commit d738c06
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
Expand All @@ -17,6 +18,7 @@ public class SignallingController {
@SendTo("/topic/peer/offer/{camKey}/{roomShortUuid}")
public String peerHandleOffer(
@Payload String offer,
@Header("Authorization") String authorization,
@DestinationVariable(value = "roomShortUuid") String roomShortUuid,
@DestinationVariable(value = "camKey") String camKey
) {
Expand All @@ -30,6 +32,7 @@ public String peerHandleOffer(
@SendTo("/topic/peer/iceCandidate/{camKey}/{roomShortUuid}")
public String peerHandleIceCandidate(
@Payload String candidate,
@Header("Authorization") String authorization,
@DestinationVariable(value = "roomShortUuid") String roomShortUuid,
@DestinationVariable(value = "camKey") String camKey
) {
Expand All @@ -42,6 +45,7 @@ public String peerHandleIceCandidate(
@SendTo("/topic/peer/answer/{camKey}/{roomShortUuid}")
public String peerHandleAnswer(
@Payload String answer,
@Header("Authorization") String authorization,
@DestinationVariable(value = "roomShortUuid") String roomShortUuid,
@DestinationVariable(value = "camKey") String camKey
) {
Expand All @@ -52,15 +56,21 @@ public String peerHandleAnswer(
//camKey 를 받기위해 신호를 보내는 webSocket
@MessageMapping("/call/key")
@SendTo("/topic/call/key")
public String callKey(@Payload String message) {
public String callKey(
@Payload String message,
@Header("Authorization") String authorization
) {
log.info("[Key] : {}", message);
return message;
}

//자신의 camKey 를 모든 연결된 세션에 보내는 webSocket
@MessageMapping("/send/key")
@SendTo("/topic/send/key")
public String sendKey(@Payload String message) {
public String sendKey(
@Payload String message,
@Header("Authorization") String authorization
) {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import ei.algobaroapi.global.jwt.JwtProvider;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class WebSocketChannelInterceptor implements ChannelInterceptor {
Expand All @@ -24,12 +26,17 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
if (accessor.getCommand() == StompCommand.CONNECT ||
accessor.getCommand() == StompCommand.SUBSCRIBE ||
accessor.getCommand() == StompCommand.SEND) {
String token = extractToken(accessor);
if (!jwtProvider.validateToken(token)) {
throw new IllegalArgumentException("Invalid token");
try {
String token = extractToken(accessor);
if (token == null || !jwtProvider.validateToken(token)) {
log.warn("토큰 null or 유효하지 않은 토큰");
throw new IllegalArgumentException("Invalid token");
}
} catch (Exception e) {
log.error("Authentication error: " + e.getMessage(), e);
return null;
}
}

return message;
}

Expand Down

0 comments on commit d738c06

Please sign in to comment.