Nestsoft-Team / DunJi-BackEnd

DunJi-BackEnd
2 stars 0 forks source link

[kakao Login] 카카오 로그인시 cookie 확인 로직 오류 #14

Open gyuturn opened 1 year ago

gyuturn commented 1 year ago

문제

카카오 로그인시 cookie를 확인하는 과정에서 예외처리가 잘못되었음

이전의 코드

private String getToken(HttpServletRequest httpServletRequest, String tokenType) {
//        String token = httpServletRequest.getHeader(tokenType);
        String token = "";
        Cookie[] cookieList = httpServletRequest.getCookies();

        for(Cookie cookie : cookieList) {
            if(cookie.getName().equals(tokenType)) {
                token = cookie.getValue();
            }
        }

        if(token == null || token.isEmpty()){
            //토큰이 비어있으면 비회원 사용으로 간주함
            log.info("jwtTokenProvider getToken : token is empty");
            throw new AuthException(CommonErrorCode.GUEST_USER);
       }        
    else{
            log.info("jwtTokenProvider getToken {} : {}", tokenType, token);
        }

        return token;
    }

해당코드에서 " for(Cookie cookie : cookieList)" 에서 cookieList가 없는데 cookie를 가져오는곳에서 NullPointerException 발생

임시로 수정 한 코드

    private String getToken(HttpServletRequest httpServletRequest, String tokenType) {
//        String token = httpServletRequest.getHeader(tokenType);
        String token = "";
        Cookie[] cookieList = httpServletRequest.getCookies();
        if(cookieList==null||cookieList.length <= 0){
            //토큰이 비어있으면 비회원 사용으로 간주함
            log.info("jwtTokenProvider getToken : token is empty");
            throw new AuthException(CommonErrorCode.GUEST_USER);
        }

        for(Cookie cookie : cookieList) {
            if(cookie.getName().equals(tokenType)) {
                token = cookie.getValue();
            }
         }

        return token;
    }

정리

gyuturn commented 1 year ago

급한거라 빠르게 수정부탁드립니다!!

jeeheaG commented 1 year ago

급하신 사항이고 추가 코드가 많지 않아서 바로 develop으로 푸시했습니다.

[수정사항]

  1. cookieList 가 null일 때 버그 : 잘 작동하는 것 확인 완료
  2. 전체 요청의 토큰을 확인하는 것이 아닌 지정된 특정 url 만 토큰 확인하도록 수정
  3. uuid 컬럼 생성과 관련된 이슈 에 언급하신 내용도 반영했습니다.

보완할 부분이 많네요.. 감사합니다!