Skip to content

Commit

Permalink
Merge pull request #210 from OutDecision/issue/197
Browse files Browse the repository at this point in the history
[UPDATE]: 로그인 쿠키 설정
  • Loading branch information
baeksom authored May 26, 2024
2 parents cee9930 + ef7622b commit 3229058
Showing 1 changed file with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static KGUcapstone.OutDecision.global.common.util.CookieUtil.addCookie;
Expand Down Expand Up @@ -61,25 +59,9 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

if (newAccessToken != null) {
addCookie(response, "Authorization", newAccessToken, 60 * 60);
atc = newAccessToken;
log.info("토큰 발급 완료 필터 newAccessToken = {}", newAccessToken);

// 원래 요청을 재시도
HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
@Override
public Cookie[] getCookies() {
Cookie[] cookies = super.getCookies();
if (cookies == null) {
cookies = new Cookie[0];
}
List<Cookie> updatedCookies = new ArrayList<>(Arrays.asList(cookies));
updatedCookies.removeIf(cookie -> "Authorization".equals(cookie.getName()));
updatedCookies.add(new Cookie("Authorization", newAccessToken));
return updatedCookies.toArray(new Cookie[0]);
}
};

filterChain.doFilter(requestWrapper, response);
filterChain.doFilter(request, response);
return;
} else {
log.error("새로운 토큰 발급 실패");
Expand Down

0 comments on commit 3229058

Please sign in to comment.