메세지 코드 정리

This commit is contained in:
Rinjae
2025-10-21 11:04:39 +09:00
parent 91e20d276c
commit 9959f15eb5
14 changed files with 190 additions and 173 deletions
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Component
public class UserInvitationEvent implements MessageEventHandler {
public static final String KEY = "user_invitation";
public static final String KEY = "USER_INVITATION";
@Override
public boolean allowAdditionalRecipients() {
@@ -2,10 +2,15 @@ package com.eactive.apim.portal.portaluser.entity;
import com.eactive.eai.data.converter.LocalDateTimeToStringConverter14;
import kjb.safedb.KjbNotRnnoJpaAttributeConverter;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.time.LocalDateTime;
/*
EMSADM.PK_PTL_TWO_FACTOR_AUTH / TS_EMS_I01
*/
@Entity
@Table(name = "PTL_TWO_FACTOR_AUTH")
public class TwoFactorAuth {
@@ -14,6 +19,11 @@ public class TwoFactorAuth {
}
@Id
@Column(name = "id", length = 36, nullable = false)
@GenericGenerator(name = "uuid-gen", strategy = "uuid2")
@GeneratedValue(generator = "uuid-gen", strategy = GenerationType.IDENTITY)
private String id;
@Column(name = "recipient", length = 255)
@Convert(converter = KjbNotRnnoJpaAttributeConverter.class)
private String recipient;
@@ -54,4 +64,8 @@ public class TwoFactorAuth {
public void setExpiresAt(LocalDateTime expiresAt) {
this.expiresAt = expiresAt;
}
public String getId() {
return id;
}
}
@@ -10,9 +10,9 @@ import java.util.HashMap;
import java.util.Map;
@Component
public class RequestAuthNumberEvent implements MessageEventHandler {
public class UserVerificationEmailEvent implements MessageEventHandler {
public static final String KEY = "request_auth_number";
public static final String KEY = "USER_VERIFICATION_EMAIL";
@Override
public boolean allowAdditionalRecipients() {
@@ -33,7 +33,7 @@ public class RequestAuthNumberEvent implements MessageEventHandler {
@Override
public String getDisplayName() {
return "인증 번호 발송";
return "이메일 인증번호 발송";
}
@Override
@@ -0,0 +1,47 @@
package com.eactive.apim.portal.portaluser.event;
import com.eactive.apim.portal.template.service.MessageEventHandler;
import com.eactive.apim.portal.template.service.MessageRecipient;
import com.eactive.apim.portal.template.service.MessageSendEvent;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class UserVerificationMobilePhoneEvent implements MessageEventHandler {
public static final String KEY = "USER_VERIFICATION_MOBILEPHONE";
@Override
public boolean allowAdditionalRecipients() {
return false;
}
@Override
public MessageSendEvent createEvent(Object source, MessageRecipient recipient, Map<String, Object> params) {
Map<String, String> requestParams = new HashMap<>();
requestParams.put("authNumber", (String) params.get("authNumber"));
return new MessageSendEvent(source, KEY, recipient, requestParams);
}
@Override
public String getKey() {
return KEY;
}
@Override
public String getDisplayName() {
return "휴대폰 인증번호 발송";
}
@Override
public String getDescription() {
return "<div>사용 가능 변수: </div><br/>"
+ "<div> - userName 수신자 이름 </div><br/>"
+ "<div> - userId 수신자 ID (이메일) </div><br/>"
+ "<div> - authNumber 인증번호 </div><br/>";
}
}
@@ -31,5 +31,7 @@ public interface PortalUserRepository extends BaseRepository<PortalUser, String>
Optional<PortalUser> findByLoginIdAndMobileNumber(String loginId, String mobileNumber);
long countByPortalOrg(PortalOrg portalOrg);
Optional<PortalUser> findByUserName(String userName);
}
@@ -3,5 +3,10 @@ package com.eactive.apim.portal.portaluser.repository;
import com.eactive.apim.portal.portaluser.entity.TwoFactorAuth;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
public interface TwoFactorAuthRepository extends JpaRepository<TwoFactorAuth, String> {
Optional<TwoFactorAuth> findByRecipient(String recipientKey);
void deleteAllByRecipient(String recipient);
}
@@ -1,48 +1,80 @@
package com.eactive.apim.portal.template.entity;
// com.eactive.apim.portal.template.entity.MessageRequestEnums.MessageCode 이미 중복이 있음
import java.util.Optional;
//public enum MessageCode {
//
// API_APPROVED("API 승인 알림"),
// API_CANCELLED("API 취소 알림"),
// API_DENIED("API 거부 알림"),
// API_REGISTER("API 등록 알림"),
//
// APP_APPROVED("앱 승인 알림"),
// APP_REGISTER("앱 등록 완료"),
// APP_REGISTER_APPROVED("앱 승인 완료"),
//// APP_CANCELLED("앱 취소 알림"),
//// APP_DENIED("앱 거부 알림"),
//// APP_MODIFY("앱 수정 알림"),
//
// USER_MANAGER_ASSIGNED("관리자 권한 부여 알림"),
// USER_REGISTER_APPROVED("사용자 가입 승인 알림"),
// USER_REGISTER_DENIED("사용자 가입 거절 알림"),
//
//// USER_APPROVED,
//// USER_CANCELLED,
//// USER_DENIED,
//// USER_REGISTER,
//
// USER_INVITATION("이메일 초대"),
// REQUEST_AUTH_NUMBER("인증번호 요청"),
//
// USER_PASSWORD_RESET("비밀번호 초기화"),
// USER_PASSWORD_CHANGED("비밀번호 변경 완료 알림");
//// USER_ACTIVATION("사용자 비활성화 알림"),
//// USER_CREATION("사용자 생성 알림"),
//
// private final String description;
//
// MessageCode(String description) {
// this.description = description;
// }
//
// public String getDescription() {
// return description;
// }
//}
//
public enum MessageCode {
// 사용자 이벤트 영역
USER_VERIFICATION_EMAIL("이메일 주소 인증", "AG_NOTI001"),
USER_VERIFICATION_MOBILEPHONE("휴대폰 번호 인증", null),
USER_PASSWORD_RESET("비밀번호 재설정", "AG_NOTI003"),
USER_PASSWORD_CHANGED("사용자 비밀번호 변경", "AG_NOTI004"),
USER_ACCOUNT_LOCKED("계정 잠금 알림", "AG_NOTI005"),
// 법인관리자 이벤트 영역
MANAGER_WITH_ORG_REGISTER_APPROVED("법인관리자 및 법인 등록 승인", "AG_NOTI008"),
MANAGER_WITH_ORG_REGISTER_REJECTED("법인관리자 및 법인 등록 거절", "AG_NOTI009"),
USER_INVITATION("법인 이용자 이메일 초대", "AG_NOTI006"),
USER_INVICATION_CANCELED("법인 이용자 이메일 초대 취소", "AG_NOTI007"),
// 관리자 영역
APP_REGISTER_APPROVED("앱 등록 승인", "AG_NOTI010"),
APP_REGISTER_REJECTED("앱 등록 거절", "AG_NOTI011"),
// 미 사용, 미 분류
@Deprecated
API_APPROVED("API 승인 알림", null),
@Deprecated
API_REJECTED("API 거절 알림", null),
@Deprecated
APP_REGISTER("앱 등록 완료", null),
@Deprecated
USER_MANAGER_ASSIGNED("관리자 권한 부여", null),
@Deprecated
REQUEST_AUTH_NUMBER("인증번호 요청", null),
@Deprecated
USER_WITHDRAWAL_APPROVED("계정 비활성화", null),
@Deprecated
USER_ACTIVATION("사용자 활성화 완료", null), // 이게 왜...이메일 인증인건데........
;
private final String description;
private final String serviceId;
public static Optional<MessageCode> findServiceId(String code) {
for (MessageCode e : values()) {
if (e.name().equalsIgnoreCase(code)) {
return Optional.of(e);
}
}
return Optional.empty();
}
MessageCode(String description, String serviceId) {
this.description = description;
this.serviceId = serviceId;
}
public String getDescription() {
return description;
}
public String getServiceId() {
return serviceId;
}
}
@@ -2,11 +2,12 @@ package com.eactive.apim.portal.template.entity;
import com.eactive.apim.portal.portaluser.entity.PortalUser;
import com.eactive.apim.portal.template.entity.MessageRequestEnums.MessageCode;
import com.eactive.eai.data.converter.LocalDateTimeToStringConverter14;
import kjb.safedb.KjbNotRnnoJpaAttributeConverter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
@@ -49,13 +50,19 @@ public class MessageRequest implements Serializable {
private LocalDateTime sentDate;
private String username;
@Convert(converter = KjbNotRnnoJpaAttributeConverter.class)
private String email;
@Convert(converter = KjbNotRnnoJpaAttributeConverter.class)
private String phone;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@Comment("발송 대상 사용자")
private PortalUser user;
@Comment("UMS 연계용 UID")
@Column(name="ums_uid", length = 16)
private String umsUid;
@@ -1,82 +0,0 @@
package com.eactive.apim.portal.template.entity;
import java.util.Optional;
public class MessageRequestEnums {
public enum MessageCode {
// 사용자 이벤트 영역
USER_VERIFICATION_EMAIL("이메일 주소 인증", "AG_NOTI001"),
USER_VERIFICATION_MOBILEPHONE("휴대폰 번호 인증", null),
USER_PASSWORD_RESET("비밀번호 재설정", "AG_NOTI003"),
USER_PASSWORD_CHANGED("사용자 비밀번호 변경", "AG_NOTI004"),
USER_ACCOUNT_LOCKED("계정 잠금 알림", "AG_NOTI005"),
// 법인관리자 이벤트 영역
ORG_APPROVED("사용자 등록 승인", "AG_NOTI008"),
ORG_REJECTED("사용자 등록 거절", "AG_NOTI009"),
USER_INVITATION("법인 이용자 이메일 초대", "AG_NOTI006"),
USER_INVICATION_CANCELED("법인 이용자 이메일 초대 취소", "AG_NOTI007"),
// 관리자 영역
APP_REGISTER_APPROVED("앱 등록 승인", "AG_NOTI010"),
APP_REGISTER_REJECTED("앱 등록 거절", "AG_NOTI011"),
// 미 사용, 미 분류
@Deprecated
API_APPROVED("API 승인 알림", null),
@Deprecated
API_REJECTED("API 거절 알림", null),
@Deprecated
APP_REGISTER("앱 등록 완료", null),
@Deprecated
USER_MANAGER_ASSIGNED("관리자 권한 부여", null),
@Deprecated
REQUEST_AUTH_NUMBER("인증번호 요청", null),
@Deprecated
USER_WITHDRAWAL_APPROVED("계정 비활성화", null),
@Deprecated
USER_ACTIVATION("사용자 활성화 완료", null), // 이게 왜...이메일 인증인건데........
;
private final String description;
private final String serviceId;
public static Optional<MessageCode> findServiceId(String code) {
for (MessageCode e : values()) {
if (e.name().equalsIgnoreCase(code)) {
return Optional.of(e);
}
}
return Optional.empty();
}
MessageCode(String description, String serviceId) {
this.description = description;
this.serviceId = serviceId;
}
public String getDescription() {
return description;
}
public String getServiceId() {
return serviceId;
}
}
}
@@ -1,27 +0,0 @@
package com.eactive.apim.portal.template.entity;
@Deprecated
public class MessageTemplateEnums {
// 이건 또 왜 3번쨰...................
// public enum MessageCode {
// API_APPROVED("API 승인 알림"),
// APP_REGISTER("앱 등록 완료"),
// USER_ACTIVATION("사용자 활성화 완료"),
// USER_INVITATION("이메일 초대"),
// USER_PASSWORD_RESET("비밀번호 재설정"),
// USER_REGISTER_APPROVED("사용자 등록 승인"),
// USER_WITHDRAWAL_APPROVED("계정 비활성화");
//
// private final String description;
//
// MessageCode(String description) {
// this.description = description;
// }
//
// public String getDescription() {
// return description;
// }
// }
}
@@ -1,26 +1,29 @@
package com.eactive.apim.portal.template.repository;
import com.eactive.apim.portal.template.entity.MessageRequest;
import com.eactive.apim.portal.template.entity.MessageRequestEnums;
import com.eactive.eai.rms.data.EMSDataSource;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import com.eactive.apim.portal.template.entity.MessageCode;
import com.eactive.apim.portal.template.entity.MessageRequest;
import com.eactive.eai.rms.data.EMSDataSource;
@Repository
@EMSDataSource
public interface MessageRequestRepository extends JpaRepository<MessageRequest, String> {
@Query("SELECT m FROM MessageRequest m WHERE m.email = :email AND m.messageCode = :messageCode")
List<MessageRequest> findByEmailAndMessageCode(@Param("email") String email, @Param("messageCode") MessageRequestEnums.MessageCode messageCode);
List<MessageRequest> findByEmailAndMessageCode(@Param("email") String email, @Param("messageCode") MessageCode messageCode);
// @Query("SELECT m fROM MessageRequest m WHERE m.email =:email AND m.messageCode =:messageCode ORDER BY m.requestDate DESC")
Optional<MessageRequest> findFirstByEmailAndMessageCodeOrderByRequestDateDesc(@Param("email") String email, @Param("messageCode") MessageRequestEnums.MessageCode messageCode);
Optional<MessageRequest> findFirstByEmailAndMessageCodeOrderByRequestDateDesc(
@Param("email") String email, @Param("messageCode") MessageCode messageCode
);
@Modifying(clearAutomatically = true)
@Query("DELETE FROM MessageRequest m WHERE m.username =:username AND m.email =:email")
@@ -7,6 +7,8 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import com.eactive.apim.portal.template.entity.MessageCode;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -43,7 +45,8 @@ public class MessageHandlerService {
@EventListener
public void handleMessageSendEvent(MessageSendEvent event) {
messageSendService.sendMessage(event.getMessageType(), event.getRecipient(), event.getParams());
// messageSendService.sendMessage(event.getMessageType(), event.getRecipient(), event.getParams());
messageSendService.sendMessage(MessageCode.valueOf(event.getMessageType()), event.getRecipient(), event.getParams());
}
}
@@ -1,8 +1,8 @@
package com.eactive.apim.portal.template.service;
import com.eactive.apim.portal.portalproperty.service.PortalPropertyService;
import com.eactive.apim.portal.template.entity.MessageCode;
import com.eactive.apim.portal.template.entity.MessageRequest;
import com.eactive.apim.portal.template.entity.MessageRequestEnums;
import com.eactive.apim.portal.template.entity.MessageTemplate;
import com.eactive.apim.portal.template.repository.MessageRequestRepository;
import com.eactive.apim.portal.template.repository.MessageTemplateRepository;
@@ -35,8 +35,8 @@ public class MessageSendService {
private final PortalPropertyService portalPropertyService;
@Transactional
public void sendMessage(String messageCode, MessageRecipient recipient, Map<String, String> messageParams) {
processMessage(messageCode, recipient, messageParams);
public void sendMessage(MessageCode messageCode, MessageRecipient recipient, Map<String, String> messageParams) {
processMessage(messageCode.name(), recipient, messageParams);
}
private void processMessage(String messageCode, MessageRecipient recipient, Map<String, String> messageParams) {
@@ -76,7 +76,7 @@ public class MessageSendService {
if (template.getEnableSms().equalsIgnoreCase("Y")) {
String smsEaiInterfaceId = portalProperties.get("message.integration.eaiId.sms");
MessageRequest smsRequest = new MessageRequest();
smsRequest.setMessageCode(MessageRequestEnums.MessageCode.valueOf(template.getMessageCode().toUpperCase()));
smsRequest.setMessageCode(MessageCode.valueOf(template.getMessageCode().toUpperCase()));
smsRequest.setSubject(subject);
String smsMessage = buildMessage(template.getSmsTemplate(), messageParams);
smsRequest.setMessage(smsMessage);
@@ -93,7 +93,7 @@ public class MessageSendService {
if (template.getEnableEmail().equalsIgnoreCase("Y")) {
String mailEaiInterfaceId = portalProperties.get("message.integration.eaiId.email");
MessageRequest emailRequest = new MessageRequest();
emailRequest.setMessageCode(MessageRequestEnums.MessageCode.valueOf(template.getMessageCode().toUpperCase()));
emailRequest.setMessageCode(MessageCode.valueOf(template.getMessageCode().toUpperCase()));
emailRequest.setSubject(subject);
String emailMessage = buildMessage(template.getEmailTemplate(), messageParams);
emailRequest.setMessage(emailMessage);
@@ -29,9 +29,22 @@ public class KjbNotRnnoJpaAttributeConverter implements AttributeConverter<Strin
if (StringUtils.isNotEmpty(attribute)) {
KjbSafedbWrapper wrapper = KjbSafedbWrapper.getInstance();
attribute = wrapper.encryptNotRnnoString(attribute);
}
// log.debug("DB 암호화 #2 : {} -> {}", originalAttribute, attribute);
if (log.isDebugEnabled()) {
// originalAttribute 홀수 글자 마스킹
StringBuilder sb = new StringBuilder();
for (int i = 0; i < originalAttribute.length(); i++) {
if (i % 2 == 0) {
sb.append(originalAttribute.charAt(i));
} else {
sb.append("*");
}
}
originalAttribute = sb.toString();
log.debug("DB 암호화 #2 : {} -> {}", originalAttribute, attribute);
}
}
return attribute;
}