Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[201800288 채다영] Level6 미션 제출합니다 #32

Open
wants to merge 2 commits into
base: level6-initial
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,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("로그인 후 접근할 수 있습니다.");

}
}