Skip to content

Commit

Permalink
[FIX] Access Token이 Bearer null 인 경우 Optional이 작동하지 않음 (#128)
Browse files Browse the repository at this point in the history
* feat: add string null check in AuthResolver

* fix: insert null string check code to hasAccessToken function
  • Loading branch information
2tle authored Nov 25, 2024
1 parent fc389c5 commit 0729132
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
AccessType[] allowedTypes = Objects.requireNonNull(parameter.getParameterAnnotation(AuthUser.class)).accessType();
List<AccessType> accessTypeList = Arrays.asList(allowedTypes);

if(accessTypeList.contains(AccessType.OPTIONAL) && !hasAccessToken(request)) {
if(accessTypeList.contains(AccessType.OPTIONAL) && !hasAccessToken(request))
{
return null;
}

String contextPath = request.getRequestURI();
String refreshToken = extractRefreshToken(request);
String accessToken = extractAccessToken(request);
String refreshToken = extractRefreshToken(request);

//검증
if (jwtUtil.isAccessTokenValid(accessToken)) {
Expand Down Expand Up @@ -129,7 +130,8 @@ private User extractUser(String accessToken) {

private boolean hasAccessToken(HttpServletRequest request) {
final String BEARER = "Bearer ";
final String BEARER_NULL = "Bearer null";
String authHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
return authHeader != null && authHeader.startsWith(BEARER);
return authHeader != null && authHeader.startsWith(BEARER) && !authHeader.equalsIgnoreCase(BEARER_NULL);
}
}

0 comments on commit 0729132

Please sign in to comment.