Skip to content

Commit

Permalink
Merge pull request #215 from TEAM-SAMSION/main
Browse files Browse the repository at this point in the history
release : 1.2.1 배포
  • Loading branch information
isprogrammingfun authored Jun 6, 2024
2 parents 94e395c + 617b78c commit 0cbe8ec
Show file tree
Hide file tree
Showing 120 changed files with 1,022 additions and 572 deletions.
13 changes: 9 additions & 4 deletions Api-Module/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
apply from: "$rootDir/gradle/customplugin/gradleutils.gradle"

dependencies {
// actuators
implementation 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'

implementation project(":Log-Module")

implementation project(":Domain-Module:Todo-Module:Todo-Presentation")
implementation project(":Domain-Module:Auth-Module:Auth-Presentation")
implementation project(":Domain-Module:User-Module:User-Presentation")

implementation project(':Alarm-Module')

implementation project(':Batch-Module')

implementation project(':Event')

getProjectsEndsWith("Domain-Module", "Presentation").forEach { module ->
implementation project(module.path)
}

}
13 changes: 13 additions & 0 deletions Batch-Module/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apply from: "$rootDir/gradle/customplugin/gradleutils.gradle"

dependencies {
getProjectsEndsWith("Domain-Module", "Domain").forEach { module ->
implementation project(module.path)
}
implementation project(":Common-Module")
}





Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pawith.todoapplication.handler;
package com.pawith.batchmodule.todo;

import com.pawith.commonmodule.cache.operators.ValueOperator;
import com.pawith.commonmodule.event.MultiNotificationEvent;
Expand All @@ -17,7 +17,7 @@

@Slf4j
@Component
public class IncompleteTodoCountNotificationHandler extends AbstractBatchSchedulingHandler<IncompleteTodoCountInfoDao> {
public class IncompleteTodoCountNotificationBatchService extends AbstractBatchSchedulingHandler<IncompleteTodoCountInfoDao> {
private static final Integer BATCH_SIZE = 100;
private static final String CRON_EXPRESSION = "0 0 20 * * *"; // 매일 20시에 실행
private static final String NOTIFICATION_MESSAGE = "[%s] 오늘이 지나기 전, %s님에게 남은 %d개의 todo를 완료해주세요!";
Expand All @@ -27,7 +27,7 @@ public class IncompleteTodoCountNotificationHandler extends AbstractBatchSchedul
private final ApplicationEventPublisher applicationEventPublisher;
private final ValueOperator<Long, String> valueOperator;

public IncompleteTodoCountNotificationHandler(RegisterRepository registerRepository, UserQueryService userQueryService, ApplicationEventPublisher applicationEventPublisher, ValueOperator<Long, String> valueOperator) {
public IncompleteTodoCountNotificationBatchService(RegisterRepository registerRepository, UserQueryService userQueryService, ApplicationEventPublisher applicationEventPublisher, ValueOperator<Long, String> valueOperator) {
super(BATCH_SIZE, CRON_EXPRESSION);
this.registerRepository = registerRepository;
this.userQueryService = userQueryService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pawith.todoapplication.handler;
package com.pawith.batchmodule.todo;

import com.pawith.commonmodule.event.MultiNotificationEvent;
import com.pawith.commonmodule.event.NotificationEvent;
Expand All @@ -22,14 +22,14 @@
*/
@Slf4j
@Component
public class TodoNotificationHandler extends AbstractBatchSchedulingHandler<NotificationDao> {
public class TodoNotificationBatchService extends AbstractBatchSchedulingHandler<NotificationDao> {
private static final Integer BATCH_SIZE = 100;
private static final String CRON_EXPRESSION = "0 0 * * * *";

private final TodoNotificationRepository todoNotificationRepository;
private final ApplicationEventPublisher applicationEventPublisher;

public TodoNotificationHandler(TodoNotificationRepository todoNotificationRepository, ApplicationEventPublisher applicationEventPublisher) {
public TodoNotificationBatchService(TodoNotificationRepository todoNotificationRepository, ApplicationEventPublisher applicationEventPublisher) {
super(BATCH_SIZE, CRON_EXPRESSION);
this.todoNotificationRepository = todoNotificationRepository;
this.applicationEventPublisher = applicationEventPublisher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.pawith.commonmodule.event;

import com.pawith.commonmodule.enums.Provider;

public record UserSignUpEvent(
String nickname,
String email,
Provider provider
String email
) {
public static UserSignUpEvent of(String nickname, String email) {
return new UserSignUpEvent(nickname, email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 6 additions & 3 deletions Domain-Module/Auth-Module/Auth-Application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ dependencies {
implementation 'io.github.openfeign:feign-httpclient:12.1'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.0.3'
// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation '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'
//OAuth
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// webclinet
implementation 'org.springframework.boot:spring-boot-starter-webflux'

// user
implementation project(':Domain-Module:User-Module:User-Domain')
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class IgnoredPathConsts {
"/oauth/**", HttpMethod.GET,
"/jwt", HttpMethod.GET,
"/reissue",HttpMethod.POST,
"/actuator/**", HttpMethod.GET
"/actuator/**", HttpMethod.GET,
"/user/landing", HttpMethod.POST
);

}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.pawith.authapplication.handler;

import com.pawith.authapplication.handler.request.OAuthSuccessEvent;
import com.pawith.authdomain.entity.OAuth;
import com.pawith.authdomain.exception.AuthError;
import com.pawith.authdomain.exception.OAuthException;
import com.pawith.authdomain.service.OAuthQueryService;
import com.pawith.authdomain.service.OAuthSaveService;
import com.pawith.commonmodule.event.UserSignUpEvent;
import com.pawith.userdomain.entity.User;
import com.pawith.userdomain.service.UserQueryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
@RequiredArgsConstructor
public class OAuthSuccessHandler {
private final OAuthQueryService oAuthQueryService;
private final OAuthSaveService oAuthSaveService;
private final UserQueryService userQueryService;
private final ApplicationEventPublisher applicationEventPublisher;

@EventListener(OAuthSuccessEvent.class)
@Transactional
/**
* TODO: 리팩터링,리팩터링,리팩터링,리팩터링,리팩터링,리팩터링,리팩터링,리팩터링,리팩터링,리팩터링,리팩터링
*/
public void handle(OAuthSuccessEvent oAuthSuccessEvent) {
if (oAuthQueryService.existBySub(oAuthSuccessEvent.sub())) {
final OAuth oAuth = oAuthQueryService.findBySub(oAuthSuccessEvent.sub());
final User user = userQueryService.findById(oAuth.getUserId());
user.updateEmail(oAuthSuccessEvent.email());
} else {
if (userQueryService.checkEmailAlreadyExist(oAuthSuccessEvent.email())) {
final User user = userQueryService.findByEmail(oAuthSuccessEvent.email());
if (oAuthQueryService.existByUserId(user.getId())|| user.isNotMatchingProvider(oAuthSuccessEvent.provider())) {
throw new OAuthException(AuthError.INVALID_OAUTH_REQUEST);
}
saveOAuth(oAuthSuccessEvent, user);
} else {
applicationEventPublisher.publishEvent(UserSignUpEvent.of(
oAuthSuccessEvent.username(),
oAuthSuccessEvent.email()
));
final User user = userQueryService.findByEmail(oAuthSuccessEvent.email());
saveOAuth(oAuthSuccessEvent, user);
}
}
}

private void saveOAuth(OAuthSuccessEvent oAuthSuccessEvent, User user) {
OAuth oAuth = OAuth.of(
oAuthSuccessEvent.provider(),
oAuthSuccessEvent.sub(),
user.getId()
);
oAuthSaveService.save(oAuth);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pawith.authapplication.handler.request;

import com.pawith.commonmodule.enums.Provider;

public record OAuthSuccessEvent(
String username,
String email,
Provider provider,
String sub
) {
public static OAuthSuccessEvent of(String username, String email, Provider provider, String sub) {
return new OAuthSuccessEvent(username, email, provider, sub);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pawith.authapplication.service;

public interface JWTExtractUserDetailsUseCase<T> {
T extract(final String token);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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;
import lombok.RequiredArgsConstructor;

@ApplicationService
@RequiredArgsConstructor
public class JWTExtractEmailUseCaseImpl implements JWTExtractEmailUseCase {
public class JWTExtractUserDetailsUseCaseImpl implements JWTExtractUserDetailsUseCase<Long> {
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -54,9 +56,9 @@ private TokenReissueResponse generateToken(final Function<String, JWTProvider.To
final String generatedRefreshToken = AuthConsts.AUTHENTICATION_TYPE_PREFIX + token.refreshToken();
return new TokenReissueResponse(generatedAccessToken, generatedRefreshToken);
}
private TokenReissueResponse generateAndSaveToken(final Function<String, JWTProvider.Token> tokenGenerator,final String refreshToken,final String userEmail) {
private TokenReissueResponse generateAndSaveToken(final Function<String, JWTProvider.Token> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 0cbe8ec

Please sign in to comment.