대칭키 유효기한 만료일시 체크로직 수정

master
minkyu1128 3 years ago
parent 96327fd687
commit a3907e152b

@ -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;

@ -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> 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<DataBodySymkeyResp> 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())

@ -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;
// }
}

Loading…
Cancel
Save