Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public record TemplateSnapshot(
String groupId, String groupName, Channel channel, int version) {}

public static MessageLogDetailResponse from(MessageLog log) {
return from(log, log.getRecipientEnc());
}

public static MessageLogDetailResponse from(MessageLog log, String recipientMasked) {
// 템플릿 정보가 있을 경우에만 Snapshot 생성
TemplateSnapshot snapshot = null;
TemplateVersion templateVersion = log.getTemplateVersion();
Expand All @@ -42,7 +46,7 @@ public static MessageLogDetailResponse from(MessageLog log) {
log.getId(),
log.getTraceId(),
log.getSubscription().getSubId(),
log.getRecipientEnc(),
recipientMasked,
Comment thread
arlen02-01 marked this conversation as resolved.
(templateVersion != null) ? templateVersion.getId() : null,
log.getChannel(),
log.getStatus(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.project.core.controller.dto.response.MaskingUtil;
import com.project.global.exception.ApplicationException;
import com.project.global.exception.code.domain.core.CoreErrorCode;
import com.project.global.exception.core.OperationFailedException;
import com.project.global.util.AesUtil;
import com.project.notification.controller.dto.request.MessageLogSearchRequest;
import com.project.notification.controller.dto.response.MessageLogDetailResponse;
import com.project.notification.controller.dto.response.MessageLogResponse;
import com.project.notification.infra.entity.MessageLog;
import com.project.notification.infra.repository.MessageLogRepository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Slf4j
public class MessageLogService {

private final MessageLogRepository messageLogRepository;
private final AesUtil aesUtil;

/** 로그 목록 검색 */
public Slice<MessageLogResponse> searchLogs(
Expand All @@ -35,6 +41,31 @@ public MessageLogDetailResponse getLogDetail(Long logId) {
.findDetailById(logId)
.orElseThrow(() -> new ApplicationException(CoreErrorCode.LOG_NOT_FOUND));

return MessageLogDetailResponse.from(log);
String decryptedRecipient = safeDecrypt(log.getRecipientEnc());
String maskedRecipient = maskRecipient(decryptedRecipient);

return MessageLogDetailResponse.from(log, maskedRecipient);
}

private String safeDecrypt(String encrypted) {
if (encrypted == null) {
return null;
}
try {
return aesUtil.decrypt(encrypted);
} catch (OperationFailedException e) {
log.warn("Failed to decrypt recipient. value: {}", encrypted, e);
return encrypted;
}
}

private String maskRecipient(String recipient) {
if (recipient == null || recipient.isBlank()) {
return recipient;
}
if (recipient.contains("@")) {
return MaskingUtil.maskEmail(recipient);
}
return MaskingUtil.maskPhone(recipient);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ logging:
org.springframework.web: INFO
org.hibernate.SQL: WARN
pattern:
level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"
level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"

debug:
crypto:
enabled: true
Comment thread
arlen02-01 marked this conversation as resolved.