-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
1,821 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.recordy.server.auth.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Builder | ||
@Getter | ||
public class Auth { | ||
|
||
private AuthPlatform platform; | ||
private AuthToken token; | ||
private boolean isSignedUp; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/recordy/server/auth/domain/AuthEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.recordy.server.auth.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@RedisHash("auth") | ||
public class AuthEntity { | ||
|
||
@Id | ||
private String platformId; | ||
private String platformType; | ||
private String accessToken; | ||
private String refreshToken; | ||
private boolean isSignedUp; | ||
|
||
public static AuthEntity from(Auth auth) { | ||
return new AuthEntity( | ||
auth.getPlatform().getId(), | ||
auth.getPlatform().getType().name(), | ||
auth.getToken().getAccessToken(), | ||
auth.getToken().getRefreshToken(), | ||
auth.isSignedUp() | ||
); | ||
} | ||
|
||
public Auth toDomain() { | ||
return new Auth( | ||
new AuthPlatform(platformId, AuthPlatform.Type.valueOf(platformType)), | ||
new AuthToken(accessToken, refreshToken), | ||
isSignedUp | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/recordy/server/auth/domain/AuthPlatform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.recordy.server.auth.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class AuthPlatform { | ||
|
||
private String id; | ||
private Type type; | ||
|
||
public enum Type { | ||
|
||
APPLE, | ||
KAKAO, | ||
; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/recordy/server/auth/domain/AuthToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.recordy.server.auth.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class AuthToken { | ||
|
||
private String accessToken; | ||
private String refreshToken; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/recordy/server/auth/domain/usecase/AuthSignIn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.recordy.server.auth.domain.usecase; | ||
|
||
import org.recordy.server.auth.domain.AuthPlatform; | ||
|
||
public record AuthSignIn( | ||
String platformToken, | ||
AuthPlatform.Type platformType | ||
) { | ||
|
||
public static AuthSignIn of(String platformToken, AuthPlatform.Type platformType) { | ||
return new AuthSignIn(platformToken, platformType); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/recordy/server/auth/repository/AuthRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.recordy.server.auth.repository; | ||
|
||
import org.recordy.server.auth.domain.Auth; | ||
|
||
public interface AuthRepository { | ||
|
||
Auth save(Auth auth); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/recordy/server/auth/repository/impl/AuthRedisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.recordy.server.auth.repository.impl; | ||
|
||
import org.recordy.server.auth.domain.AuthEntity; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface AuthRedisRepository extends CrudRepository<AuthEntity, String> { | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/recordy/server/auth/repository/impl/AuthRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.recordy.server.auth.repository.impl; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.recordy.server.auth.domain.Auth; | ||
import org.recordy.server.auth.domain.AuthEntity; | ||
import org.recordy.server.auth.repository.AuthRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class AuthRepositoryImpl implements AuthRepository { | ||
|
||
private final AuthRedisRepository authRedisRepository; | ||
|
||
@Override | ||
public Auth save(Auth auth) { | ||
return authRedisRepository.save(AuthEntity.from(auth)) | ||
.toDomain(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/recordy/server/auth/service/AuthPlatformService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.recordy.server.auth.service; | ||
|
||
import org.recordy.server.auth.domain.usecase.AuthSignIn; | ||
import org.recordy.server.auth.domain.AuthPlatform; | ||
|
||
public interface AuthPlatformService { | ||
|
||
AuthPlatform getPlatform(AuthSignIn authSignIn); | ||
AuthPlatform.Type getPlatformType(); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/recordy/server/auth/service/AuthPlatformServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.recordy.server.auth.service; | ||
|
||
import org.recordy.server.auth.domain.AuthPlatform; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class AuthPlatformServiceFactory { | ||
|
||
private final Map<AuthPlatform.Type, AuthPlatformService> platformServices; | ||
|
||
public AuthPlatformServiceFactory(List<AuthPlatformService> platformServices) { | ||
this.platformServices = new HashMap<>(); | ||
|
||
platformServices.forEach( | ||
platformService -> this.platformServices.put(platformService.getPlatformType(), platformService)); | ||
} | ||
|
||
public AuthPlatformService getPlatformServiceFrom(AuthPlatform.Type platformType) { | ||
return platformServices.get(platformType); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/recordy/server/auth/service/AuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.recordy.server.auth.service; | ||
|
||
import org.recordy.server.auth.domain.Auth; | ||
import org.recordy.server.auth.domain.usecase.AuthSignIn; | ||
|
||
public interface AuthService { | ||
|
||
Auth signIn(AuthSignIn authSignIn); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/recordy/server/auth/service/AuthTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.recordy.server.auth.service; | ||
|
||
import org.recordy.server.auth.domain.AuthToken; | ||
import org.recordy.server.auth.service.dto.AuthTokenValidationResult; | ||
|
||
public interface AuthTokenService { | ||
|
||
AuthToken issueToken(long userId); | ||
AuthTokenValidationResult validateToken(String token); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/recordy/server/auth/service/dto/AuthTokenValidationResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.recordy.server.auth.service.dto; | ||
|
||
public enum AuthTokenValidationResult { | ||
VALID_JWT, // 유효한 토큰 | ||
INVALID_SIGNATURE, // 유효하지 않은 서명 | ||
INVALID_TOKEN, // 유효하지 않은 토큰 | ||
EXPIRED_TOKEN, // 만료된 토큰 | ||
UNSUPPORTED_TOKEN, // 지원하지 않는 형식의 토큰 | ||
EMPTY_TOKEN // 빈 토큰 | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/recordy/server/auth/service/impl/AuthServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.recordy.server.auth.service.impl; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.recordy.server.auth.domain.Auth; | ||
import org.recordy.server.auth.domain.AuthPlatform; | ||
import org.recordy.server.auth.domain.AuthToken; | ||
import org.recordy.server.auth.domain.usecase.AuthSignIn; | ||
import org.recordy.server.auth.repository.AuthRepository; | ||
import org.recordy.server.auth.service.AuthPlatformService; | ||
import org.recordy.server.auth.service.AuthPlatformServiceFactory; | ||
import org.recordy.server.auth.service.AuthService; | ||
import org.recordy.server.auth.service.AuthTokenService; | ||
import org.recordy.server.user.domain.User; | ||
import org.recordy.server.user.domain.UserStatus; | ||
import org.recordy.server.user.service.UserService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static org.recordy.server.user.domain.UserStatus.ACTIVE; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AuthServiceImpl implements AuthService { | ||
|
||
private final AuthRepository authRepository; | ||
private final AuthPlatformServiceFactory platformServiceFactory; | ||
private final AuthTokenService authTokenService; | ||
private final UserService userService; | ||
|
||
@Override | ||
public Auth signIn(AuthSignIn authSignIn) { | ||
AuthPlatform platform = getPlatform(authSignIn); | ||
User user = getOrCreateUser(platform); | ||
AuthToken token = authTokenService.issueToken(user.getId()); | ||
|
||
return create(platform, token, user.getStatus()); | ||
} | ||
|
||
private AuthPlatform getPlatform(AuthSignIn authSignIn) { | ||
AuthPlatformService platformService = platformServiceFactory.getPlatformServiceFrom(authSignIn.platformType()); | ||
|
||
return platformService.getPlatform(authSignIn); | ||
} | ||
|
||
private User getOrCreateUser(AuthPlatform platform) { | ||
return userService.getByPlatformId(platform.getId()) | ||
.orElseGet(() -> userService.create(platform)); | ||
} | ||
|
||
private Auth create(AuthPlatform platform, AuthToken token, UserStatus userStatus) { | ||
return authRepository.save(Auth.builder() | ||
.platform(platform) | ||
.token(token) | ||
.isSignedUp(userStatus.equals(ACTIVE)) | ||
.build()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/recordy/server/auth/service/impl/AuthTokenServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.recordy.server.auth.service.impl; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.recordy.server.auth.domain.AuthToken; | ||
import org.recordy.server.auth.service.AuthTokenService; | ||
import org.recordy.server.auth.service.dto.AuthTokenValidationResult; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AuthTokenServiceImpl implements AuthTokenService { | ||
|
||
@Override | ||
public AuthToken issueToken(long userId) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AuthTokenValidationResult validateToken(String token) { | ||
return null; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/recordy/server/auth/service/impl/apple/AuthApplePlatformServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.recordy.server.auth.service.impl.apple; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.recordy.server.auth.domain.AuthPlatform; | ||
import org.recordy.server.auth.domain.usecase.AuthSignIn; | ||
import org.recordy.server.auth.service.AuthPlatformService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AuthApplePlatformServiceImpl implements AuthPlatformService { | ||
|
||
@Override | ||
public AuthPlatform getPlatform(AuthSignIn authSignIn) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AuthPlatform.Type getPlatformType() { | ||
return AuthPlatform.Type.APPLE; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/recordy/server/auth/service/impl/kakao/AuthKakaoPlatformServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.recordy.server.auth.service.impl.kakao; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.recordy.server.auth.domain.AuthPlatform; | ||
import org.recordy.server.auth.domain.usecase.AuthSignIn; | ||
import org.recordy.server.auth.service.AuthPlatformService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AuthKakaoPlatformServiceImpl implements AuthPlatformService { | ||
|
||
@Override | ||
public AuthPlatform getPlatform(AuthSignIn authSignIn) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AuthPlatform.Type getPlatformType() { | ||
return AuthPlatform.Type.KAKAO; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/recordy/server/common/config/FeignClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.recordy.server.common.config; | ||
|
||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@EnableFeignClients(basePackages = "org.recordy.server.auth.service.impl") | ||
@Configuration | ||
public class FeignClientConfig { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/recordy/server/common/config/JpaEntityAuditingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.recordy.server.common.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class JpaEntityAuditingConfig { | ||
} |
Oops, something went wrong.