From 421813f82f2e7561cea32d0022ce93c51f9b92de Mon Sep 17 00:00:00 2001 From: devmizz Date: Tue, 4 Jun 2024 00:57:12 +0900 Subject: [PATCH] fix: Rebase --- .../java/org/example/error/GlobalExceptionHandler.java | 6 +++--- .../java/org/example/filter/ExceptionHandlerFilter.java | 5 ++--- .../src/main/java/org/example/property/TokenProperty.java | 2 +- .../java/org/example/security/token/JWTGenerator.java | 4 ++-- .../main/java/org/example/security/token/JWTHandler.java | 4 ++-- .../java/org/example/security/token/JWTGeneratorTest.java | 8 ++++---- .../java/org/example/security/token/JWTHandlerTest.java | 5 +++-- config/checkstyle.xml | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java b/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java index 1ce2f8d3..de134752 100644 --- a/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java +++ b/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java @@ -1,11 +1,11 @@ package org.example.error; -import org.example.exception.BusinessException; -import org.example.exception.ErrorResponse; -import org.example.exception.GlobalError; import jakarta.validation.ConstraintViolationException; import java.util.UUID; import lombok.extern.slf4j.Slf4j; +import org.example.exception.BusinessException; +import org.example.exception.ErrorResponse; +import org.example.exception.GlobalError; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingServletRequestParameterException; diff --git a/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java b/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java index 3c36499d..726cb8bd 100644 --- a/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java +++ b/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java @@ -1,8 +1,6 @@ package org.example.filter; import com.fasterxml.jackson.databind.ObjectMapper; -import org.example.exception.BusinessException; -import org.example.exception.ErrorResponse; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -10,8 +8,9 @@ import java.io.IOException; import java.util.UUID; import lombok.extern.slf4j.Slf4j; +import org.example.exception.BusinessException; +import org.example.exception.ErrorResponse; import org.example.exception.GlobalError; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; diff --git a/app/api/src/main/java/org/example/property/TokenProperty.java b/app/api/src/main/java/org/example/property/TokenProperty.java index 349c6507..83584275 100644 --- a/app/api/src/main/java/org/example/property/TokenProperty.java +++ b/app/api/src/main/java/org/example/property/TokenProperty.java @@ -12,7 +12,7 @@ public record TokenProperty( Long refreshTokenExpirationSeconds ) { - public SecretKey getBASE64URLSecretKey() { + public SecretKey getBase64URLSecretKey() { return Keys.hmacShaKeyFor( Decoders.BASE64URL.decode(secretKey) ); diff --git a/app/api/src/main/java/org/example/security/token/JWTGenerator.java b/app/api/src/main/java/org/example/security/token/JWTGenerator.java index 741dcd09..0568f166 100644 --- a/app/api/src/main/java/org/example/security/token/JWTGenerator.java +++ b/app/api/src/main/java/org/example/security/token/JWTGenerator.java @@ -28,7 +28,7 @@ private String createAccessToken(UserParam userParam, Date from) { .expiration( new Date(from.getTime() + tokenProperty.accessTokenExpirationSeconds()) ) - .signWith(tokenProperty.getBASE64URLSecretKey()) + .signWith(tokenProperty.getBase64URLSecretKey()) .compact(); } @@ -39,7 +39,7 @@ private String createRefreshToken(UserParam userParam, Date from) { .expiration( new Date(from.getTime() + tokenProperty.refreshTokenExpirationSeconds()) ) - .signWith(tokenProperty.getBASE64URLSecretKey()) + .signWith(tokenProperty.getBase64URLSecretKey()) .compact(); } } diff --git a/app/api/src/main/java/org/example/security/token/JWTHandler.java b/app/api/src/main/java/org/example/security/token/JWTHandler.java index 09a6445b..9841d2a9 100644 --- a/app/api/src/main/java/org/example/security/token/JWTHandler.java +++ b/app/api/src/main/java/org/example/security/token/JWTHandler.java @@ -1,12 +1,12 @@ package org.example.security.token; -import org.example.exception.BusinessException; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.Jwt; import io.jsonwebtoken.Jwts; import jakarta.servlet.http.HttpServletRequest; import java.util.UUID; import lombok.RequiredArgsConstructor; +import org.example.exception.BusinessException; import org.example.property.TokenProperty; import org.example.security.dto.UserParam; import org.example.security.vo.TokenError; @@ -66,7 +66,7 @@ private Object parsePayload(String token) { private Jwt parseToken(String token) { return Jwts.parser() - .verifyWith(tokenProperty.getBASE64URLSecretKey()) + .verifyWith(tokenProperty.getBase64URLSecretKey()) .build() .parse(token); } diff --git a/app/api/src/test/java/org/example/security/token/JWTGeneratorTest.java b/app/api/src/test/java/org/example/security/token/JWTGeneratorTest.java index 7a9ee941..f5e1d5b1 100644 --- a/app/api/src/test/java/org/example/security/token/JWTGeneratorTest.java +++ b/app/api/src/test/java/org/example/security/token/JWTGeneratorTest.java @@ -39,7 +39,7 @@ void accessTokenInvalidBeforeHourAgo() { Assertions.assertThrowsExactly( ExpiredJwtException.class, () -> Jwts.parser() - .verifyWith(tokenProperty.getBASE64URLSecretKey()) + .verifyWith(tokenProperty.getBase64URLSecretKey()) .build() .parse(token.accessToken()) ); @@ -54,7 +54,7 @@ void accessTokenValidAfterHourAgo() { Assertions.assertDoesNotThrow( () -> Jwts.parser() - .verifyWith(tokenProperty.getBASE64URLSecretKey()) + .verifyWith(tokenProperty.getBase64URLSecretKey()) .build() .parse(token.accessToken()) ); @@ -69,7 +69,7 @@ void refreshTokenInvalidBeforeHourAgo() { Assertions.assertThrowsExactly( ExpiredJwtException.class, () -> Jwts.parser() - .verifyWith(tokenProperty.getBASE64URLSecretKey()) + .verifyWith(tokenProperty.getBase64URLSecretKey()) .build() .parse(token.refreshToken()) ); @@ -84,7 +84,7 @@ void refreshTokenValidAfterHourAgo() { Assertions.assertDoesNotThrow( () -> Jwts.parser() - .verifyWith(tokenProperty.getBASE64URLSecretKey()) + .verifyWith(tokenProperty.getBase64URLSecretKey()) .build() .parse(token.refreshToken()) ); diff --git a/app/api/src/test/java/org/example/security/token/JWTHandlerTest.java b/app/api/src/test/java/org/example/security/token/JWTHandlerTest.java index 8b03bad8..7227d068 100644 --- a/app/api/src/test/java/org/example/security/token/JWTHandlerTest.java +++ b/app/api/src/test/java/org/example/security/token/JWTHandlerTest.java @@ -3,9 +3,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.example.exception.BusinessException; import java.util.Date; import java.util.UUID; +import org.example.exception.BusinessException; import org.example.property.TokenProperty; import org.example.security.dto.TokenParam; import org.example.security.dto.UserParam; @@ -69,7 +69,8 @@ void extractUserIdFromExpiredToken() { new Date(new Date().getTime() - tokenProperty.accessTokenExpirationSeconds()) ).accessToken(); - UUID extractedUserIdFromExpiredToken = jwtHandler.getUserIdFromExpiredToken(expiredAccessToken); + UUID extractedUserIdFromExpiredToken = jwtHandler.getUserIdFromExpiredToken( + expiredAccessToken); assertThat(extractedUserIdFromExpiredToken).isEqualTo(userParam.userId()); } } \ No newline at end of file diff --git a/config/checkstyle.xml b/config/checkstyle.xml index 1a5274f7..1f6f7130 100644 --- a/config/checkstyle.xml +++ b/config/checkstyle.xml @@ -263,7 +263,7 @@ - + - +