Skip to content

Commit

Permalink
!hotfix: 쿠키 파싱 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kimday0326 committed May 29, 2024
1 parent 31e395a commit 408eb5e
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import com.khu.gitbox.auth.provider.JwtTokenProvider;

import io.jsonwebtoken.ExpiredJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -47,12 +47,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}

private String parseJwt(HttpServletRequest request) {
String headerAuth = request.getHeader("Cookie");

if (StringUtils.hasText(headerAuth) && headerAuth.startsWith("accessToken=")) {
return headerAuth.substring(12);
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if ("accessToken".equals(cookie.getName())) {
log.info("cookies : {}", cookie.getValue());
return cookie.getValue();
}
}
}

throw new AuthenticationCredentialsNotFoundException("토큰이 존재하지 않습니다.");
}
}

0 comments on commit 408eb5e

Please sign in to comment.