From 8874c41104be853dbb1025791fc2057e1d882e0a Mon Sep 17 00:00:00 2001 From: Rinjae Date: Fri, 17 Oct 2025 18:11:29 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B8=EC=A6=9D=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=EC=8B=9C=20=EC=95=94=ED=98=B8=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/service/AuthNumberServiceImpl.java | 2 -- .../apps/auth/service/AuthNumberStorage.java | 4 +-- .../apps/auth/service/MessageSender.java | 15 ++++++-- .../config/PortalConfigPortalDatasource.java | 35 ++++++++++++++++--- .../portal/tools/HibernateSqlGenerator.java | 20 +++++++++++ src/main/resources/logback-spring.xml | 13 +++++++ 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/eactive/apim/portal/tools/HibernateSqlGenerator.java diff --git a/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberServiceImpl.java b/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberServiceImpl.java index 3e9bbd2..d873d08 100644 --- a/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberServiceImpl.java +++ b/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberServiceImpl.java @@ -38,14 +38,12 @@ public class AuthNumberServiceImpl implements AuthNumberService { } /** - * 이메일 인증도 가능하도록 개선 * @param recipientKey * @param msgType */ @Override @Transactional(noRollbackFor = AuthNumberException.class) public void sendRequestAuthNumber(String recipientKey, String msgType) { - // TODO: 이메일 인증도 가능하도록 개선 logger.info("Sending auth number to: {} via {}", recipientKey, msgType); validateResendTime(recipientKey); diff --git a/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberStorage.java b/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberStorage.java index 6cd0859..85acad1 100644 --- a/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberStorage.java +++ b/src/main/java/com/eactive/apim/portal/apps/auth/service/AuthNumberStorage.java @@ -19,7 +19,7 @@ public class AuthNumberStorage { public void saveAuthNumber(String recipientKey, String authNumber, LocalDateTime expiresAt) { - Optional exist = twoFactorAuthRepository.findById(recipientKey); + Optional exist = twoFactorAuthRepository.findByRecipient(recipientKey); if (exist.isPresent()) { TwoFactorAuth old = exist.get(); old.setAuthNumber(authNumber); @@ -33,7 +33,7 @@ public class AuthNumberStorage { } public Optional getAuthNumber(String recipientKey) { - return twoFactorAuthRepository.findById(recipientKey); + return twoFactorAuthRepository.findByRecipient(recipientKey); } public void deleteAuthNumber(String recipientKey) { diff --git a/src/main/java/com/eactive/apim/portal/apps/auth/service/MessageSender.java b/src/main/java/com/eactive/apim/portal/apps/auth/service/MessageSender.java index b5f104b..70a0ab9 100644 --- a/src/main/java/com/eactive/apim/portal/apps/auth/service/MessageSender.java +++ b/src/main/java/com/eactive/apim/portal/apps/auth/service/MessageSender.java @@ -1,6 +1,6 @@ package com.eactive.apim.portal.apps.auth.service; -import com.eactive.apim.portal.portaluser.event.RequestAuthNumberEvent; +import com.eactive.apim.portal.portaluser.event.UserVerificationMobilePhoneEvent; import com.eactive.apim.portal.template.service.MessageHandlerService; import com.eactive.apim.portal.template.service.MessageRecipient; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +29,17 @@ public class MessageSender { HashMap params = new HashMap<>(); params.put("authNumber", authNumber); - messageHandlerService.publishEvent(RequestAuthNumberEvent.KEY, recipient, params); + + // 이메일, SMS MESSAEG_CODE 다름 처리 + String messageCode = ""; + if ("email".equalsIgnoreCase(msgType)) { + messageCode = "USER_VERIFICATION_EMAIL"; + } else if ("sms".equalsIgnoreCase(msgType)) { + messageCode = "USER_VERIFICATION_MOBILEPHONE"; + } else { + throw new IllegalArgumentException("Unsupported message type: " + msgType); + } + + messageHandlerService.publishEvent(UserVerificationMobilePhoneEvent.KEY, recipient, params); } } diff --git a/src/main/java/com/eactive/apim/portal/config/PortalConfigPortalDatasource.java b/src/main/java/com/eactive/apim/portal/config/PortalConfigPortalDatasource.java index d195e96..730d3ae 100644 --- a/src/main/java/com/eactive/apim/portal/config/PortalConfigPortalDatasource.java +++ b/src/main/java/com/eactive/apim/portal/config/PortalConfigPortalDatasource.java @@ -20,6 +20,8 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import javax.annotation.PostConstruct; import javax.sql.DataSource; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.HashMap; /** @@ -45,12 +47,14 @@ import java.util.HashMap; @EnableJpaAuditing(auditorAwareRef = "auditorProvider") @Slf4j public class PortalConfigPortalDatasource { + private final EmsDatasourceProperties emsDatasourceProperties; + private final Environment env; - @Autowired - private EmsDatasourceProperties emsDatasourceProperties; - @Autowired - Environment env; + public PortalConfigPortalDatasource(EmsDatasourceProperties emsDatasourceProperties, Environment env) { + this.emsDatasourceProperties = emsDatasourceProperties; + this.env = env; + } @PostConstruct @@ -130,6 +134,7 @@ public class PortalConfigPortalDatasource { properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect"); properties.put("hibernate.format_sql", "true"); properties.put("hibernate.physical_naming_strategy", "com.eactive.apim.portal.common.entity.CustomPhysicalNamingStrategy"); + // properties.put("hibernate.show_sql", "true"); properties.put("hibernate.transaction.jta.platform", "org.hibernate.engine.transaction.jta.platform.internal.AtomikosJtaPlatform"); properties.put("hibernate.use_sql_comments", "true"); @@ -148,6 +153,28 @@ public class PortalConfigPortalDatasource { properties.put("org.hibernate.envers.revision_number_field_name", "id"); properties.put("org.hibernate.envers.store_data_at_delete", "true"); + // 개발 환경용 + if (env.matchesProfiles("dev", "local")) { + properties.put("hibernate.hbm2ddl.auto", "validate"); + } + + + // DDL 생성용 + if (env.matchesProfiles("ddl_generate")) { + log.warn("Spring profile 내 ddl_generate 지정됨 / 로컬 개발용"); + + String filePath = "D:\\kjb-logs\\devSvr99\\portal-schema_ddl-" + + DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss").format(LocalDateTime.now()) + ".sql"; + + properties.put("hibernate.hbm2ddl.auto", "validate"); + properties.put("javax.persistence.schema-generation.create-source", "metadata"); + properties.put("javax.persistence.schema-generation.scripts.action", "update"); +// properties.put("javax.persistence.schema-generation.scripts.action", "create"); + properties.put("javax.persistence.schema-generation.scripts.create-target", filePath); + + log.info("DDL script 생성 : {}", filePath); + } + return builder .dataSource(dataSource) diff --git a/src/main/java/com/eactive/apim/portal/tools/HibernateSqlGenerator.java b/src/main/java/com/eactive/apim/portal/tools/HibernateSqlGenerator.java new file mode 100644 index 0000000..53f7997 --- /dev/null +++ b/src/main/java/com/eactive/apim/portal/tools/HibernateSqlGenerator.java @@ -0,0 +1,20 @@ +package com.eactive.apim.portal.tools; + +import com.eactive.apim.portal.PortalApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.ConfigurableApplicationContext; + +/** + * DDL SQL 생성용으로 HTTP 서버는 구동하지 않음 + */ +public class HibernateSqlGenerator { + public static void main(String[] args) { + ConfigurableApplicationContext context = + new SpringApplicationBuilder(PortalApplication.class) + .web(WebApplicationType.NONE) + .profiles("ddl_generate", "gf63") + .run(args); + context.close(); + } +} diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 15cc970..55b0057 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -100,12 +100,25 @@ + + + > + + + + + + + + + + \ No newline at end of file