From 5b10b19870ca85cc759221062db071944e64374f Mon Sep 17 00:00:00 2001 From: minkyu1128 Date: Tue, 21 Feb 2023 17:40:05 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8C=80=EC=B9=AD=ED=82=A4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -.원인: 대칭키관리DB 에는 공개키1:대칭키N 개가 등록이 가능하나 대칭키 조회 시 단건 조회를 하고 있어 오류가 발생 함. -.수정: AsIs: 단건 조회 ToBe: 다건 조회(등록일자 내림차순) and get(0) --- .../domain/repository/NiceCiSymkeyMngRepository.java | 4 ++-- .../xit/ci/api/service/support/NiceCiGenerator.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java b/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java index be78ee8..6e6a793 100644 --- a/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java +++ b/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java @@ -3,9 +3,9 @@ package cokr.xit.ci.api.domain.repository; import cokr.xit.ci.api.domain.NiceCiSymkeyMng; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; +import java.util.List; public interface NiceCiSymkeyMngRepository extends JpaRepository { - Optional findByPubkey(String pubkey); + List findAllByPubkeyOrderByRegistDtDesc(String pubkey); } diff --git a/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java b/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java index 696c8b2..c39a93b 100644 --- a/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java +++ b/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java @@ -20,6 +20,7 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Optional; @Log4j2 @@ -47,7 +48,7 @@ public class NiceCiGenerator { @Value("${contract.nice.ci.rest.api.ci}") private String API_CI; - public ResponseVO initialKey(){ + public ResponseVO initialKey() { NiceCiApiExecutor executor = buildExecutor(); try { @@ -80,11 +81,12 @@ public class NiceCiGenerator { dataBodySymkeyResp = SymmetricKey.getInstance().getData(); } else { //대칭키 상태가 유효하지 않으면... //현재 대칭키 조회(by 공개키) - Optional niceCiSymkeyMng = niceCiSymkeyMngRepository.findByPubkey(pubkeyResponseVO.getResultInfo().getPublicKey()); + List niceCiSymkeyMngs = niceCiSymkeyMngRepository.findAllByPubkeyOrderByRegistDtDesc(pubkeyResponseVO.getResultInfo().getPublicKey()); + Optional niceCiSymkeyMng = Optional.ofNullable(niceCiSymkeyMngs == null || niceCiSymkeyMngs.isEmpty() ? null : niceCiSymkeyMngs.get(0)); //대칭키 유효기간만료일이 1일 이상 남았으면 if (niceCiSymkeyMng.isPresent() - &&(Long.parseLong(niceCiSymkeyMng.get().getExpireDt()) > Long.parseLong(LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))) ) { + && (Long.parseLong(niceCiSymkeyMng.get().getExpireDt()) > Long.parseLong(LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))))) { dataBodySymkeyResp = mapper.readValue(niceCiSymkeyMng.get().getRespJsonData(), DataBodySymkeyResp.class); //대칭키 싱글톤 객체 초기화 @@ -137,7 +139,7 @@ public class NiceCiGenerator { } } - private NiceCiApiExecutor buildExecutor(){ + private NiceCiApiExecutor buildExecutor() { return NiceCiApiExecutor.builder() .HOST(this.HOST) .CLIENT_ID(this.CLIENT_ID)