Skip to content

Commit

Permalink
fix : 헤더 인증처리 #171 from dltjdgh0428/feature/JWT로그인
Browse files Browse the repository at this point in the history
fix : 헤더 인증처리
  • Loading branch information
dltjdgh0428 authored Apr 1, 2024
2 parents 49f6482 + 543fb17 commit a3b3e3f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
response.addCookie(jwtProvider.createCookie(ACCESS.getType(), access));
response.addCookie(jwtProvider.createCookie(REFRESH.getType(), refresh));
response.sendRedirect("https://www.bookeverywhere.site/");
response.setStatus(HttpStatus.OK.value());
}
}
43 changes: 23 additions & 20 deletions src/main/java/com/book_everywhere/jwt/filter/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,31 @@ public class JwtFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//여기서 헤더가 access인
String accessToken = null;
Cookie[] cookies = request.getCookies();
if (cookies == null) {
// 쿠키가 없음을 처리하는 로직
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("쿠키없다는데? 왜없냐 ㄹㅇ");
filterChain.doFilter(request, response);
return;
}
for (Cookie cookie : cookies) {
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
String accessToken = request.getHeader(ACCESS.getType());


// String accessToken = null;
// Cookie[] cookies = request.getCookies();
// if (cookies == null) {
// // 쿠키가 없음을 처리하는 로직
// logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info("@@@@@@@@@@@@@@@@@@@@@@");
logger.info(cookie);
if (cookie.getName().equals(ACCESS.getType())) {
accessToken = cookie.getValue();
}
}
logger.info(accessToken);
// logger.info("쿠키없다는데? 왜없냐 ㄹㅇ");
// filterChain.doFilter(request, response);
// return;
// }
// for (Cookie cookie : cookies) {
// logger.info("@@@@@@@@@@@@@@@@@@@@@@");
// logger.info("@@@@@@@@@@@@@@@@@@@@@@");
// logger.info("@@@@@@@@@@@@@@@@@@@@@@");
// logger.info("@@@@@@@@@@@@@@@@@@@@@@");
// logger.info(cookie);
// if (cookie.getName().equals(ACCESS.getType())) {
// accessToken = cookie.getValue();
// }
// }

if (accessToken == null) {
filterChain.doFilter(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String createJwt(String category, String username, String role, Long expi

public Cookie createCookie(String key, String value) {
Cookie cookie = new Cookie(key, value);
cookie.setMaxAge(60 * 60 * 60 * 60);
cookie.setMaxAge(24 * 60 * 60);
//cookie.setSecure(true);
cookie.setPath("/");
cookie.setHttpOnly(true);
Expand Down

0 comments on commit a3b3e3f

Please sign in to comment.