From 2ef328ef5d7e6ce957a7f0161f734d35e3bbd430 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:12:07 +0900 Subject: [PATCH 01/27] =?UTF-8?q?PET-300=20chore=20:=20JJWT=200.11.5=20->?= =?UTF-8?q?=200.12.5=EB=A1=9C=20=EB=B2=84=EC=A0=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Domain-Module/Auth-Module/Auth-Domain/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Domain/build.gradle b/Domain-Module/Auth-Module/Auth-Domain/build.gradle index e1c0b874..344fd2ba 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/build.gradle +++ b/Domain-Module/Auth-Module/Auth-Domain/build.gradle @@ -1,8 +1,8 @@ dependencies { // jwt - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + implementation 'io.jsonwebtoken:jjwt-api:0.12.5' + implementation 'io.jsonwebtoken:jjwt-impl:0.12.5' + implementation 'io.jsonwebtoken:jjwt-jackson:0.12.5' // configuration properties implementation 'org.springframework.boot:spring-boot-configuration-processor' From 5bb4642e7758a55d08e78c4b80c93d72d977a037 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:20:01 +0900 Subject: [PATCH 02/27] =?UTF-8?q?PET-300=20feat=20:=20Jwt=EC=9D=98=20Claim?= =?UTF-8?q?s=20=EC=A0=95=EB=B3=B4=20=EA=B4=80=EB=A6=AC=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pawith/authdomain/jwt/PrivateClaims.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/PrivateClaims.java diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/PrivateClaims.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/PrivateClaims.java new file mode 100644 index 00000000..2632d88e --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/PrivateClaims.java @@ -0,0 +1,53 @@ +package com.pawith.authdomain.jwt; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import java.util.Map; + +@Getter +public class PrivateClaims { + private final UserClaims userClaims; + private final TokenType tokenType; + + public PrivateClaims(UserClaims userClaims, TokenType tokenType) { + this.userClaims = userClaims; + this.tokenType = tokenType; + } + + public Map createClaimsMap() { + return Map.of( + JWTConsts.USER_CLAIMS, userClaims, + JWTConsts.TOKEN_TYPE, tokenType.name() + ); + } + + public static Map> getClaimsTypeDetailMap(){ + return Map.of( + JWTConsts.USER_CLAIMS, PrivateClaims.UserClaims.class, + JWTConsts.TOKEN_TYPE, TokenType.class + ); + } + + @Getter + @ToString + @NoArgsConstructor(access = AccessLevel.PROTECTED) + public static class UserClaims{ + @JsonProperty("user_id") + private Long userId; + private UserClaims(Long userId) { + this.userId = userId; + } + + public static UserClaims of(Long userId){ + return new UserClaims(userId); + } + + public PrivateClaims createPrivateClaims(TokenType tokenType) { + return new PrivateClaims(this, tokenType); + } + } +} From 9b34e0c45874baa828e14865c8531bc8b8f53089 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:20:51 +0900 Subject: [PATCH 03/27] =?UTF-8?q?PET-300=20refactor=20:=20Email=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20jwt=EC=97=90=EC=84=9C=20PrivateClaims=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F,=20=EB=9D=BC=EC=9D=B4=EB=B8=8C?= =?UTF-8?q?=EB=9F=AC=EB=A6=AC=20=EB=B2=84=EC=A0=84=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pawith/authdomain/jwt/JWTProvider.java | 100 ++++++------------ 1 file changed, 31 insertions(+), 69 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTProvider.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTProvider.java index 0c01c7c0..338f7acc 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTProvider.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTProvider.java @@ -6,15 +6,14 @@ import com.pawith.commonmodule.cache.operators.ValueOperator; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; +import io.jsonwebtoken.jackson.io.JacksonDeserializer; import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.SignatureException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import java.security.Key; +import javax.crypto.SecretKey; import java.util.Date; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -26,87 +25,53 @@ public class JWTProvider { private final JWTProperties jwtProperties; private final ValueOperator tokenCacheOperator; - /** - * access token 생성 - * - * @param email 토큰에 담길 email - * @return 생성된 access token - */ - public String generateAccessToken(final String email) { - final Claims claims = createPrivateClaims(email, TokenType.ACCESS_TOKEN); - return generateToken(claims, jwtProperties.getAccessTokenExpirationTime()); + public String generateAccessToken(final PrivateClaims.UserClaims userClaims) { + return generateToken(userClaims.createPrivateClaims(TokenType.ACCESS_TOKEN), jwtProperties.getAccessTokenExpirationTime()); } - /** - * refershToken 생성 - * refreshToken은 DB에 저장함 - */ - public String generateRefreshToken(final String email) { - final Claims claims = createPrivateClaims(email, TokenType.REFRESH_TOKEN); - return generateToken(claims, jwtProperties.getRefreshTokenExpirationTime()); + public String generateRefreshToken(final PrivateClaims.UserClaims userClaims) { + return generateToken(userClaims.createPrivateClaims(TokenType.REFRESH_TOKEN), jwtProperties.getRefreshTokenExpirationTime()); } - public Token generateToken(final String email){ - final String accessToken = generateAccessToken(email); - final String refreshToken = generateRefreshToken(email); + public Token generateToken(final PrivateClaims.UserClaims userClaims) { + final String accessToken = generateAccessToken(userClaims); + final String refreshToken = generateRefreshToken(userClaims); return new Token(accessToken, refreshToken); } - public Token reIssueToken(final String refreshToken){ + public Token reIssueToken(final String refreshToken) { validateToken(refreshToken, TokenType.REFRESH_TOKEN); - final String email = extractEmailFromToken(refreshToken, TokenType.REFRESH_TOKEN); - final String newAccessToken = generateAccessToken(email); - final String newRefreshToken = generateRefreshToken(email); + final PrivateClaims.UserClaims userClaims = extractUserClaimsFromToken(refreshToken, TokenType.REFRESH_TOKEN); + final String newAccessToken = generateAccessToken(userClaims); + final String newRefreshToken = generateRefreshToken(userClaims); tokenCacheOperator.setWithExpire(refreshToken, new Token(newAccessToken, newRefreshToken), 1, TimeUnit.MINUTES); return new Token(newAccessToken, newRefreshToken); } - public String extractEmailFromToken(String token, TokenType tokenType) { + public PrivateClaims.UserClaims extractUserClaimsFromToken(String token, TokenType tokenType) { return initializeJwtParser(tokenType) - .parseClaimsJws(token) - .getBody() - .get(JWTConsts.EMAIL) - .toString(); + .parseSignedClaims(token) + .getPayload() + .get(JWTConsts.USER_CLAIMS, PrivateClaims.UserClaims.class); } - public boolean existsCachedRefreshToken(String refreshToken){ + public boolean existsCachedRefreshToken(String refreshToken) { return tokenCacheOperator.contains(refreshToken); } - public Token getCachedToken(String refreshToken){ + public Token getCachedToken(String refreshToken) { return tokenCacheOperator.get(refreshToken); } - /** - * 기본 jwt claims 스팩에서 개발자가 더 추가한 claim을 private claim이라고 함 - *
private claims : email, tokenType + issuer - * - * @param email 토큰에 담길 email - * @param tokenType 토큰 타입(ACCESS_TOKEN, REFRESH_TOKEN) - */ - private Claims createPrivateClaims(final String email, final TokenType tokenType) { - final Map claims = new HashMap<>(); - claims.put(JWTConsts.EMAIL, email); - claims.put(JWTConsts.TOKEN_TYPE, tokenType.name()); - return Jwts.claims(claims) - .setIssuer(JWTConsts.TOKEN_ISSUER); - } - - /** - * 토큰 생성 메소드 - * - * @param claims 토큰에 담길 정보(email, tokenType) - * @param expirationTime 토큰 만료 시간(시간 단위 ms) - * @return 생성된 토큰 - */ - private String generateToken(final Claims claims, final Long expirationTime) { + private String generateToken(final PrivateClaims privateClaims, final Long expirationTime) { final Date now = new Date(); return Jwts.builder() - .setClaims(claims) - .setIssuedAt(now) - .setExpiration(new Date(now.getTime() + expirationTime)) + .issuer(JWTConsts.TOKEN_ISSUER) + .claims(privateClaims.createClaimsMap()) + .issuedAt(now) + .expiration(new Date(now.getTime() + expirationTime)) .signWith(getSigningKey()) .compact(); } @@ -114,7 +79,7 @@ private String generateToken(final Claims claims, final Long expirationTime) { /** * @return 서명에 사용할 Key 반환 */ - private Key getSigningKey() { + private SecretKey getSigningKey() { return Keys.hmacShaKeyFor(Decoders.BASE64.decode(jwtProperties.getSecret())); } @@ -133,20 +98,17 @@ public void validateToken(final String token, final TokenType tokenType) { } } - /** - * iss, key 설정 - * - * @return 토큰 검증 위한 JwtParser 반환 - */ + private JwtParser initializeJwtParser(final TokenType tokenType) { - return Jwts.parserBuilder() - .setSigningKey(getSigningKey()) + return Jwts.parser() + .json(new JacksonDeserializer<>(PrivateClaims.getClaimsTypeDetailMap())) + .verifyWith(getSigningKey()) .requireIssuer(JWTConsts.TOKEN_ISSUER) - .require(JWTConsts.TOKEN_TYPE, tokenType.name()) + .require(JWTConsts.TOKEN_TYPE, tokenType) .build(); } - public record Token(String accessToken, String refreshToken){ + public record Token(String accessToken, String refreshToken) { } } From 9edf095c00d0ff767aaec411cf3d59b73d8a9439 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:22:18 +0900 Subject: [PATCH 04/27] =?UTF-8?q?PET-300=20test=20:=20JWTProvider=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authdomain/jwt/JWTProviderTest.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/test/java/com/pawith/authdomain/jwt/JWTProviderTest.java b/Domain-Module/Auth-Module/Auth-Domain/src/test/java/com/pawith/authdomain/jwt/JWTProviderTest.java index de9483f9..663a1ddc 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/test/java/com/pawith/authdomain/jwt/JWTProviderTest.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/test/java/com/pawith/authdomain/jwt/JWTProviderTest.java @@ -9,6 +9,7 @@ import io.jsonwebtoken.JwtParser; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.io.Decoders; +import io.jsonwebtoken.jackson.io.JacksonDeserializer; import io.jsonwebtoken.security.Keys; import lombok.SneakyThrows; import org.assertj.core.api.Assertions; @@ -33,29 +34,29 @@ void init(){ } @Test - @DisplayName("사용자 email이 입력으로 들어오면 accessToken을 발급하여 반환한다.") + @DisplayName("사용자 정보가 입력으로 들어오면 accessToken을 발급하여 반환한다.") void generateAccessTokenByEmail(){ //given - final String randomEmail = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(String.class); - final String accessToken = jwtProvider.generateAccessToken(randomEmail); + final PrivateClaims.UserClaims userClaims = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(PrivateClaims.UserClaims.class); + final String accessToken = jwtProvider.generateAccessToken(userClaims); //when final Claims body = extractClaimsFromToken(accessToken); //then - Assertions.assertThat(body.get(JWTConsts.EMAIL)).isEqualTo(randomEmail); - Assertions.assertThat(body.get(JWTConsts.TOKEN_TYPE)).isEqualTo(TokenType.ACCESS_TOKEN.toString()); + Assertions.assertThat(body.get(JWTConsts.USER_CLAIMS)).usingRecursiveComparison().isEqualTo(userClaims); + Assertions.assertThat(body.get(JWTConsts.TOKEN_TYPE)).isEqualTo(TokenType.ACCESS_TOKEN); } @Test - @DisplayName("사용자 email이 입력으로 들어오면 refreshToken을 발급하여 반환한다.") + @DisplayName("사용자 정보가 입력으로 들어오면 refreshToken을 발급하여 반환한다.") void generateRefreshTokenByEmail(){ //given - final String randomEmail = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(String.class); - final String refreshToken = jwtProvider.generateRefreshToken(randomEmail); + final PrivateClaims.UserClaims userClaims = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(PrivateClaims.UserClaims.class); + final String refreshToken = jwtProvider.generateRefreshToken(userClaims); //when final Claims body = extractClaimsFromToken(refreshToken); //then - Assertions.assertThat(body.get(JWTConsts.EMAIL)).isEqualTo(randomEmail); - Assertions.assertThat(body.get(JWTConsts.TOKEN_TYPE)).isEqualTo(TokenType.REFRESH_TOKEN.toString()); + Assertions.assertThat(body.get(JWTConsts.USER_CLAIMS)).usingRecursiveComparison().isEqualTo(userClaims); + Assertions.assertThat(body.get(JWTConsts.TOKEN_TYPE)).isEqualTo(TokenType.REFRESH_TOKEN); } @Test @@ -74,8 +75,8 @@ void validateTokenWithInvalidToken(){ @SneakyThrows void validateTokenWithExpiredToken(){ //given - final String randomEmail = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(String.class); - final String refreshToken = jwtProvider.generateRefreshToken(randomEmail); + final PrivateClaims.UserClaims userClaims = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(PrivateClaims.UserClaims.class); + final String refreshToken = jwtProvider.generateAccessToken(userClaims); Thread.sleep(JWTTestConsts.REFRESH_TOKEN_EXPIRED_TIME+1); //when //then @@ -86,13 +87,15 @@ void validateTokenWithExpiredToken(){ private Claims extractClaimsFromToken(final String token){ return createJwtParser() - .parseClaimsJws(token) - .getBody(); + .parseSignedClaims(token) + .getPayload(); + } private JwtParser createJwtParser() { - return Jwts.parserBuilder() - .setSigningKey(Keys.hmacShaKeyFor(Decoders.BASE64.decode(jwtProperties.getSecret()))) + return Jwts.parser() + .json(new JacksonDeserializer<>(PrivateClaims.getClaimsTypeDetailMap())) + .verifyWith(Keys.hmacShaKeyFor(Decoders.BASE64.decode(jwtProperties.getSecret()))) .requireIssuer(JWTConsts.TOKEN_ISSUER) .build(); } From 2f4417a3a35d5cf3b31505b4d55c85dc87589273 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:24:59 +0900 Subject: [PATCH 05/27] =?UTF-8?q?PET-300=20fix=20:=20Jwt=20email=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=EC=97=90=EC=84=9C=20userId=EA=B8=B0=EB=B0=98?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20Tok?= =?UTF-8?q?en=20=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20userId=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pawith/authdomain/entity/Token.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/Token.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/Token.java index e57dd93e..4e347b18 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/Token.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/Token.java @@ -24,14 +24,14 @@ public class Token extends BaseEntity { @Enumerated(EnumType.STRING) private TokenType tokenType; - private String email; + private Long userId; private String value; private Boolean isDeleted = Boolean.FALSE; @Builder - public Token(TokenType tokenType, String email, String value) { + public Token(TokenType tokenType, Long userId, String value) { this.tokenType = tokenType; - this.email = email; + this.userId = userId; this.value = value; } } From ce4f7b92a0760e9f5b808bf8ed69bbfaf5b03681 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:25:55 +0900 Subject: [PATCH 06/27] =?UTF-8?q?PET-300=20fix=20:=20Jwt=20email=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=EC=97=90=EC=84=9C=20userId=EA=B8=B0=EB=B0=98?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20Tok?= =?UTF-8?q?en=20=EC=A1=B0=ED=9A=8C,=20=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20use?= =?UTF-8?q?rId=20=EC=9D=B4=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20email=20=EA=B8=B0=EB=B0=98=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pawith/authdomain/repository/TokenRepository.java | 3 --- .../com/pawith/authdomain/service/TokenQueryService.java | 6 ------ .../com/pawith/authdomain/service/TokenSaveService.java | 2 +- .../authdomain/service/impl/TokenQueryServiceImpl.java | 9 --------- .../authdomain/service/impl/TokenSaveServiceImpl.java | 5 ++--- 5 files changed, 3 insertions(+), 22 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/TokenRepository.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/TokenRepository.java index ce9f5329..fd8961d4 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/TokenRepository.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/TokenRepository.java @@ -4,14 +4,11 @@ import com.pawith.authdomain.jwt.TokenType; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; import java.util.Optional; public interface TokenRepository extends JpaRepository { Optional findByValueAndTokenType(String email, TokenType tokenType); - List findAllByEmailAndTokenType(String email, TokenType tokenType); - void deleteByValue(String value); Boolean existsByValueAndTokenType(String value, TokenType tokenType); diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenQueryService.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenQueryService.java index 8215390e..4b595457 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenQueryService.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenQueryService.java @@ -3,13 +3,7 @@ import com.pawith.authdomain.entity.Token; import com.pawith.authdomain.jwt.TokenType; -import java.util.List; - public interface TokenQueryService { - String findEmailByValue(final String value, final TokenType tokenType); - Token findTokenByValue(final String value, final TokenType tokenType); - - List findAllByEmailAndTokenType(String email, TokenType tokenType); } diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenSaveService.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenSaveService.java index d8b52f69..e3d43e3e 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenSaveService.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/TokenSaveService.java @@ -4,5 +4,5 @@ public interface TokenSaveService { - void saveToken(final String token, final String email, final TokenType tokenType); + void saveToken(final String token, final TokenType tokenType, final Long userId); } diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenQueryServiceImpl.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenQueryServiceImpl.java index 00a372a9..02915063 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenQueryServiceImpl.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenQueryServiceImpl.java @@ -15,21 +15,12 @@ @RequiredArgsConstructor public class TokenQueryServiceImpl implements TokenQueryService { private final TokenRepository tokenRepository; - @Override - public String findEmailByValue(final String value, final TokenType tokenType) { - Token token = findToken(value, tokenType); - return token.getEmail(); - } @Override public Token findTokenByValue(String value, TokenType tokenType) { return findToken(value, tokenType); } - public List findAllByEmailAndTokenType(String email, TokenType tokenType){ - return tokenRepository.findAllByEmailAndTokenType(email, tokenType); - } - private Token findToken(final String value, final TokenType tokenType){ return tokenRepository.findByValueAndTokenType(value, tokenType) .orElseThrow(() -> new NotExistTokenException(AuthError.NOT_EXIST_TOKEN)); diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenSaveServiceImpl.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenSaveServiceImpl.java index 3497a49d..33f491dc 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenSaveServiceImpl.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/service/impl/TokenSaveServiceImpl.java @@ -13,13 +13,12 @@ public class TokenSaveServiceImpl implements TokenSaveService { private final TokenRepository tokenRepository; @Override - public void saveToken(final String token, final String email, final TokenType tokenType) { + public void saveToken(String token, TokenType tokenType, Long userId) { final Token saveToken = Token.builder() .tokenType(tokenType) .value(token) - .email(email) + .userId(userId) .build(); tokenRepository.save(saveToken); } - } From 2862ddb4e4244347061fe8e14db0d3c7b56a70a5 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:27:18 +0900 Subject: [PATCH 07/27] =?UTF-8?q?PET-300=20refactor=20:=20=EB=AF=B8?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20=ED=86=A0=ED=81=B0=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=95=88=ED=95=A8=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnusedTokenExpireEventHandler.java | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/handler/UnusedTokenExpireEventHandler.java diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/handler/UnusedTokenExpireEventHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/handler/UnusedTokenExpireEventHandler.java deleted file mode 100644 index f6da26f6..00000000 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/handler/UnusedTokenExpireEventHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.pawith.authapplication.handler; - -import com.pawith.authapplication.handler.request.UnusedTokenExpireEvent; -import com.pawith.authdomain.entity.Token; -import com.pawith.authdomain.service.TokenDeleteService; -import com.pawith.authdomain.service.TokenQueryService; -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Component -@RequiredArgsConstructor -@Transactional -public class UnusedTokenExpireEventHandler { - - private final TokenQueryService tokenQueryService; - private final TokenDeleteService tokenDeleteService; - - @EventListener - public void handle(UnusedTokenExpireEvent event){ - final List allToken = tokenQueryService.findAllByEmailAndTokenType(event.getEmail(), event.getTokenType()); - tokenDeleteService.deleteAllToken(allToken); - } - -} From b1abe01709a37201c9bf8b3d82f3c937d1a7bb71 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:30:55 +0900 Subject: [PATCH 08/27] =?UTF-8?q?PET-300=20refactor=20:=20jwt=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=96=BB=EC=9D=80=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20email=EC=97=90=EC=84=9C=20userId?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/security/JWTAuthenticationToken.java | 8 ++++---- .../common/security/filter/JWTAuthenticationFilter.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/JWTAuthenticationToken.java b/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/JWTAuthenticationToken.java index 77209d75..7328e727 100644 --- a/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/JWTAuthenticationToken.java +++ b/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/JWTAuthenticationToken.java @@ -4,10 +4,10 @@ public class JWTAuthenticationToken extends AbstractAuthenticationToken { - private String email; - public JWTAuthenticationToken(String email) { + private Long userId; + public JWTAuthenticationToken(Long userId) { super(null); - this.email=email; + this.userId = userId; setAuthenticated(true); } @@ -18,6 +18,6 @@ public Object getCredentials() { @Override public Object getPrincipal() { - return email; + return userId; } } diff --git a/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/filter/JWTAuthenticationFilter.java b/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/filter/JWTAuthenticationFilter.java index bff0aaf7..0dc03318 100644 --- a/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/filter/JWTAuthenticationFilter.java +++ b/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/common/security/filter/JWTAuthenticationFilter.java @@ -2,7 +2,7 @@ import com.pawith.authapplication.consts.AuthConsts; import com.pawith.authapplication.consts.IgnoredPathConsts; -import com.pawith.authapplication.service.JWTExtractEmailUseCase; +import com.pawith.authapplication.service.JWTExtractUserDetailsUseCase; import com.pawith.authapplication.service.JWTExtractTokenUseCase; import com.pawith.authapplication.service.JWTVerifyUseCase; import com.pawith.authpresentation.common.security.JWTAuthenticationToken; @@ -26,7 +26,7 @@ public class JWTAuthenticationFilter extends OncePerRequestFilter { private final JWTVerifyUseCase jwtVerifyUseCase; - private final JWTExtractEmailUseCase jwtExtractEmailUseCase; + private final JWTExtractUserDetailsUseCase jwtExtractUserDetailsUseCase; private final JWTExtractTokenUseCase jwtExtractTokenUseCase; @Override @@ -35,8 +35,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse final String tokenHeaderValue = getTokenFromHeader(request); final String accessToken = jwtExtractTokenUseCase.extractToken(tokenHeaderValue); jwtVerifyUseCase.validateToken(accessToken); - final String email = jwtExtractEmailUseCase.extractEmail(accessToken); - initAuthentication(new JWTAuthenticationToken(email)); + final Long userId = jwtExtractUserDetailsUseCase.extract(accessToken); + initAuthentication(new JWTAuthenticationToken(userId)); } filterChain.doFilter(request, response); } From f8a476ca7634c6f6e87ab61b9b4a6c607e399b28 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:31:45 +0900 Subject: [PATCH 09/27] =?UTF-8?q?PET-300=20feat=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EB=8B=B4=EC=9D=84=20claims=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20email=20->=20user=5Fclaims=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pawith/authdomain/jwt/JWTConsts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTConsts.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTConsts.java index 703d553d..11d87f15 100644 --- a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTConsts.java +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/jwt/JWTConsts.java @@ -6,6 +6,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class JWTConsts { public static final String TOKEN_ISSUER = "pawith"; - public static final String EMAIL ="email"; + public static final String USER_CLAIMS = "user_claims"; public static final String TOKEN_TYPE = "token_type"; } From 83850c3ff6e8491dc670d2fe282f8c3391005b1e Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:32:36 +0900 Subject: [PATCH 10/27] =?UTF-8?q?PET-300=20refactor=20:=20JWTExtractEmailU?= =?UTF-8?q?seCase=EC=97=90=EC=84=9C=20email=20=EC=B6=94=EC=B6=9C=EC=9D=B4?= =?UTF-8?q?=20=EC=95=84=EB=8B=8C=20userId=20=EC=B6=94=EC=B6=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20JWTExtractUserDetails?= =?UTF-8?q?UseCase=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authapplication/service/JWTExtractEmailUseCase.java | 5 ----- .../service/JWTExtractUserDetailsUseCase.java | 5 +++++ ...seImpl.java => JWTExtractUserDetailsUseCaseImpl.java} | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractEmailUseCase.java create mode 100644 Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCase.java rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/{JWTExtractEmailUseCaseImpl.java => JWTExtractUserDetailsUseCaseImpl.java} (52%) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractEmailUseCase.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractEmailUseCase.java deleted file mode 100644 index fabac432..00000000 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractEmailUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.pawith.authapplication.service; - -public interface JWTExtractEmailUseCase { - String extractEmail(final String token); -} diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCase.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCase.java new file mode 100644 index 00000000..9c989d1f --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCase.java @@ -0,0 +1,5 @@ +package com.pawith.authapplication.service; + +public interface JWTExtractUserDetailsUseCase { + T extract(final String token); +} diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/JWTExtractEmailUseCaseImpl.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/JWTExtractUserDetailsUseCaseImpl.java similarity index 52% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/JWTExtractEmailUseCaseImpl.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/JWTExtractUserDetailsUseCaseImpl.java index 9512f912..48b7048b 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/JWTExtractEmailUseCaseImpl.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/JWTExtractUserDetailsUseCaseImpl.java @@ -1,6 +1,6 @@ package com.pawith.authapplication.service.impl; -import com.pawith.authapplication.service.JWTExtractEmailUseCase; +import com.pawith.authapplication.service.JWTExtractUserDetailsUseCase; import com.pawith.authdomain.jwt.JWTProvider; import com.pawith.authdomain.jwt.TokenType; import com.pawith.commonmodule.annotation.ApplicationService; @@ -8,11 +8,12 @@ @ApplicationService @RequiredArgsConstructor -public class JWTExtractEmailUseCaseImpl implements JWTExtractEmailUseCase { +public class JWTExtractUserDetailsUseCaseImpl implements JWTExtractUserDetailsUseCase { private final JWTProvider jwtProvider; @Override - public String extractEmail(final String token){ - return jwtProvider.extractEmailFromToken(token, TokenType.ACCESS_TOKEN); + public Long extract(final String token) { + return jwtProvider.extractUserClaimsFromToken(token, TokenType.ACCESS_TOKEN) + .getUserId(); } } From 887e14bf9bfee16c699fec40d51728c396d0b8a4 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:46:49 +0900 Subject: [PATCH 11/27] =?UTF-8?q?PET-300=20refactor=20:=20OAuth=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B4=80=EB=A0=A8=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/{command/handler => oauth}/AuthHandler.java | 2 +- .../{command => oauth}/feign/AppleFeignClient.java | 4 ++-- .../{command => oauth}/feign/GoogleOAuthFeignClient.java | 4 ++-- .../{command => oauth}/feign/KakaoOAuthFeignClient.java | 6 +++--- .../{command => oauth}/feign/NaverOAuthFeignClient.java | 4 ++-- .../feign/response/GoogleUserInfo.java | 2 +- .../{command => oauth}/feign/response/KakaoUserInfo.java | 2 +- .../service/{command => oauth}/feign/response/Keys.java | 2 +- .../{command => oauth}/feign/response/NaverUserInfo.java | 2 +- .../handler => oauth}/impl/AppleOAuthHandler.java | 6 +++--- .../handler => oauth}/impl/GoogleOAuthHandler.java | 6 +++--- .../handler => oauth}/impl/KakaoOAuthHandler.java | 8 ++++---- .../handler => oauth}/impl/NaverOAuthHandler.java | 6 +++--- .../handler/impl/GoogleOAuthHandlerTest.java | 7 ++++--- .../handler/impl/KakaoOAuthHandlerTest.java | 9 +++++---- .../handler/impl/NaverOAuthHandlerTest.java | 7 ++++--- 16 files changed, 40 insertions(+), 37 deletions(-) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command/handler => oauth}/AuthHandler.java (83%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/AppleFeignClient.java (72%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/GoogleOAuthFeignClient.java (74%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/KakaoOAuthFeignClient.java (71%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/NaverOAuthFeignClient.java (74%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/response/GoogleUserInfo.java (77%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/response/KakaoUserInfo.java (92%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/response/Keys.java (82%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/response/NaverUserInfo.java (88%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command/handler => oauth}/impl/AppleOAuthHandler.java (95%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command/handler => oauth}/impl/GoogleOAuthHandler.java (84%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command/handler => oauth}/impl/KakaoOAuthHandler.java (85%) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command/handler => oauth}/impl/NaverOAuthHandler.java (84%) rename Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/{command => oauth}/handler/impl/GoogleOAuthHandlerTest.java (87%) rename Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/{command => oauth}/handler/impl/KakaoOAuthHandlerTest.java (91%) rename Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/{command => oauth}/handler/impl/NaverOAuthHandlerTest.java (87%) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/AuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/AuthHandler.java similarity index 83% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/AuthHandler.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/AuthHandler.java index 6667ffe3..0ae9944c 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/AuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/AuthHandler.java @@ -1,4 +1,4 @@ -package com.pawith.authapplication.service.command.handler; +package com.pawith.authapplication.service.oauth; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/AppleFeignClient.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/AppleFeignClient.java similarity index 72% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/AppleFeignClient.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/AppleFeignClient.java index eb858be1..1708a2d5 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/AppleFeignClient.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/AppleFeignClient.java @@ -1,6 +1,6 @@ -package com.pawith.authapplication.service.command.feign; +package com.pawith.authapplication.service.oauth.feign; -import com.pawith.authapplication.service.command.feign.response.Keys; +import com.pawith.authapplication.service.oauth.feign.response.Keys; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/GoogleOAuthFeignClient.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/GoogleOAuthFeignClient.java similarity index 74% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/GoogleOAuthFeignClient.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/GoogleOAuthFeignClient.java index fdf5e3df..0adaeebe 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/GoogleOAuthFeignClient.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/GoogleOAuthFeignClient.java @@ -1,6 +1,6 @@ -package com.pawith.authapplication.service.command.feign; +package com.pawith.authapplication.service.oauth.feign; -import com.pawith.authapplication.service.command.feign.response.GoogleUserInfo; +import com.pawith.authapplication.service.oauth.feign.response.GoogleUserInfo; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/KakaoOAuthFeignClient.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/KakaoOAuthFeignClient.java similarity index 71% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/KakaoOAuthFeignClient.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/KakaoOAuthFeignClient.java index 28847967..d8f8f118 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/KakaoOAuthFeignClient.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/KakaoOAuthFeignClient.java @@ -1,7 +1,7 @@ -package com.pawith.authapplication.service.command.feign; +package com.pawith.authapplication.service.oauth.feign; -import com.pawith.authapplication.service.command.feign.response.KakaoUserInfo; -import com.pawith.authapplication.service.command.feign.response.TokenInfo; +import com.pawith.authapplication.service.oauth.feign.response.KakaoUserInfo; +import com.pawith.authapplication.service.oauth.feign.response.TokenInfo; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/NaverOAuthFeignClient.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/NaverOAuthFeignClient.java similarity index 74% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/NaverOAuthFeignClient.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/NaverOAuthFeignClient.java index c08904d4..c34d2d05 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/NaverOAuthFeignClient.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/NaverOAuthFeignClient.java @@ -1,6 +1,6 @@ -package com.pawith.authapplication.service.command.feign; +package com.pawith.authapplication.service.oauth.feign; -import com.pawith.authapplication.service.command.feign.response.NaverUserInfo; +import com.pawith.authapplication.service.oauth.feign.response.NaverUserInfo; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/GoogleUserInfo.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/GoogleUserInfo.java similarity index 77% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/GoogleUserInfo.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/GoogleUserInfo.java index 1792dcbd..e30dbf72 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/GoogleUserInfo.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/GoogleUserInfo.java @@ -1,4 +1,4 @@ -package com.pawith.authapplication.service.command.feign.response; +package com.pawith.authapplication.service.oauth.feign.response; import lombok.AccessLevel; import lombok.Getter; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/KakaoUserInfo.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/KakaoUserInfo.java similarity index 92% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/KakaoUserInfo.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/KakaoUserInfo.java index da0398ea..09726b15 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/KakaoUserInfo.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/KakaoUserInfo.java @@ -1,4 +1,4 @@ -package com.pawith.authapplication.service.command.feign.response; +package com.pawith.authapplication.service.oauth.feign.response; import com.fasterxml.jackson.annotation.JsonAlias; import lombok.AccessLevel; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/Keys.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/Keys.java similarity index 82% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/Keys.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/Keys.java index 59a98420..363da09c 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/Keys.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/Keys.java @@ -1,4 +1,4 @@ -package com.pawith.authapplication.service.command.feign.response; +package com.pawith.authapplication.service.oauth.feign.response; import lombok.Data; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/NaverUserInfo.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/NaverUserInfo.java similarity index 88% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/NaverUserInfo.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/NaverUserInfo.java index 77513765..f52df0ca 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/NaverUserInfo.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/NaverUserInfo.java @@ -1,4 +1,4 @@ -package com.pawith.authapplication.service.command.feign.response; +package com.pawith.authapplication.service.oauth.feign.response; import lombok.AccessLevel; import lombok.Getter; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/AppleOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java similarity index 95% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/AppleOAuthHandler.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java index ea548b8a..4b4e07a2 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/AppleOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java @@ -1,9 +1,9 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.AppleFeignClient; -import com.pawith.authapplication.service.command.feign.response.Keys; +import com.pawith.authapplication.service.oauth.feign.AppleFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.Keys; import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.authdomain.exception.AuthError; import com.pawith.authdomain.jwt.exception.InvalidTokenException; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/GoogleOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java similarity index 84% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/GoogleOAuthHandler.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java index 841b16bb..fffd5208 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/GoogleOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java @@ -1,9 +1,9 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.GoogleOAuthFeignClient; -import com.pawith.authapplication.service.command.feign.response.GoogleUserInfo; +import com.pawith.authapplication.service.oauth.feign.GoogleOAuthFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.GoogleUserInfo; import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.commonmodule.enums.Provider; import lombok.RequiredArgsConstructor; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/KakaoOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java similarity index 85% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/KakaoOAuthHandler.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java index 11e552c3..b923a5ab 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/KakaoOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java @@ -1,10 +1,10 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.KakaoOAuthFeignClient; -import com.pawith.authapplication.service.command.feign.response.KakaoUserInfo; -import com.pawith.authapplication.service.command.feign.response.TokenInfo; +import com.pawith.authapplication.service.oauth.feign.KakaoOAuthFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.KakaoUserInfo; +import com.pawith.authapplication.service.oauth.feign.response.TokenInfo; import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.authdomain.exception.AuthError; import com.pawith.authdomain.jwt.exception.InvalidTokenException; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/NaverOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java similarity index 84% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/NaverOAuthHandler.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java index 20c4a4af..0324f2e4 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/handler/impl/NaverOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java @@ -1,9 +1,9 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.NaverOAuthFeignClient; -import com.pawith.authapplication.service.command.feign.response.NaverUserInfo; +import com.pawith.authapplication.service.oauth.feign.NaverOAuthFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.NaverUserInfo; import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.commonmodule.enums.Provider; import lombok.RequiredArgsConstructor; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/GoogleOAuthHandlerTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/GoogleOAuthHandlerTest.java similarity index 87% rename from Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/GoogleOAuthHandlerTest.java rename to Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/GoogleOAuthHandlerTest.java index f8d73f59..43854f11 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/GoogleOAuthHandlerTest.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/GoogleOAuthHandlerTest.java @@ -1,9 +1,10 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.handler.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.GoogleOAuthFeignClient; -import com.pawith.authapplication.service.command.feign.response.GoogleUserInfo; +import com.pawith.authapplication.service.oauth.feign.GoogleOAuthFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.GoogleUserInfo; +import com.pawith.authapplication.service.oauth.impl.GoogleOAuthHandler; import com.pawith.commonmodule.UnitTestConfig; import com.pawith.commonmodule.enums.Provider; import com.pawith.commonmodule.utils.FixtureMonkeyUtils; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/KakaoOAuthHandlerTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/KakaoOAuthHandlerTest.java similarity index 91% rename from Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/KakaoOAuthHandlerTest.java rename to Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/KakaoOAuthHandlerTest.java index 4e032cfe..87dc72c1 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/KakaoOAuthHandlerTest.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/KakaoOAuthHandlerTest.java @@ -1,10 +1,11 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.handler.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.KakaoOAuthFeignClient; -import com.pawith.authapplication.service.command.feign.response.KakaoUserInfo; -import com.pawith.authapplication.service.command.feign.response.TokenInfo; +import com.pawith.authapplication.service.oauth.feign.KakaoOAuthFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.KakaoUserInfo; +import com.pawith.authapplication.service.oauth.feign.response.TokenInfo; +import com.pawith.authapplication.service.oauth.impl.KakaoOAuthHandler; import com.pawith.authdomain.jwt.exception.InvalidTokenException; import com.pawith.commonmodule.UnitTestConfig; import com.pawith.commonmodule.enums.Provider; diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/NaverOAuthHandlerTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/NaverOAuthHandlerTest.java similarity index 87% rename from Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/NaverOAuthHandlerTest.java rename to Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/NaverOAuthHandlerTest.java index a3e09680..aab2c45c 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/handler/impl/NaverOAuthHandlerTest.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/handler/impl/NaverOAuthHandlerTest.java @@ -1,9 +1,10 @@ -package com.pawith.authapplication.service.command.handler.impl; +package com.pawith.authapplication.service.oauth.handler.impl; import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.feign.NaverOAuthFeignClient; -import com.pawith.authapplication.service.command.feign.response.NaverUserInfo; +import com.pawith.authapplication.service.oauth.feign.NaverOAuthFeignClient; +import com.pawith.authapplication.service.oauth.feign.response.NaverUserInfo; +import com.pawith.authapplication.service.oauth.impl.NaverOAuthHandler; import com.pawith.commonmodule.UnitTestConfig; import com.pawith.commonmodule.enums.Provider; import com.pawith.commonmodule.utils.FixtureMonkeyUtils; From d8b07285e773a44e14bda5c857bf0153c3fcc61d Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:50:07 +0900 Subject: [PATCH 12/27] =?UTF-8?q?PET-300=20refactor=20:=20SecurityContextH?= =?UTF-8?q?older=20=EB=82=B4=EB=B6=80=EC=9D=98=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=B3=B4=EA=B0=80=20email=20->=20userId?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=EB=90=A8=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B0=A9=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/pawith/commonmodule/util/SecurityUtils.java | 5 ++--- .../main/java/com/pawith/userdomain/utils/UserUtils.java | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Common-Module/src/main/java/com/pawith/commonmodule/util/SecurityUtils.java b/Common-Module/src/main/java/com/pawith/commonmodule/util/SecurityUtils.java index 5e9a4ccb..f2ca0124 100644 --- a/Common-Module/src/main/java/com/pawith/commonmodule/util/SecurityUtils.java +++ b/Common-Module/src/main/java/com/pawith/commonmodule/util/SecurityUtils.java @@ -7,8 +7,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class SecurityUtils { - public static String getAuthenticationPrincipal() { - final String email = (String)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - return email; + public static Long getAuthenticationPrincipal() { + return (Long)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); } } diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java index 005cae6e..2015e2ee 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java @@ -15,11 +15,11 @@ public class UserUtils { private final UserQueryService userQueryService; public User getAccessUser(){ - final String email = SecurityUtils.getAuthenticationPrincipal(); - return userQueryService.findByEmail(email); + final Long userId = SecurityUtils.getAuthenticationPrincipal(); + return userQueryService.findById(userId); } - public static String getEmailFromAccessUser(){ + public static Long getIdFromAccessUser(){ return SecurityUtils.getAuthenticationPrincipal(); } } From ecec6207f0d7770c3c2bc08733c665b45904ee0a Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:55:59 +0900 Subject: [PATCH 13/27] =?UTF-8?q?PET-300=20refactor=20:=20UserAuthority?= =?UTF-8?q?=EC=97=90=EC=84=9C=20User=EC=99=80=20=EC=99=84=EA=B4=80?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=84=A4=EC=A0=95=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20email=20=EA=B8=B0=EB=B0=98=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/UserAuthorityGetUseCase.java | 4 ++-- .../service/UserAuthorityGetUseCaseTest.java | 4 ++-- .../pawith/userdomain/entity/UserAuthority.java | 11 ++++++++++- .../repository/UserAuthorityRepository.java | 2 ++ .../service/UserAuthorityQueryService.java | 5 +++++ .../service/UserAuthoritySaveService.java | 5 +++-- .../service/UserAuthorityQueryServiceTest.java | 16 ++++++++-------- .../service/UserAuthoritySaveServiceTest.java | 9 ++++++--- 8 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java index 47f3132a..38a31d2f 100644 --- a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java +++ b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java @@ -14,8 +14,8 @@ public class UserAuthorityGetUseCase { private final UserAuthorityQueryService userAuthorityQueryService; public UserAuthorityInfoResponse getUserAuthority() { - final String email = UserUtils.getEmailFromAccessUser(); - final UserAuthority userAuthority = userAuthorityQueryService.findByEmail(email); + final Long userId = UserUtils.getIdFromAccessUser(); + final UserAuthority userAuthority = userAuthorityQueryService.findByUserId(userId); return new UserAuthorityInfoResponse(userAuthority.getAuthority()); } } diff --git a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java index cb06346a..331330c5 100644 --- a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java +++ b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mock; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.BDDMockito.given; @UnitTestConfig @@ -37,7 +37,7 @@ void getUserAuthority() { final UserAuthority userAuthority = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey() .giveMeBuilder(UserAuthority.class) .sample(); - given(userAuthorityQueryService.findByEmail(anyString())).willReturn(userAuthority); + given(userAuthorityQueryService.findByUserId(anyLong())).willReturn(userAuthority); //when UserAuthorityInfoResponse result = userAuthorityGetUseCase.getUserAuthority(); //then diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/entity/UserAuthority.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/entity/UserAuthority.java index 20543a3c..d07f3732 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/entity/UserAuthority.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/entity/UserAuthority.java @@ -21,11 +21,20 @@ public class UserAuthority extends BaseEntity { private Authority authority; private String email; - public UserAuthority(String email) { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + private UserAuthority(User user, String email) { this.authority = Authority.GUEST; + this.user = user; this.email = email; } + public static UserAuthority of(User user, String email) { + return new UserAuthority(user,email); + } + public void changeUserAuthority(){ if(this.authority.equals(Authority.GUEST)){ this.authority = Authority.USER; diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/repository/UserAuthorityRepository.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/repository/UserAuthorityRepository.java index f8b18065..09f07526 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/repository/UserAuthorityRepository.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/repository/UserAuthorityRepository.java @@ -8,4 +8,6 @@ public interface UserAuthorityRepository extends JpaRepository { Optional findByEmail(String email); + + Optional findByUserId(Long userId); } diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthorityQueryService.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthorityQueryService.java index d846e4d7..00b28425 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthorityQueryService.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthorityQueryService.java @@ -17,4 +17,9 @@ public UserAuthority findByEmail(final String email) { .orElseThrow(() -> new UserAuthorityNotFoundException(UserError.USER_AUTHORITY_NOT_FOUND)); return userAuthority; } + + public UserAuthority findByUserId(final Long userId) { + return userAuthorityRepository.findByUserId(userId) + .orElseThrow(() -> new UserAuthorityNotFoundException(UserError.USER_AUTHORITY_NOT_FOUND)); + } } diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthoritySaveService.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthoritySaveService.java index 454ad0d8..f1f64fc5 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthoritySaveService.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/service/UserAuthoritySaveService.java @@ -1,6 +1,7 @@ package com.pawith.userdomain.service; import com.pawith.commonmodule.annotation.DomainService; +import com.pawith.userdomain.entity.User; import com.pawith.userdomain.entity.UserAuthority; import com.pawith.userdomain.repository.UserAuthorityRepository; import lombok.RequiredArgsConstructor; @@ -10,10 +11,10 @@ public class UserAuthoritySaveService { private final UserAuthorityRepository userAuthorityRepository; - public void saveUserAuthority(final String email) { + public void saveUserAuthority(final User user, final String email) { userAuthorityRepository.findByEmail(email) .ifPresentOrElse( UserAuthority::initialUserAuthority, - () -> userAuthorityRepository.save(new UserAuthority(email))); + () -> userAuthorityRepository.save(UserAuthority.of(user, email))); } } diff --git a/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthorityQueryServiceTest.java b/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthorityQueryServiceTest.java index deb3ce33..96e1f348 100644 --- a/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthorityQueryServiceTest.java +++ b/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthorityQueryServiceTest.java @@ -1,8 +1,8 @@ package com.pawith.userdomain.service; -import com.navercorp.fixturemonkey.FixtureMonkey; import com.pawith.commonmodule.UnitTestConfig; import com.pawith.commonmodule.utils.FixtureMonkeyUtils; +import com.pawith.userdomain.entity.User; import com.pawith.userdomain.entity.UserAuthority; import com.pawith.userdomain.exception.UserAuthorityNotFoundException; import com.pawith.userdomain.repository.UserAuthorityRepository; @@ -36,14 +36,14 @@ void init() { @DisplayName("유저 권한을 조회한다.") void findByEmail() { //given - final String email = FixtureMonkey.create().giveMeOne(String.class); + final User user = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey().giveMeOne(User.class); final UserAuthority userAuthority = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey() .giveMeBuilder(UserAuthority.class) - .set("email", email) + .set("user", user) .sample(); - given(userAuthorityRepository.findByEmail(email)).willReturn(Optional.of(userAuthority)); + given(userAuthorityRepository.findByUserId(user.getId())).willReturn(Optional.of(userAuthority)); //when - UserAuthority result = userAuthorityQueryService.findByEmail(email); + UserAuthority result = userAuthorityQueryService.findByUserId(user.getId()); //then Assertions.assertThat(result).usingRecursiveComparison().isEqualTo(userAuthority); } @@ -52,11 +52,11 @@ void findByEmail() { @DisplayName("유저 권한을 조회할 수 없으면 예외가 발생한다.") void findByEmailThrowException() { //given - final String email = FixtureMonkey.create().giveMeOne(String.class); - given(userAuthorityRepository.findByEmail(email)).willReturn(Optional.empty()); + final Long userId = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey().giveMeOne(Long.class); + given(userAuthorityRepository.findByUserId(userId)).willReturn(Optional.empty()); //when //then - Assertions.assertThatCode(() -> userAuthorityQueryService.findByEmail(email)) + Assertions.assertThatCode(() -> userAuthorityQueryService.findByUserId(userId)) .isInstanceOf(UserAuthorityNotFoundException.class); } diff --git a/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthoritySaveServiceTest.java b/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthoritySaveServiceTest.java index 55be1e03..64e03158 100644 --- a/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthoritySaveServiceTest.java +++ b/Domain-Module/User-Module/User-Domain/src/test/java/com/pawith/userdomain/service/UserAuthoritySaveServiceTest.java @@ -2,6 +2,7 @@ import com.pawith.commonmodule.UnitTestConfig; import com.pawith.commonmodule.utils.FixtureMonkeyUtils; +import com.pawith.userdomain.entity.User; import com.pawith.userdomain.entity.UserAuthority; import com.pawith.userdomain.repository.UserAuthorityRepository; import org.junit.jupiter.api.BeforeEach; @@ -34,9 +35,10 @@ void init() { void saveUserAuthority() { //given final String email = FixtureMonkeyUtils.getJavaTypeBasedFixtureMonkey().giveMeOne(String.class); + final User user = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(User.class); given(userAuthorityRepository.findByEmail(email)).willReturn(Optional.empty()); //when - userAuthoritySaveService.saveUserAuthority(email); + userAuthoritySaveService.saveUserAuthority(user, email); //then then(userAuthorityRepository).should().save(any()); } @@ -46,9 +48,10 @@ void saveUserAuthority() { void saveUserAuthorityWhenUserAuthorityExist() { //given final String email = FixtureMonkeyUtils.getJavaTypeBasedFixtureMonkey().giveMeOne(String.class); - given(userAuthorityRepository.findByEmail(email)).willReturn(Optional.of(new UserAuthority(email))); + final User user = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(User.class); + given(userAuthorityRepository.findByEmail(email)).willReturn(Optional.of(UserAuthority.of(user, email))); //when - userAuthoritySaveService.saveUserAuthority(email); + userAuthoritySaveService.saveUserAuthority(user, email); //then then(userAuthorityRepository).should().findByEmail(email); then(userAuthorityRepository).shouldHaveNoMoreInteractions(); From a5a6e4c046210f154168c8bc711ab1cddbc8323b Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:56:38 +0900 Subject: [PATCH 14/27] =?UTF-8?q?PET-300=20refactor=20:=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EA=B0=80=EC=9E=85=20=EC=8B=9C=20UserAutho?= =?UTF-8?q?rity=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=EC=97=90=20User?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=20=EB=84=98=EA=B1=B0=EC=A3=BC=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/pawith/commonmodule/event/UserSignUpEvent.java | 3 +++ .../pawith/userapplication/handler/UserSignUpHandler.java | 5 ++--- .../userapplication/handler/UserSignUpHandlerTest.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Common-Module/src/main/java/com/pawith/commonmodule/event/UserSignUpEvent.java b/Common-Module/src/main/java/com/pawith/commonmodule/event/UserSignUpEvent.java index 1689f170..3d2eaca4 100644 --- a/Common-Module/src/main/java/com/pawith/commonmodule/event/UserSignUpEvent.java +++ b/Common-Module/src/main/java/com/pawith/commonmodule/event/UserSignUpEvent.java @@ -7,4 +7,7 @@ public record UserSignUpEvent( String email, Provider provider ) { + public static UserSignUpEvent of(String nickname, String email, Provider provider) { + return new UserSignUpEvent(nickname, email, provider); + } } diff --git a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/handler/UserSignUpHandler.java b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/handler/UserSignUpHandler.java index efa71201..80511f0e 100644 --- a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/handler/UserSignUpHandler.java +++ b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/handler/UserSignUpHandler.java @@ -29,9 +29,8 @@ public void signUp(final UserSignUpEvent userSignUpEvent){ if(!userQueryService.checkEmailAlreadyExist(userSignUpEvent.email())) { final User user = UserMapper.toUserEntity(userSignUpEvent,DEFAULT_PROFILE_IMAGE_URL); userSaveService.saveUser(user); - userAuthoritySaveService.saveUserAuthority(userSignUpEvent.email()); - } - else { + userAuthoritySaveService.saveUserAuthority(user, userSignUpEvent.email()); + } else { userQueryService.checkAccountAlreadyExist(userSignUpEvent.email(), userSignUpEvent.provider()); } } diff --git a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/handler/UserSignUpHandlerTest.java b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/handler/UserSignUpHandlerTest.java index f5cb2ffd..3a7aeb8e 100644 --- a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/handler/UserSignUpHandlerTest.java +++ b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/handler/UserSignUpHandlerTest.java @@ -47,7 +47,7 @@ void userSignUp() { userSignUpHandler.signUp(mockUserSignUpEvent); //then then(userSaveService).should(times(1)).saveUser(any()); - then(userAuthoritySaveService).should(times(1)).saveUserAuthority(any()); + then(userAuthoritySaveService).should(times(1)).saveUserAuthority(any(),any()); } @Test From e9dde69f714f9f20ed8509151f09d587777d91d9 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:57:29 +0900 Subject: [PATCH 15/27] =?UTF-8?q?PET-300=20refactor=20:=20=EC=B2=AB=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=8B=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=A1=B0=ED=9A=8C=EC=97=90=EC=84=9C=20userId?= =?UTF-8?q?=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userapplication/service/UserNicknameChangeUseCase.java | 2 +- .../userapplication/service/UserNicknameChangeUseCaseTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserNicknameChangeUseCase.java b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserNicknameChangeUseCase.java index 16ad516f..8d3d0eb1 100644 --- a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserNicknameChangeUseCase.java +++ b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserNicknameChangeUseCase.java @@ -20,7 +20,7 @@ public class UserNicknameChangeUseCase { public void changeUserName(final UserNicknameChangeRequest request){ final User user = userUtils.getAccessUser(); user.updateNickname(request.getNickname()); - final UserAuthority userAuthority = userAuthorityQueryService.findByEmail(user.getEmail()); + final UserAuthority userAuthority = userAuthorityQueryService.findByUserId(user.getId()); userAuthority.changeUserAuthority(); } } diff --git a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserNicknameChangeUseCaseTest.java b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserNicknameChangeUseCaseTest.java index 05c7caef..97d75a5c 100644 --- a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserNicknameChangeUseCaseTest.java +++ b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserNicknameChangeUseCaseTest.java @@ -47,7 +47,7 @@ void changeUserName() { .set("authority", Authority.GUEST) .sample(); given(userUtils.getAccessUser()).willReturn(mockUser); - given(userAuthorityQueryService.findByEmail(mockUser.getEmail())).willReturn(mockUserAuthority); + given(userAuthorityQueryService.findByUserId(mockUser.getId())).willReturn(mockUserAuthority); //when userNicknameChangeUseCase.changeUserName(mockRequest); //then From 6701e9f9edf9d4335fb9af1710a632a1914fbf46 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:58:13 +0900 Subject: [PATCH 16/27] =?UTF-8?q?PET-300=20refactor=20:=20oauth=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/{command => oauth}/feign/response/TokenInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/{command => oauth}/feign/response/TokenInfo.java (82%) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/TokenInfo.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/TokenInfo.java similarity index 82% rename from Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/TokenInfo.java rename to Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/TokenInfo.java index 10b334ab..122643fd 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/feign/response/TokenInfo.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/feign/response/TokenInfo.java @@ -1,4 +1,4 @@ -package com.pawith.authapplication.service.command.feign.response; +package com.pawith.authapplication.service.oauth.feign.response; import com.fasterxml.jackson.annotation.JsonAlias; import lombok.AccessLevel; From 1d91e2c8ef961ae72e61440fc24e53772cb8aa78 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 14:59:03 +0900 Subject: [PATCH 17/27] =?UTF-8?q?PET-300=20refactor=20:=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EC=9E=AC=20=EB=B0=9C=EA=B8=89=EC=8B=9C=20email=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=EC=9D=B4=20=EC=95=84=EB=8B=8C=20PrivateClaim?= =?UTF-8?q?s=EA=B8=B0=EB=B0=98=20=EC=83=9D=EC=84=B1=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ReissueUseCaseImpl.java | 18 ++++++++++-------- .../service/ReissueUseCaseImplTest.java | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/ReissueUseCaseImpl.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/ReissueUseCaseImpl.java index fb6054be..f738a56c 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/ReissueUseCaseImpl.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/ReissueUseCaseImpl.java @@ -5,6 +5,7 @@ import com.pawith.authapplication.service.ReissueUseCase; import com.pawith.authapplication.utils.TokenExtractUtils; import com.pawith.authdomain.jwt.JWTProvider; +import com.pawith.authdomain.jwt.PrivateClaims; import com.pawith.authdomain.jwt.TokenType; import com.pawith.authdomain.service.TokenDeleteService; import com.pawith.authdomain.service.TokenLockService; @@ -30,21 +31,22 @@ public class ReissueUseCaseImpl implements ReissueUseCase { public TokenReissueResponse reissue(String refreshTokenHeader) { final String refreshToken = TokenExtractUtils.extractToken(refreshTokenHeader); jwtProvider.validateToken(refreshToken, TokenType.REFRESH_TOKEN); - final String userEmail = jwtProvider.extractEmailFromToken(refreshToken, TokenType.REFRESH_TOKEN); - return reissueToken(refreshToken, userEmail); + final PrivateClaims.UserClaims userClaims = jwtProvider.extractUserClaimsFromToken(refreshToken, TokenType.REFRESH_TOKEN); + return reissueToken(refreshToken, userClaims); } - private TokenReissueResponse reissueToken(final String refreshToken,final String userEmail) { + private TokenReissueResponse reissueToken(final String refreshToken,final PrivateClaims.UserClaims userClaims) { + final String lockKey = userClaims.toString(); try { - tokenLockService.lockToken(userEmail); + tokenLockService.lockToken(lockKey); if (jwtProvider.existsCachedRefreshToken(refreshToken)) { return generateToken(jwtProvider::getCachedToken, refreshToken); } tokenValidateService.validateIsExistToken(refreshToken, TokenType.REFRESH_TOKEN); tokenDeleteService.deleteTokenByValue(refreshToken); - return generateAndSaveToken(jwtProvider::reIssueToken, refreshToken, userEmail); + return generateAndSaveToken(jwtProvider::reIssueToken, refreshToken, userClaims.getUserId()); } finally { - tokenLockService.releaseLockToken(userEmail); + tokenLockService.releaseLockToken(lockKey); } } @@ -54,9 +56,9 @@ private TokenReissueResponse generateToken(final Function tokenGenerator,final String refreshToken,final String userEmail) { + private TokenReissueResponse generateAndSaveToken(final Function tokenGenerator,final String refreshToken,final Long userId) { final JWTProvider.Token token = tokenGenerator.apply(refreshToken); - tokenSaveService.saveToken(token.refreshToken(), userEmail, TokenType.REFRESH_TOKEN); + tokenSaveService.saveToken(token.refreshToken(), TokenType.REFRESH_TOKEN, userId); return generateToken(inputRefreshToken -> token, refreshToken); } diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/ReissueUseCaseImplTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/ReissueUseCaseImplTest.java index ac491f74..65cec285 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/ReissueUseCaseImplTest.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/ReissueUseCaseImplTest.java @@ -4,6 +4,7 @@ import com.pawith.authapplication.dto.TokenReissueResponse; import com.pawith.authapplication.service.impl.ReissueUseCaseImpl; import com.pawith.authdomain.jwt.JWTProvider; +import com.pawith.authdomain.jwt.PrivateClaims; import com.pawith.authdomain.jwt.TokenType; import com.pawith.authdomain.service.TokenDeleteService; import com.pawith.authdomain.service.TokenLockService; @@ -50,11 +51,11 @@ void setUp() { void reissue() { // given final String refreshToken = FixtureMonkeyUtils.getJavaTypeBasedFixtureMonkey().giveMeOne(String.class); - final String email = FixtureMonkeyUtils.getJavaTypeBasedFixtureMonkey().giveMeOne(String.class); + final PrivateClaims.UserClaims userClaims = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(PrivateClaims.UserClaims.class); final JWTProvider.Token token = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(JWTProvider.Token.class); given(jwtProvider.existsCachedRefreshToken(refreshToken)).willReturn(false); given(jwtProvider.reIssueToken(refreshToken)).willReturn(token); - given(jwtProvider.extractEmailFromToken(refreshToken, TokenType.REFRESH_TOKEN)).willReturn(email); + given(jwtProvider.extractUserClaimsFromToken(refreshToken, TokenType.REFRESH_TOKEN)).willReturn(userClaims); // when TokenReissueResponse reissue = reissueUseCase.reissue(AuthConsts.AUTHENTICATION_TYPE_PREFIX + refreshToken); // then @@ -62,9 +63,9 @@ void reissue() { Assertions.assertThat(reissue.getRefreshToken()).isEqualTo(AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.refreshToken()); then(tokenValidateService).should().validateIsExistToken(refreshToken, TokenType.REFRESH_TOKEN); then(tokenDeleteService).should().deleteTokenByValue(refreshToken); - then(tokenSaveService).should().saveToken(token.refreshToken(), email, TokenType.REFRESH_TOKEN); - then(tokenLockService).should().lockToken(email); - then(tokenLockService).should().releaseLockToken(email); + then(tokenSaveService).should().saveToken(token.refreshToken(), TokenType.REFRESH_TOKEN, userClaims.getUserId()); + then(tokenLockService).should().lockToken(userClaims.toString()); + then(tokenLockService).should().releaseLockToken(userClaims.toString()); } @Test @@ -72,11 +73,11 @@ void reissue() { void reissue2() { // given final String refreshToken = FixtureMonkeyUtils.getJavaTypeBasedFixtureMonkey().giveMeOne(String.class); - final String email = FixtureMonkeyUtils.getJavaTypeBasedFixtureMonkey().giveMeOne(String.class); + final PrivateClaims.UserClaims userClaims = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(PrivateClaims.UserClaims.class); final JWTProvider.Token token = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(JWTProvider.Token.class); given(jwtProvider.existsCachedRefreshToken(refreshToken)).willReturn(true); given(jwtProvider.getCachedToken(refreshToken)).willReturn(token); - given(jwtProvider.extractEmailFromToken(refreshToken, TokenType.REFRESH_TOKEN)).willReturn(email); + given(jwtProvider.extractUserClaimsFromToken(refreshToken, TokenType.REFRESH_TOKEN)).willReturn(userClaims); // when TokenReissueResponse reissue = reissueUseCase.reissue(AuthConsts.AUTHENTICATION_TYPE_PREFIX + refreshToken); // then @@ -85,8 +86,8 @@ void reissue2() { then(tokenValidateService).shouldHaveNoInteractions(); then(tokenDeleteService).shouldHaveNoInteractions(); then(tokenSaveService).shouldHaveNoInteractions(); - then(tokenLockService).should().lockToken(email); - then(tokenLockService).should().releaseLockToken(email); + then(tokenLockService).should().lockToken(userClaims.toString()); + then(tokenLockService).should().releaseLockToken(userClaims.toString()); } } \ No newline at end of file From 2a202ced6bbe1b593bd5d9f631822abcd0182fe2 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:01:50 +0900 Subject: [PATCH 18/27] =?UTF-8?q?PET-300=20refactor=20:=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20refreshToken?= =?UTF-8?q?=EB=8F=84=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/pawith/authapplication/dto/OAuthRequest.java | 3 ++- .../com/pawith/authapplication/service/OAuthUseCase.java | 2 +- .../authapplication/service/impl/OAuthUseCaseImpl.java | 6 +++--- .../authapplication/service/OAuthUseCaseImplTest.java | 7 ++++--- .../java/com/pawith/authpresentation/OAuthController.java | 6 ++++-- .../com/pawith/authpresentation/OAuthControllerTest.java | 8 +++++--- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthRequest.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthRequest.java index e265554c..197f38aa 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthRequest.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthRequest.java @@ -1,9 +1,9 @@ package com.pawith.authapplication.dto; +import com.pawith.commonmodule.enums.Provider; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; -import com.pawith.commonmodule.enums.Provider; import lombok.NoArgsConstructor; @Getter @@ -12,4 +12,5 @@ public class OAuthRequest { private Provider provider; private String accessToken; + private String refreshToken; // nullable } diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/OAuthUseCase.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/OAuthUseCase.java index 513dd615..b33ca80f 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/OAuthUseCase.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/OAuthUseCase.java @@ -5,6 +5,6 @@ public interface OAuthUseCase { - OAuthResponse oAuthLogin(Provider provider, String accessToken); + OAuthResponse oAuthLogin(Provider provider, String accessToken, String refreshToken); } diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/OAuthUseCaseImpl.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/OAuthUseCaseImpl.java index 72e1a427..4deb62b1 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/OAuthUseCaseImpl.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/impl/OAuthUseCaseImpl.java @@ -3,7 +3,7 @@ import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthResponse; import com.pawith.authapplication.service.OAuthUseCase; -import com.pawith.authapplication.service.command.OAuthInvoker; +import com.pawith.authapplication.service.oauth.OAuthInvoker; import com.pawith.commonmodule.annotation.ApplicationService; import com.pawith.commonmodule.enums.Provider; import lombok.RequiredArgsConstructor; @@ -15,7 +15,7 @@ public class OAuthUseCaseImpl implements OAuthUseCase { private final OAuthInvoker oAuthInvoker; @Override - public OAuthResponse oAuthLogin(Provider provider, String accessToken){ - return oAuthInvoker.execute(new OAuthRequest(provider, accessToken)); + public OAuthResponse oAuthLogin(Provider provider, String accessToken, String refreshToken){ + return oAuthInvoker.execute(new OAuthRequest(provider, accessToken, refreshToken)); } } diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/OAuthUseCaseImplTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/OAuthUseCaseImplTest.java index f26457b1..520abc56 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/OAuthUseCaseImplTest.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/OAuthUseCaseImplTest.java @@ -2,7 +2,7 @@ import com.navercorp.fixturemonkey.FixtureMonkey; import com.pawith.commonmodule.enums.Provider; -import com.pawith.authapplication.service.command.OAuthInvoker; +import com.pawith.authapplication.service.oauth.OAuthInvoker; import com.pawith.authapplication.service.impl.OAuthUseCaseImpl; import com.pawith.commonmodule.UnitTestConfig; import org.junit.jupiter.api.BeforeEach; @@ -30,9 +30,10 @@ public class OAuthUseCaseImplTest { void oAuthLogin() { //given final Provider testProvider = FixtureMonkey.create().giveMeOne(Provider.class); - final String token = FixtureMonkey.create().giveMeOne(String.class); + final String accessToken = FixtureMonkey.create().giveMeOne(String.class); + final String refreshToken = FixtureMonkey.create().giveMeOne(String.class); //when - oAuthUseCaseImpl.oAuthLogin(testProvider, token); + oAuthUseCaseImpl.oAuthLogin(testProvider, accessToken, refreshToken); //then then(oAuthInvoker).should(times(1)).execute(any()); } diff --git a/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/OAuthController.java b/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/OAuthController.java index 1f85a4e5..6ef5def0 100644 --- a/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/OAuthController.java +++ b/Domain-Module/Auth-Module/Auth-Presentation/src/main/java/com/pawith/authpresentation/OAuthController.java @@ -21,8 +21,10 @@ public class OAuthController { private final ReissueUseCase reissueUseCase; @GetMapping("/oauth/{provider}") - public OAuthResponse oAuthLogin(@PathVariable Provider provider, @RequestHeader("Authorization") String accessToken){ - return oAuthUseCase.oAuthLogin(provider, accessToken); + public OAuthResponse oAuthLogin(@PathVariable Provider provider, + @RequestHeader("Authorization") String accessToken, + @RequestHeader(value = "RefreshToken", required = false) String refreshToken){ + return oAuthUseCase.oAuthLogin(provider, accessToken, refreshToken); } @PostMapping("/reissue") diff --git a/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/OAuthControllerTest.java b/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/OAuthControllerTest.java index 381f1576..458af7c0 100644 --- a/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/OAuthControllerTest.java +++ b/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/OAuthControllerTest.java @@ -51,11 +51,13 @@ class OAuthControllerTest extends BaseRestDocsTest { void oAuthLogin() throws Exception { //given final Provider testProvider = FixtureMonkey.create().giveMeOne(Provider.class); - final String OAUTH_ACCESS_TOKEN = FixtureMonkey.create().giveMeOne(String.class); + final String accessToken = FixtureMonkey.create().giveMeOne(String.class); + final String refreshToken = FixtureMonkey.create().giveMeOne(String.class); final OAuthResponse testOAuthResponse = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(OAuthResponse.class); MockHttpServletRequestBuilder request = get(OAUTH_URL, testProvider) - .header(OAUTH_REQUEST_ACCESS_TOKEN_PARAM_NAME, OAUTH_ACCESS_TOKEN); - given(oAuthUseCase.oAuthLogin(testProvider, OAUTH_ACCESS_TOKEN)).willReturn(testOAuthResponse); + .header(OAUTH_REQUEST_ACCESS_TOKEN_PARAM_NAME, accessToken) + .header("RefreshToken", refreshToken); + given(oAuthUseCase.oAuthLogin(testProvider, accessToken, refreshToken)).willReturn(testOAuthResponse); //when ResultActions result = mvc.perform(request); //then From 789546346c99aa4e1537bd3899ad06e634be85b6 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:02:47 +0900 Subject: [PATCH 19/27] =?UTF-8?q?PET-300=20fix=20:=20=EC=86=8C=EC=85=9C?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=97=90=EC=84=9C=20sub=EA=B0=92=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20=EC=9E=84=EC=8B=9C=EB=A1=9C=20null=20?= =?UTF-8?q?=EA=B0=92=20=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/pawith/authapplication/dto/OAuthUserInfo.java | 3 ++- .../authapplication/service/oauth/impl/AppleOAuthHandler.java | 4 ++-- .../service/oauth/impl/GoogleOAuthHandler.java | 4 ++-- .../authapplication/service/oauth/impl/KakaoOAuthHandler.java | 4 ++-- .../authapplication/service/oauth/impl/NaverOAuthHandler.java | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthUserInfo.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthUserInfo.java index 2b398e90..509d81f1 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthUserInfo.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/dto/OAuthUserInfo.java @@ -7,5 +7,6 @@ @RequiredArgsConstructor public class OAuthUserInfo { private final String username; - private final String email; + private final String email; // email -> sub, 사용자 식별 정보를 email에서 sub로 변경 + private final String sub; } diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java index 4b4e07a2..f4e086bc 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/AppleOAuthHandler.java @@ -2,9 +2,9 @@ import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; +import com.pawith.authapplication.service.oauth.AuthHandler; import com.pawith.authapplication.service.oauth.feign.AppleFeignClient; import com.pawith.authapplication.service.oauth.feign.response.Keys; -import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.authdomain.exception.AuthError; import com.pawith.authdomain.jwt.exception.InvalidTokenException; import com.pawith.commonmodule.enums.Provider; @@ -43,7 +43,7 @@ public OAuthUserInfo handle(OAuthRequest authenticationInfo) { Jws oidcTokenJws = sigVerificationAndGetJws(authenticationInfo.getAccessToken()); // 토큰 바디 파싱해서 사용자 정보 획득 String email = (String) oidcTokenJws.getBody().get(APPLE_USER_INFO); - return new OAuthUserInfo("포잇", email); + return new OAuthUserInfo("포잇", email, null); } @Override diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java index fffd5208..8c67e04c 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/GoogleOAuthHandler.java @@ -2,9 +2,9 @@ import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; +import com.pawith.authapplication.service.oauth.AuthHandler; import com.pawith.authapplication.service.oauth.feign.GoogleOAuthFeignClient; import com.pawith.authapplication.service.oauth.feign.response.GoogleUserInfo; -import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.commonmodule.enums.Provider; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -21,7 +21,7 @@ public class GoogleOAuthHandler implements AuthHandler { public OAuthUserInfo handle(OAuthRequest authenticationInfo) { final String accessToken = authenticationInfo.getAccessToken(); final GoogleUserInfo googleUserInfo = getGoogleUserInfo(accessToken); - return new OAuthUserInfo(googleUserInfo.getName(), googleUserInfo.getEmail()); + return new OAuthUserInfo(googleUserInfo.getName(), googleUserInfo.getEmail(), null); } @Override diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java index b923a5ab..25b7aaf0 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/KakaoOAuthHandler.java @@ -2,10 +2,10 @@ import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; +import com.pawith.authapplication.service.oauth.AuthHandler; import com.pawith.authapplication.service.oauth.feign.KakaoOAuthFeignClient; import com.pawith.authapplication.service.oauth.feign.response.KakaoUserInfo; import com.pawith.authapplication.service.oauth.feign.response.TokenInfo; -import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.authdomain.exception.AuthError; import com.pawith.authdomain.jwt.exception.InvalidTokenException; import com.pawith.commonmodule.enums.Provider; @@ -29,7 +29,7 @@ public OAuthUserInfo handle(OAuthRequest authenticationInfo) { if (!tokenInfo.getAppId().equals(appId)) throw new InvalidTokenException(AuthError.INVALID_TOKEN); final KakaoUserInfo kakaoUserInfo = getKaKaoUserInfo(authenticationInfo.getAccessToken()); - return new OAuthUserInfo(kakaoUserInfo.getNickname(), kakaoUserInfo.getEmail()); + return new OAuthUserInfo(kakaoUserInfo.getNickname(), kakaoUserInfo.getEmail(), null); } @Override diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java index 0324f2e4..27f75d72 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/impl/NaverOAuthHandler.java @@ -2,9 +2,9 @@ import com.pawith.authapplication.dto.OAuthRequest; import com.pawith.authapplication.dto.OAuthUserInfo; +import com.pawith.authapplication.service.oauth.AuthHandler; import com.pawith.authapplication.service.oauth.feign.NaverOAuthFeignClient; import com.pawith.authapplication.service.oauth.feign.response.NaverUserInfo; -import com.pawith.authapplication.service.command.handler.AuthHandler; import com.pawith.commonmodule.enums.Provider; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -20,7 +20,7 @@ public class NaverOAuthHandler implements AuthHandler { @Override public OAuthUserInfo handle(OAuthRequest authenticationInfo) { final NaverUserInfo naverUserInfo = getNaverUserInfo(authenticationInfo.getAccessToken()); - return new OAuthUserInfo(naverUserInfo.getNickname(), naverUserInfo.getEmail()); + return new OAuthUserInfo(naverUserInfo.getNickname(), naverUserInfo.getEmail(), null); } @Override From ecbc44b2d2ef12e6ec0b0583893aab351022b2ff Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:03:37 +0900 Subject: [PATCH 20/27] =?UTF-8?q?PET-300=20test=20:=20Jwt=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=ED=95=84=ED=84=B0=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pawith/authpresentation/common/FilterConfig.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/common/FilterConfig.java b/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/common/FilterConfig.java index 3759b7f2..8f8f4c30 100644 --- a/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/common/FilterConfig.java +++ b/Domain-Module/Auth-Module/Auth-Presentation/src/test/java/com/pawith/authpresentation/common/FilterConfig.java @@ -1,6 +1,6 @@ package com.pawith.authpresentation.common; -import com.pawith.authapplication.service.JWTExtractEmailUseCase; +import com.pawith.authapplication.service.JWTExtractUserDetailsUseCase; import com.pawith.authapplication.service.JWTExtractTokenUseCase; import com.pawith.authapplication.service.JWTVerifyUseCase; import org.springframework.boot.test.context.TestConfiguration; @@ -17,8 +17,8 @@ public JWTVerifyUseCase jwtVerifyUseCase(){ } @Bean - public JWTExtractEmailUseCase jwtExtractEmailUseCase(){ - return mock(JWTExtractEmailUseCase.class); + public JWTExtractUserDetailsUseCase jwtExtractEmailUseCase(){ + return mock(JWTExtractUserDetailsUseCase.class); } @Bean From acade8d0454ab017f2c5675a035e1ebc88d00085 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:03:53 +0900 Subject: [PATCH 21/27] =?UTF-8?q?PET-300=20test=20:=20Jwt=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JWTExtractEmailUseCaseImplTest.java | 41 ------------------ .../JWTExtractUserDetailsUseCaseImplTest.java | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 41 deletions(-) delete mode 100644 Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractEmailUseCaseImplTest.java create mode 100644 Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCaseImplTest.java diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractEmailUseCaseImplTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractEmailUseCaseImplTest.java deleted file mode 100644 index b5a664a5..00000000 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractEmailUseCaseImplTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.pawith.authapplication.service; - -import com.navercorp.fixturemonkey.FixtureMonkey; -import com.pawith.authapplication.service.impl.JWTExtractEmailUseCaseImpl; -import com.pawith.authdomain.jwt.TokenType; -import com.pawith.commonmodule.UnitTestConfig; -import com.pawith.authdomain.jwt.JWTProvider; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -@UnitTestConfig -@DisplayName("JWTExtractEmailService 테스트") -public class JWTExtractEmailUseCaseImplTest { - - @Mock - private JWTProvider jwtProvider; - JWTExtractEmailUseCaseImpl jwtExtractEmailUseCaseImpl; - - @BeforeEach - void init() { jwtExtractEmailUseCaseImpl = new JWTExtractEmailUseCaseImpl(jwtProvider); } - - @Test - @DisplayName("accessToken에서 email을 추출한다.") - void extractEmail(){ - //given - final String randomEmail = FixtureMonkey.create().giveMe(String.class).findFirst().get(); - final String accessToken = jwtProvider.generateAccessToken(randomEmail); - given(jwtProvider.extractEmailFromToken(accessToken, TokenType.ACCESS_TOKEN)).willReturn(randomEmail); - //when - final String email = jwtExtractEmailUseCaseImpl.extractEmail(accessToken); - //then - verify(jwtProvider).extractEmailFromToken(accessToken, TokenType.ACCESS_TOKEN); - assertEquals(email, randomEmail); - } -} diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCaseImplTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCaseImplTest.java new file mode 100644 index 00000000..f2cddaa0 --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/JWTExtractUserDetailsUseCaseImplTest.java @@ -0,0 +1,42 @@ +package com.pawith.authapplication.service; + +import com.pawith.authapplication.service.impl.JWTExtractUserDetailsUseCaseImpl; +import com.pawith.authdomain.jwt.JWTProvider; +import com.pawith.authdomain.jwt.PrivateClaims; +import com.pawith.authdomain.jwt.TokenType; +import com.pawith.commonmodule.UnitTestConfig; +import com.pawith.commonmodule.utils.FixtureMonkeyUtils; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; + +@UnitTestConfig +@DisplayName("JWTExtractEmailService 테스트") +public class JWTExtractUserDetailsUseCaseImplTest { + + @Mock + private JWTProvider jwtProvider; + JWTExtractUserDetailsUseCaseImpl jwtExtractEmailUseCaseImpl; + + @BeforeEach + void init() { jwtExtractEmailUseCaseImpl = new JWTExtractUserDetailsUseCaseImpl(jwtProvider); } + + @Test + @DisplayName("accessToken에서 사용자 정보를 추출한다.") + void extractEmail(){ + //given + final PrivateClaims.UserClaims userClaims = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(PrivateClaims.UserClaims.class); + final String accessToken = jwtProvider.generateAccessToken(userClaims); + given(jwtProvider.extractUserClaimsFromToken(accessToken, TokenType.ACCESS_TOKEN)).willReturn(userClaims); + //when + final Long userId = jwtExtractEmailUseCaseImpl.extract(accessToken); + //then + verify(jwtProvider).extractUserClaimsFromToken(accessToken, TokenType.ACCESS_TOKEN); + Assertions.assertThat(userId).isEqualTo(userClaims.getUserId()); + } +} From d1dec0cfe75deac46bebfc91d529c0efe5369c0a Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:06:32 +0900 Subject: [PATCH 22/27] =?UTF-8?q?PET-300=20refactor=20:=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=EC=B2=98=EB=A6=AC=20=EC=A0=84=EB=9E=B5=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20=ED=9B=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/command/OAuthInvoker.java | 57 ------------ .../service/oauth/OAuthInvoker.java | 92 +++++++++++++++++++ .../service/command/OAuthInvokerTest.java | 72 --------------- .../service/oauth/OAuthInvokerTest.java | 71 ++++++++++++++ 4 files changed, 163 insertions(+), 129 deletions(-) delete mode 100644 Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/OAuthInvoker.java create mode 100644 Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java delete mode 100644 Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/OAuthInvokerTest.java create mode 100644 Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/OAuthInvokerTest.java diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/OAuthInvoker.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/OAuthInvoker.java deleted file mode 100644 index 4c2c5c83..00000000 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/command/OAuthInvoker.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.pawith.authapplication.service.command; - -import com.pawith.authapplication.consts.AuthConsts; -import com.pawith.authapplication.dto.OAuthRequest; -import com.pawith.authapplication.dto.OAuthResponse; -import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.exception.AuthException; -import com.pawith.authapplication.service.command.handler.AuthHandler; -import com.pawith.authdomain.exception.AuthError; -import com.pawith.authdomain.jwt.JWTProvider; -import com.pawith.authdomain.jwt.TokenType; -import com.pawith.authdomain.service.TokenSaveService; -import com.pawith.commonmodule.event.UserSignUpEvent; -import lombok.RequiredArgsConstructor; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -@RequiredArgsConstructor -public class OAuthInvoker { - private final List authHandlerList; - private final JWTProvider jwtProvider; - private final TokenSaveService tokenSaveService; - private final ApplicationEventPublisher publisher; - public OAuthResponse execute(OAuthRequest request){ - OAuthUserInfo oAuthUserInfo = attemptLogin(request); - publishEvent(request, oAuthUserInfo); - return generateServerAuthenticationTokens(oAuthUserInfo); - } - - private void publishEvent(OAuthRequest request, OAuthUserInfo oAuthUserInfo) { - publisher.publishEvent(new UserSignUpEvent(oAuthUserInfo.getUsername(), oAuthUserInfo.getEmail(), request.getProvider())); -// publisher.publishEvent(new UnusedTokenExpireEvent(oAuthUserInfo.getEmail(), TokenType.REFRESH_TOKEN)); - } - - private OAuthUserInfo attemptLogin(OAuthRequest request) { - for (AuthHandler authHandler : authHandlerList) { - if (authHandler.isAccessible(request)) { - return authHandler.handle(request); - } - } - throw new AuthException(AuthError.OAUTH_FAIL); - } - - private OAuthResponse generateServerAuthenticationTokens(OAuthUserInfo oAuthUserInfo) { - final JWTProvider.Token token = jwtProvider.generateToken(oAuthUserInfo.getEmail()); - tokenSaveService.saveToken(token.refreshToken(), oAuthUserInfo.getEmail(), TokenType.REFRESH_TOKEN); - final String accessToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.accessToken(); - final String refreshToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.refreshToken(); - return OAuthResponse.builder() - .accessToken(accessToken) - .refreshToken(refreshToken) - .build(); - } -} diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java new file mode 100644 index 00000000..2588a4bc --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java @@ -0,0 +1,92 @@ +package com.pawith.authapplication.service.oauth; + +import com.pawith.authapplication.consts.AuthConsts; +import com.pawith.authapplication.dto.OAuthRequest; +import com.pawith.authapplication.dto.OAuthResponse; +import com.pawith.authapplication.dto.OAuthUserInfo; +import com.pawith.authapplication.exception.AuthException; +import com.pawith.authdomain.exception.AuthError; +import com.pawith.authdomain.jwt.JWTProvider; +import com.pawith.authdomain.jwt.PrivateClaims; +import com.pawith.authdomain.jwt.TokenType; +import com.pawith.authdomain.service.OAuthModifyingService; +import com.pawith.authdomain.service.OAuthQueryService; +import com.pawith.authdomain.service.OAuthSaveService; +import com.pawith.authdomain.service.TokenSaveService; +import com.pawith.userdomain.service.UserQueryService; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; +import org.springframework.transaction.support.TransactionTemplate; + +import java.util.List; + +@Component +@RequiredArgsConstructor +public class OAuthInvoker { + private final List authHandlerList; + private final JWTProvider jwtProvider; + private final TokenSaveService tokenSaveService; + private final ApplicationEventPublisher publisher; + private final OAuthModifyingService oAuthModifyingService; + private final OAuthQueryService oAuthQueryService; + private final OAuthSaveService oAuthSaveService; + private final UserQueryService userQueryService; + private final TransactionTemplate transactionTemplate; + + public OAuthResponse execute(OAuthRequest request){ + // oauth 정보가 없으면 생성 + // 생성하고 조회, email이 없어도 될지, user에서 email, provider는 제거 + // oauth에는 userId를 넣는다? + // 있으면 그대로 진행 + final OAuthUserInfo oAuthUserInfo = attemptLogin(request); + saveOAuthAndPublishEvent(request, oAuthUserInfo); + return generateServerAuthenticationTokens(PrivateClaims.UserClaims.of(userQueryService.findByEmail(oAuthUserInfo.getEmail()).getId())); + } + + private void saveOAuthAndPublishEvent(OAuthRequest request, OAuthUserInfo oAuthUserInfo) { + transactionTemplate.execute(status -> { + /** + * OAuth 정보가 이미 존재하면, OAuth 정보를 조회하고 이메일 정보가 변경되면 UserEmailUpdateEvent를 발행한다. + * OAuth 존재하지 않으면 새로운 OAuth 정보를 생성한다. 이후에 UserSignUpEvent를 발행하여 사용자의 가입을 알린다. + */ +// if(oAuthQueryService.isOAuthExist(oAuthUserInfo.getSub())){ +// final OAuth oAuth = oAuthQueryService.findBySub(oAuthUserInfo.getSub()); +// oAuthModifyingService. +// } else{ +// publisher.publishEvent(UserSignUpEvent.of(oAuthUserInfo.getUsername(), oAuthUserInfo.getEmail(), request.getProvider())); +// oAuthSaveService.saveOAuthUser( +// OAuth.of( +// request.getProvider(), +// request.getRefreshToken(), +// oAuthUserInfo.getEmail(), +// oAuthUserInfo.getSub(), +// userQueryService.findByEmail(oAuthUserInfo.getEmail()).getId() +// ) +// ); +// } +// return null; + return null; + }); + } + + private OAuthUserInfo attemptLogin(OAuthRequest request) { + for (AuthHandler authHandler : authHandlerList) { + if (authHandler.isAccessible(request)) { + return authHandler.handle(request); + } + } + throw new AuthException(AuthError.OAUTH_FAIL); + } + + private OAuthResponse generateServerAuthenticationTokens(PrivateClaims.UserClaims userClaims) { + final JWTProvider.Token token = jwtProvider.generateToken(userClaims); + tokenSaveService.saveToken(token.refreshToken(), TokenType.REFRESH_TOKEN, userClaims.getUserId()); + final String accessToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.accessToken(); + final String refreshToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.refreshToken(); + return OAuthResponse.builder() + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } +} diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/OAuthInvokerTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/OAuthInvokerTest.java deleted file mode 100644 index 9c2d2b92..00000000 --- a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/command/OAuthInvokerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.pawith.authapplication.service.command; - -import com.pawith.authapplication.consts.AuthConsts; -import com.pawith.authapplication.dto.OAuthRequest; -import com.pawith.authapplication.dto.OAuthResponse; -import com.pawith.authapplication.dto.OAuthUserInfo; -import com.pawith.authapplication.service.command.handler.AuthHandler; -import com.pawith.authapplication.utils.TokenExtractUtils; -import com.pawith.authdomain.jwt.JWTProvider; -import com.pawith.authdomain.service.TokenSaveService; -import com.pawith.commonmodule.UnitTestConfig; -import com.pawith.commonmodule.utils.FixtureMonkeyUtils; -import lombok.extern.slf4j.Slf4j; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.Spy; -import org.springframework.context.ApplicationEventPublisher; - -import java.util.ArrayList; -import java.util.List; - -import static org.mockito.BDDMockito.given; - -@Slf4j -@UnitTestConfig -@DisplayName("OAuthInvoker 테스트") -class OAuthInvokerTest { - - @Mock - private JWTProvider jwtProvider; - @Mock - private ApplicationEventPublisher applicationEventPublisher; - @Mock - private TokenSaveService tokenSaveService; - @Spy - private List authHandlerList = new ArrayList<>(); - @Mock - private AuthHandler authHandler; - - private OAuthInvoker oAuthInvoker; - - @BeforeEach - void setUp() { - authHandlerList.add(authHandler); - oAuthInvoker=new OAuthInvoker(authHandlerList, jwtProvider, tokenSaveService,applicationEventPublisher); - } - - @Test - @DisplayName("execute 테스트") - void execute(){ - // given - final OAuthRequest mockRequest = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(OAuthRequest.class); - final OAuthUserInfo mockOAuthUserInfo = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(OAuthUserInfo.class); - final JWTProvider.Token mockToken = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(JWTProvider.Token.class); - given(authHandler.isAccessible(mockRequest)).willReturn(true); - given(authHandler.handle(mockRequest)).willReturn(mockOAuthUserInfo); - given(jwtProvider.generateToken(mockOAuthUserInfo.getEmail())).willReturn(mockToken); - // when - final OAuthResponse result = oAuthInvoker.execute(mockRequest); - // then - Assertions.assertThat(result.getAccessToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE); - Assertions.assertThat(result.getRefreshToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE); - Assertions.assertThat(result.getAccessToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE_PREFIX); - Assertions.assertThat(result.getRefreshToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE_PREFIX); - Assertions.assertThat(TokenExtractUtils.extractToken(result.getAccessToken())).isEqualTo(mockToken.accessToken()); - Assertions.assertThat(TokenExtractUtils.extractToken(result.getRefreshToken())).isEqualTo(mockToken.refreshToken()); - } - -} \ No newline at end of file diff --git a/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/OAuthInvokerTest.java b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/OAuthInvokerTest.java new file mode 100644 index 00000000..5ad429e1 --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Application/src/test/java/com/pawith/authapplication/service/oauth/OAuthInvokerTest.java @@ -0,0 +1,71 @@ +//package com.pawith.authapplication.service.oauth; +// +//import com.pawith.authapplication.consts.AuthConsts; +//import com.pawith.authapplication.dto.OAuthRequest; +//import com.pawith.authapplication.dto.OAuthResponse; +//import com.pawith.authapplication.dto.OAuthUserInfo; +//import com.pawith.authapplication.utils.TokenExtractUtils; +//import com.pawith.authdomain.jwt.JWTProvider; +//import com.pawith.authdomain.service.TokenSaveService; +//import com.pawith.commonmodule.UnitTestConfig; +//import com.pawith.commonmodule.utils.FixtureMonkeyUtils; +//import lombok.extern.slf4j.Slf4j; +//import org.assertj.core.api.Assertions; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.mockito.Mock; +//import org.mockito.Spy; +//import org.springframework.context.ApplicationEventPublisher; +// +//import java.util.ArrayList; +//import java.util.List; +// +//import static org.mockito.BDDMockito.given; +// +//@Slf4j +//@UnitTestConfig +//@DisplayName("OAuthInvoker 테스트") +//class OAuthInvokerTest { +// +// @Mock +// private JWTProvider jwtProvider; +// @Mock +// private ApplicationEventPublisher applicationEventPublisher; +// @Mock +// private TokenSaveService tokenSaveService; +// @Spy +// private List authHandlerList = new ArrayList<>(); +// @Mock +// private AuthHandler authHandler; +// +// private OAuthInvoker oAuthInvoker; +// +// @BeforeEach +// void setUp() { +// authHandlerList.add(authHandler); +// oAuthInvoker=new OAuthInvoker(authHandlerList, jwtProvider, tokenSaveService,applicationEventPublisher); +// } +// +// @Test +// @DisplayName("execute 테스트") +// void execute(){ +// // given +// final OAuthRequest mockRequest = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(OAuthRequest.class); +// final OAuthUserInfo mockOAuthUserInfo = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(OAuthUserInfo.class); +// final JWTProvider.Token mockToken = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(JWTProvider.Token.class); +// given(authHandler.isAccessible(mockRequest)).willReturn(true); +// given(authHandler.handle(mockRequest)).willReturn(mockOAuthUserInfo); +// given(jwtProvider.generateToken(mockOAuthUserInfo.getEmail())).willReturn(mockToken); +// // when +// final OAuthResponse result = oAuthInvoker.execute(mockRequest); +// // then +// Assertions.assertThat(result.getAccessToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE); +// Assertions.assertThat(result.getRefreshToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE); +// Assertions.assertThat(result.getAccessToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE_PREFIX); +// Assertions.assertThat(result.getRefreshToken()).startsWith(AuthConsts.AUTHENTICATION_TYPE_PREFIX); +// Assertions.assertThat(TokenExtractUtils.extractToken(result.getAccessToken())).isEqualTo(mockToken.accessToken()); +// Assertions.assertThat(TokenExtractUtils.extractToken(result.getRefreshToken())).isEqualTo(mockToken.refreshToken()); +// } +// +//} \ No newline at end of file From 800b11f73d49569615d58c56f16762a081886626 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:07:27 +0900 Subject: [PATCH 23/27] =?UTF-8?q?PET-300=20feat=20:=20=EC=86=8C=EC=85=9C?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pawith/authdomain/entity/OAuth.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/OAuth.java diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/OAuth.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/OAuth.java new file mode 100644 index 00000000..1efe5742 --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/entity/OAuth.java @@ -0,0 +1,45 @@ +package com.pawith.authdomain.entity; + +import com.pawith.commonmodule.enums.Provider; +import com.pawith.commonmodule.util.DomainFieldUtils; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class OAuth { + @Id@GeneratedValue(strategy = GenerationType.IDENTITY) + private Long authId; + @Enumerated(value = EnumType.STRING) + private Provider provider; + private String refreshToken; + private String email; + private String sub; + private Long userId; + + private OAuth(Provider provider, String refreshToken, String email, String sub, Long userId) { + this.provider = provider; + this.refreshToken = refreshToken; + this.email = email; + this.sub = sub; + this.userId = userId; + } + + public static OAuth of(Provider provider, String refreshToken, String email, String sub, Long userId){ + return new OAuth(provider, refreshToken, email, sub, userId); + } + + public void updateEmail(String email){ + this.email = DomainFieldUtils.DomainValidateBuilder.builder(String.class) + .newValue(email) + .currentValue(this.email) + .validate(); + } + + public boolean isEqualEmail(String email){ + return this.email.equals(email); + } +} From 1254ab0ee114abcf976b9eb18c2686b3c1226cd6 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:07:49 +0900 Subject: [PATCH 24/27] =?UTF-8?q?PET-300=20feat=20:=20OAuthRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authdomain/repository/OAuthRepository.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/OAuthRepository.java diff --git a/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/OAuthRepository.java b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/OAuthRepository.java new file mode 100644 index 00000000..6ad465ea --- /dev/null +++ b/Domain-Module/Auth-Module/Auth-Domain/src/main/java/com/pawith/authdomain/repository/OAuthRepository.java @@ -0,0 +1,13 @@ +package com.pawith.authdomain.repository; + + +import com.pawith.authdomain.entity.OAuth; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface OAuthRepository extends JpaRepository { + boolean existsBySub(String sub); + + Optional findBySub(String sub); +} From 90f73186f33b2a2ae80d5ff78dcd3e10015569d4 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:14:52 +0900 Subject: [PATCH 25/27] =?UTF-8?q?PET-300=20chore=20:=20Auth=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=EC=97=90=EC=84=9C=20User=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Domain-Module/Auth-Module/Auth-Application/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Domain-Module/Auth-Module/Auth-Application/build.gradle b/Domain-Module/Auth-Module/Auth-Application/build.gradle index 331ee452..fb629fc8 100644 --- a/Domain-Module/Auth-Module/Auth-Application/build.gradle +++ b/Domain-Module/Auth-Module/Auth-Application/build.gradle @@ -12,4 +12,7 @@ dependencies { // webclinet implementation 'org.springframework.boot:spring-boot-starter-webflux' + + // user + implementation project(':Domain-Module:User-Module:User-Domain') } \ No newline at end of file From 607e9133e96493ababe21c9e514f80fd689cf731 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:15:13 +0900 Subject: [PATCH 26/27] =?UTF-8?q?PET-300=20fix=20:=20=EB=AF=B8=EC=A0=95?= =?UTF-8?q?=EC=9D=98=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=A3=BC=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authapplication/service/oauth/OAuthInvoker.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java index 2588a4bc..7e1a5356 100644 --- a/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java +++ b/Domain-Module/Auth-Module/Auth-Application/src/main/java/com/pawith/authapplication/service/oauth/OAuthInvoker.java @@ -9,9 +9,6 @@ import com.pawith.authdomain.jwt.JWTProvider; import com.pawith.authdomain.jwt.PrivateClaims; import com.pawith.authdomain.jwt.TokenType; -import com.pawith.authdomain.service.OAuthModifyingService; -import com.pawith.authdomain.service.OAuthQueryService; -import com.pawith.authdomain.service.OAuthSaveService; import com.pawith.authdomain.service.TokenSaveService; import com.pawith.userdomain.service.UserQueryService; import lombok.RequiredArgsConstructor; @@ -28,9 +25,9 @@ public class OAuthInvoker { private final JWTProvider jwtProvider; private final TokenSaveService tokenSaveService; private final ApplicationEventPublisher publisher; - private final OAuthModifyingService oAuthModifyingService; - private final OAuthQueryService oAuthQueryService; - private final OAuthSaveService oAuthSaveService; +// private final OAuthModifyingService oAuthModifyingService; +// private final OAuthQueryService oAuthQueryService; +// private final OAuthSaveService oAuthSaveService; private final UserQueryService userQueryService; private final TransactionTemplate transactionTemplate; From 4d0f9f0f874932208633cf858a111c1a3bfde0b9 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:24:34 +0900 Subject: [PATCH 27/27] =?UTF-8?q?PET-300=20fix=20:=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=9D=84=20=EB=B3=B4=EB=82=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20static=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EB=A1=9C=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userapplication/service/UserAuthorityGetUseCase.java | 3 ++- .../service/UserAuthorityGetUseCaseTest.java | 9 ++++++--- .../main/java/com/pawith/userdomain/utils/UserUtils.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java index 38a31d2f..1d039255 100644 --- a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java +++ b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java @@ -12,9 +12,10 @@ public class UserAuthorityGetUseCase { private final UserAuthorityQueryService userAuthorityQueryService; + private final UserUtils userUtils; public UserAuthorityInfoResponse getUserAuthority() { - final Long userId = UserUtils.getIdFromAccessUser(); + final Long userId = userUtils.getIdFromAccessUser(); final UserAuthority userAuthority = userAuthorityQueryService.findByUserId(userId); return new UserAuthorityInfoResponse(userAuthority.getAuthority()); } diff --git a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java index 331330c5..6df3ef84 100644 --- a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java +++ b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java @@ -6,6 +6,7 @@ import com.pawith.userapplication.dto.response.UserAuthorityInfoResponse; import com.pawith.userdomain.entity.UserAuthority; import com.pawith.userdomain.service.UserAuthorityQueryService; +import com.pawith.userdomain.utils.UserUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -20,13 +21,14 @@ class UserAuthorityGetUseCaseTest { @Mock - UserAuthorityQueryService userAuthorityQueryService; + private UserAuthorityQueryService userAuthorityQueryService; + @Mock + private UserUtils userUtils; UserAuthorityGetUseCase userAuthorityGetUseCase; - @BeforeEach void init() { - userAuthorityGetUseCase = new UserAuthorityGetUseCase(userAuthorityQueryService); + userAuthorityGetUseCase = new UserAuthorityGetUseCase(userAuthorityQueryService, userUtils); } @Test @@ -37,6 +39,7 @@ void getUserAuthority() { final UserAuthority userAuthority = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey() .giveMeBuilder(UserAuthority.class) .sample(); + given(userUtils.getIdFromAccessUser()).willReturn(userAuthority.getUser().getId()); given(userAuthorityQueryService.findByUserId(anyLong())).willReturn(userAuthority); //when UserAuthorityInfoResponse result = userAuthorityGetUseCase.getUserAuthority(); diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java index 2015e2ee..8dd9bb20 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java @@ -19,7 +19,7 @@ public User getAccessUser(){ return userQueryService.findById(userId); } - public static Long getIdFromAccessUser(){ + public Long getIdFromAccessUser(){ return SecurityUtils.getAuthenticationPrincipal(); } }