From a3907e152b75c623fd7839298732c94c38c05455 Mon Sep 17 00:00:00 2001 From: minkyu1128 Date: Thu, 12 May 2022 09:33:01 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=80=EC=B9=AD=ED=82=A4=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EA=B8=B0=ED=95=9C=20=EB=A7=8C=EB=A3=8C=EC=9D=BC?= =?UTF-8?q?=EC=8B=9C=20=EC=B2=B4=ED=81=AC=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/ci/api/domain/NiceCiSymkeyMng.java | 4 ++++ .../ci/api/service/support/NiceCiGenerator.java | 8 +++++++- .../service/support/rest/utils/SymmetricKey.java | 16 ++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/cokr/xit/ci/api/domain/NiceCiSymkeyMng.java b/src/main/java/cokr/xit/ci/api/domain/NiceCiSymkeyMng.java index 0724300..e8d677c 100644 --- a/src/main/java/cokr/xit/ci/api/domain/NiceCiSymkeyMng.java +++ b/src/main/java/cokr/xit/ci/api/domain/NiceCiSymkeyMng.java @@ -34,6 +34,10 @@ public class NiceCiSymkeyMng { @Column(nullable = false, length = 32) private String symkey; + @Schema(required = false, title = "만료일시", example = " ", description = "yyyyMMddHHmmss 포맷") + @Column(nullable = true, length = 14) + private String expireDt; + @Schema(required = false, title = "버전", example = " ", description = "대칭키 현재 버전") @Column(nullable = true, length = 50) private String version; 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 c5ef2b6..696c8b2 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 @@ -18,6 +18,8 @@ import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Optional; @Log4j2 @@ -80,12 +82,15 @@ public class NiceCiGenerator { //현재 대칭키 조회(by 공개키) Optional niceCiSymkeyMng = niceCiSymkeyMngRepository.findByPubkey(pubkeyResponseVO.getResultInfo().getPublicKey()); - if (niceCiSymkeyMng.isPresent()) { + //대칭키 유효기간만료일이 1일 이상 남았으면 + if (niceCiSymkeyMng.isPresent() + &&(Long.parseLong(niceCiSymkeyMng.get().getExpireDt()) > Long.parseLong(LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))) ) { dataBodySymkeyResp = mapper.readValue(niceCiSymkeyMng.get().getRespJsonData(), DataBodySymkeyResp.class); //대칭키 싱글톤 객체 초기화 SymmetricKey.getInstance(dataBodySymkeyResp); + } else { //3. 대칭키 등록 요청 NiceCiRespVO symkeyResponseVO = executor.symkey(); @@ -97,6 +102,7 @@ public class NiceCiGenerator { niceCiSymkeyMngRepository.save(NiceCiSymkeyMng.builder() .pubkey(pubkeyResponseVO.getResultInfo().getPublicKey()) .symkey(dataBodySymkeyResp.getKey()) + .expireDt(dataBodySymkeyResp.getSymkeyStatInfo().getCurValidDtim()) .version(dataBodySymkeyResp.getSymkeyStatInfo().getCurSymkeyVersion()) .iv(dataBodySymkeyResp.getIv()) .hmacKey(dataBodySymkeyResp.getHmacKey()) diff --git a/src/main/java/cokr/xit/ci/api/service/support/rest/utils/SymmetricKey.java b/src/main/java/cokr/xit/ci/api/service/support/rest/utils/SymmetricKey.java index 97e338c..1e94bfc 100644 --- a/src/main/java/cokr/xit/ci/api/service/support/rest/utils/SymmetricKey.java +++ b/src/main/java/cokr/xit/ci/api/service/support/rest/utils/SymmetricKey.java @@ -10,9 +10,7 @@ public class SymmetricKey { private volatile static SymmetricKey instance; private static DataBodySymkeyResp data; - // private static String key; -// private static String version; - private static Long expireDt; +// private static Long expireDt; // private SymkeyInfo() { // @@ -31,7 +29,7 @@ public class SymmetricKey { private SymmetricKey(DataBodySymkeyResp data) { this.data = data; // this.expireDt = Long.parseLong(LocalDateTime.now().plusMonths(5L).format(DateTimeFormatter.ofPattern("yyyyMMdd"))); - this.expireDt = Long.parseLong(LocalDateTime.now().plusDays(1L).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); +// this.expireDt = Long.parseLong(LocalDateTime.now().plusDays(1L).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); } public static SymmetricKey getInstance() { @@ -54,7 +52,9 @@ public class SymmetricKey { return false; if (data == null) return false; - if (expireDt < Long.parseLong(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")))) +// if (expireDt < Long.parseLong(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")))) + //유효기간 만료일까지 1일 미만이면.. + if (Long.parseLong(data.getSymkeyStatInfo().getCurValidDtim()) < Long.parseLong(LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))) return false; return true; @@ -65,7 +65,7 @@ public class SymmetricKey { return data; } - public Long getExpireDe(){ - return expireDt; - } +// public Long getExpireDe(){ +// return expireDt; +// } }