From 9f7133970b31b90f120001d236ead7d589fc54e7 Mon Sep 17 00:00:00 2001 From: CHAEGODA Date: Tue, 2 Apr 2024 17:36:13 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20parameter=EA=B0=80=20@Auth=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=9D=84=20?= =?UTF-8?q?=EA=B0=96=EA=B3=A0=20=EC=9E=88=EA=B3=A0,=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=20=ED=83=80=EC=9E=85=EC=9D=B4=20Long.class?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20true=EB=A5=BC=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8A=94=20=EC=A1=B0=EA=B1=B4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/likelion/todos/auth/AuthArgumentResolver.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java b/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java index 9be1b25..07b2531 100644 --- a/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java +++ b/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java @@ -20,7 +20,9 @@ public class AuthArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean supportsParameter(MethodParameter parameter) { // TODO [6단계] parameter가 @Auth 어노테이션을 갖고 있고, 파라미터 타입이 Long.class인 경우 true를 반환하는 조건을 구현하세요. - return false; + boolean b = parameter.hasParameterAnnotation(Auth.class); + boolean equals = parameter.getParameterType().equals(Long.class); + return b && equals; } @Override From d9b100469187d1ea8161045e60fb60c5084c1c5f Mon Sep 17 00:00:00 2001 From: CHAEGODA Date: Wed, 3 Apr 2024 00:41:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20request=20=ED=97=A4=EB=8D=94?= =?UTF-8?q?=EC=97=90=EC=84=9C=20"Authorization"=20=ED=97=A4=EB=8D=94=20?= =?UTF-8?q?=EA=B0=92=EC=9D=84=20=EC=B6=94=EC=B6=9C=ED=95=98=EC=97=AC=20"Be?= =?UTF-8?q?arer=20"=EB=A1=9C=20=EC=8B=9C=EC=9E=91=ED=95=98=EB=8A=94=20acce?= =?UTF-8?q?ssToken=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98=EC=84=B8?= =?UTF-8?q?=EC=9A=94.=20=EC=9C=A0=ED=9A=A8=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20"=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=ED=9B=84=20=EC=A0=91=EA=B7=BC=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EC=8A=B5=EB=8B=88=EB=8B=A4."=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=EC=99=80=20=ED=95=A8=EA=BB=98=20UnAuthorizedException?= =?UTF-8?q?=EC=9D=84=20=EB=B0=9C=EC=83=9D=EC=8B=9C=ED=82=A4=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion/todos/auth/AuthArgumentResolver.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java b/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java index 07b2531..a187dd1 100644 --- a/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java +++ b/src/main/java/backend/likelion/todos/auth/AuthArgumentResolver.java @@ -33,12 +33,17 @@ public Object resolveArgument( WebDataBinderFactory binderFactory ) { // TODO [6단계] webRequest로부터 accessToken을 추출하고, jwtService를 사용하여 memberId를 추출하여 반환하는 로직을 구현하세요. - return null; + String accessToken = extractAccessToken(webRequest); + return jwtService.extractMemberId(accessToken); } private static String extractAccessToken(NativeWebRequest request) { // TODO [6단계] request 헤더에서 "Authorization" 헤더 값을 추출하여 "Bearer "로 시작하는 accessToken을 반환하세요. 유효하지 않을 경우 "로그인 후 접근할 수 있습니다." 메시지와 함께 UnAuthorizedException을 발생시키는 로직을 구현하세요. - return null; - } + String bearerToken = request.getHeader("Authorization"); + if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer")) { + return bearerToken.substring(7); + } + throw new UnAuthorizedException("로그인 후 접근할 수 있습니다."); + } }