Skip to content

Commit

Permalink
[feat] 발행, 구독시 토큰 검증 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
khee2 committed Jun 12, 2024
1 parent 02ac050 commit 3d65b5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ public AuthChannelInterceptor(JwtTokenProvider jwtTokenProvider) {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
if (StompCommand.CONNECT.equals(accessor.getCommand())) {

if (StompCommand.CONNECT.equals(accessor.getCommand()) ||
StompCommand.SUBSCRIBE.equals(accessor.getCommand()) ||
StompCommand.SEND.equals(accessor.getCommand())) {

String token = accessor.getFirstNativeHeader("ACCESS_TOKEN");
log.debug("Received ACCESS_TOKEN in Interceptor: {}", token);

try {
if (token != null && token.startsWith("Bearer ")) {
token = token.substring(7);
Expand All @@ -48,6 +54,7 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
throw e;
}
}

return message;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws-stomp").setAllowedOriginPatterns("*") // stomp websocket 연결
.withSockJS();
}
}
}

// WebSocket 메시지의 헤더에서 ACCESS_TOKEN을 추출하고 검증
// 유효한 토큰이 있는 경우 사용자 인증 정보를 설정하고, 유효하지 않은 경우 연결을 차단

0 comments on commit 3d65b5e

Please sign in to comment.