From e061aa9d5ad288606e4e0b592e55c9eb426aa482 Mon Sep 17 00:00:00 2001 From: khee2 <21keunghee@gmail.com> Date: Wed, 12 Jun 2024 14:11:05 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EB=B3=B4=EB=82=BC=20=EB=95=8C=20resolve=20=ED=9B=84=20validati?= =?UTF-8?q?on=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/controller/MessageController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/SafeNet/Backend/domain/message/controller/MessageController.java b/src/main/java/com/SafeNet/Backend/domain/message/controller/MessageController.java index 4b76a2e..597c26b 100644 --- a/src/main/java/com/SafeNet/Backend/domain/message/controller/MessageController.java +++ b/src/main/java/com/SafeNet/Backend/domain/message/controller/MessageController.java @@ -44,11 +44,17 @@ public void message(@RequestHeader(name = "ACCESS_TOKEN", required = false) Stri MessageDto messageDto) { try { // Access Token 검증 - if (accessToken == null || !jwtTokenProvider.validateToken(accessToken)) { // 메시지 전송 전 유효한 토큰인지 검증 - throw new AccessDeniedException("Invalid or expired token"); + if (accessToken != null && accessToken.startsWith("Bearer ")) { + String token = accessToken.substring(7); + if (jwtTokenProvider.validateToken(token)) { + // 메시지 전송 로직 호출 + messageRoomService.handleMessage(messageDto.getRoomId(), messageDto.getSender(), messageDto); + } else { + throw new AccessDeniedException("Invalid or expired token"); + } + } else { + throw new AccessDeniedException("Missing or invalid ACCESS_TOKEN header"); } - // 메시지 전송 로직 호출 - messageRoomService.handleMessage(messageDto.getRoomId(), messageDto.getSender(), messageDto); } catch (Exception e) { log.error("Failed to send message: {}", e.getMessage()); throw e;