diff --git a/src/main/java/com/gt/genti/aop/EnvAop.java b/src/main/java/com/gt/genti/aop/EnvAop.java new file mode 100644 index 00000000..feb35cab --- /dev/null +++ b/src/main/java/com/gt/genti/aop/EnvAop.java @@ -0,0 +1,43 @@ +package com.gt.genti.aop; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +import com.gt.genti.config.auth.UserDetailsImpl; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Aspect +@Component +@Slf4j +@RequiredArgsConstructor +public class EnvAop { + + private final Environment env; + + @Before("@annotation(com.gt.genti.aop.annotation.CheckUserIsQuit) && args(userDetailsImpl)") + public void checkUserIsQuit(final UserDetailsImpl userDetailsImpl) { + log.info("유저탈퇴확인aop실행"); + if (!userDetailsImpl.isEnabled()) { + throw new RuntimeException("탈퇴한 사용자입니다."); + } + } + + @Around("@annotation(com.gt.genti.aop.annotation.DeployOnly)") + public Object deployOnly(ProceedingJoinPoint joinPoint) throws Throwable { + String[] activeProfiles = env.getActiveProfiles(); + for (String profile : activeProfiles) { + if ("deploy".equals(profile)) { + return joinPoint.proceed(); + } + } + + return null; + + } +} diff --git a/src/main/java/com/gt/genti/aop/annotation/DeployOnly.java b/src/main/java/com/gt/genti/aop/annotation/DeployOnly.java new file mode 100644 index 00000000..11dd2450 --- /dev/null +++ b/src/main/java/com/gt/genti/aop/annotation/DeployOnly.java @@ -0,0 +1,12 @@ +package com.gt.genti.aop.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +public @interface DeployOnly { + +} diff --git a/src/main/java/com/gt/genti/config/auth/UserDetailsImpl.java b/src/main/java/com/gt/genti/config/auth/UserDetailsImpl.java index ff749d1e..62e1a249 100644 --- a/src/main/java/com/gt/genti/config/auth/UserDetailsImpl.java +++ b/src/main/java/com/gt/genti/config/auth/UserDetailsImpl.java @@ -65,7 +65,7 @@ public UserDetailsImpl(Long authId, String roles, String userEmail, String userP this.email = userEmail; this.password = userPw; this.emailVerified = emailVerified; - this.locked = !locked; + this.locked = locked; } private Collection createAuthorities(String roles) { @@ -153,10 +153,7 @@ public boolean isCredentialsNonExpired() { */ @Override public boolean isEnabled() { - //이메일이 인증되어 있고 계정이 잠겨있지 않으면 true - //상식과 조금 벗어나서, Customizing 하였음 - return (emailVerified && locked); - + return true; } @Override diff --git a/src/main/java/com/gt/genti/external/discord/service/DiscordService.java b/src/main/java/com/gt/genti/external/discord/service/DiscordService.java index 1026525c..9cb50f2a 100644 --- a/src/main/java/com/gt/genti/external/discord/service/DiscordService.java +++ b/src/main/java/com/gt/genti/external/discord/service/DiscordService.java @@ -2,6 +2,7 @@ import org.springframework.stereotype.Service; +import com.gt.genti.aop.annotation.DeployOnly; import com.gt.genti.external.discord.restclient.DiscordRestClient; import jakarta.annotation.PostConstruct; @@ -23,6 +24,7 @@ void init() { sb = new StringBuilder(jsonTemplate); } + @DeployOnly public void sendToDiscord(String message) { int startIndex = sb.lastIndexOf("$1"); diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 27143d20..29da2684 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -12,14 +12,14 @@ false - + ${CONSOLE_LOG_PATTERN} utf8 - + /logs/app.log ${CONSOLE_LOG_PATTERN} @@ -35,8 +35,19 @@ - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/gt/genti/service/DiscordLogTest.java b/src/test/java/com/gt/genti/service/DiscordLog_LocalEnvTest.java similarity index 53% rename from src/test/java/com/gt/genti/service/DiscordLogTest.java rename to src/test/java/com/gt/genti/service/DiscordLog_LocalEnvTest.java index a98c1d47..45c78f98 100644 --- a/src/test/java/com/gt/genti/service/DiscordLogTest.java +++ b/src/test/java/com/gt/genti/service/DiscordLog_LocalEnvTest.java @@ -1,14 +1,18 @@ package com.gt.genti.service; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import lombok.extern.slf4j.Slf4j; @SpringBootTest @Slf4j -public class DiscordLogTest { +@ActiveProfiles("local") +public class DiscordLog_LocalEnvTest { @Test + @DisplayName("로컬환경이므로 디스코드에 전송되지않는것이 정상") void loggingError() { log.error("오류"); log.warn("워닝");