강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

정영돈님의 프로필 이미지
정영돈

작성한 질문수

Spring Cloud로 개발하는 마이크로서비스 애플리케이션(MSA)

jjwt 0.12 이상으로 하시는 분들에게..

해결된 질문

작성

·

619

2

jjwt가 버전업 되면서 강사님이 업데이트 해주신 코드들도 jwt valid할 때 안되는 경우가 발생하더라고요... 그래서 찾아본결과

다음과 같이 작성하시면 원활하게 동작을 합니다. 참고하세요.

 

    private boolean isJwtValid(String jwt) {
        byte[] secretKeyBytes = Base64.getEncoder().encode(env.getProperty("token.secret").getBytes());
        SecretKey signingKey = new SecretKeySpec(secretKeyBytes, SignatureAlgorithm.HS512.getJcaName());

        boolean returnValue = true;
        String subject = null;

        try {
            JwtParser jwtParser = Jwts.parser().
                                    verifyWith(signingKey).build();

            Jws<Claims> claimsJws = jwtParser.parseSignedClaims(jwt);
            Claims payload = claimsJws.getPayload();
            subject = payload.getSubject();

        }catch (Exception ex){
            returnValue = false;
        }

        if(subject == null || subject.isEmpty()){
            returnValue = false;
        }

        return returnValue;
    }

답변 1

0

Dowon Lee님의 프로필 이미지
Dowon Lee
지식공유자

안녕하세요 이도원입니다.

정보 공유 감사합니다. 업데이트 된 코드 다시 한번 확인해 보겠습니다.

좋은 하루 되세요.

정영돈님의 프로필 이미지
정영돈

작성한 질문수

질문하기