From 01a2a82c4212080b439f98e3f52b524a1a854515 Mon Sep 17 00:00:00 2001 From: minkyu1128 Date: Wed, 11 May 2022 10:00:04 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A9=80=ED=8B=B0=EC=93=B0=EB=A0=88=EB=93=9C?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=EC=97=90=EC=84=9C=201=EB=B2=88=EC=9D=98?= =?UTF-8?q?=20=EC=B4=88=EA=B8=B0=ED=99=94=EB=A7=8C=20=EC=A7=84=ED=96=89?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/ci/api/service/NiceCiService.java | 8 +++- .../api/service/support/NiceCiGenerator.java | 44 +++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/main/java/cokr/xit/ci/api/service/NiceCiService.java b/src/main/java/cokr/xit/ci/api/service/NiceCiService.java index 3ca874a..cff9f0d 100644 --- a/src/main/java/cokr/xit/ci/api/service/NiceCiService.java +++ b/src/main/java/cokr/xit/ci/api/service/NiceCiService.java @@ -3,6 +3,7 @@ package cokr.xit.ci.api.service; import cokr.xit.ci.api.code.ErrCd; import cokr.xit.ci.api.model.ResponseVO; import cokr.xit.ci.api.service.support.NiceCiGenerator; +import cokr.xit.ci.api.service.support.rest.utils.SymmetricKey; import cokr.xit.ci.api.service.support.socket.Interop; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -13,6 +14,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Slf4j @@ -37,6 +39,7 @@ public class NiceCiService { * @return */ public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List jids) { + AtomicInteger i = new AtomicInteger(); return ResponseVO.builder() .errCode(ErrCd.OK) .errMsg(ErrCd.OK.getCodeNm()) @@ -67,7 +70,10 @@ public class NiceCiService { ======================== */ if("socket".equals(type)) { responseVO = Interop.getCI(siteCode, sitePw, jid); - }else{ + }else if("rest".equals(type)){ + if(0 == i.getAndIncrement()) + if(!SymmetricKey.isValidStat()) + niceCiGenerator.initialKey(); responseVO = niceCiGenerator.getCI(jid, null); } 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 6aeb0d9..c5ef2b6 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 @@ -45,18 +45,9 @@ public class NiceCiGenerator { @Value("${contract.nice.ci.rest.api.ci}") private String API_CI; - public ResponseVO getCI(String jid, String clientIp) { + public ResponseVO initialKey(){ - NiceCiApiExecutor executor = NiceCiApiExecutor.builder() - .HOST(this.HOST) - .CLIENT_ID(this.CLIENT_ID) - .CLIENT_SECRET(this.CLIENT_SECRET) - .API_GENERATE_TOKEN(this.API_GENERATE_TOKEN) - .API_REVOKE_TOKEN(this.API_REVOKE_TOKEN) - .API_PUBLICKEY(this.API_PUBLICKEY) - .API_SYMMETRICKEY(this.API_SYMMETRICKEY) - .API_CI(this.API_CI) - .build(); + NiceCiApiExecutor executor = buildExecutor(); try { /* ========================================================================== @@ -74,13 +65,13 @@ public class NiceCiGenerator { return ResponseVO.builder().errCode(ErrCd.ERR600).errMsg(pubkeyResponseVO.getErrCode().getCode() + " " + pubkeyResponseVO.getErrMsg()).build(); /* ========================================================================== - * 3. 대칭키 등록 요청 + * 3. 대칭키 등록 요청 * -. 대칭키는 1일 1회만 등록이 가능하며, 1일 2회 이상 등록요청 시 "0099 기타오류" 가 발생 하므로 * -. 등록요청에 성공한 대칭키는 DB에 저장하여, 서버 재기동 시에도 휘발되지 않도록 한다. ========================================================================== */ // NiceCiRespVO symkeyResponseVO = executor.symkey(); // if (!NiceCiApiCd.OK.equals(symkeyResponseVO.getErrCode())) -// return ResponseVO.builder().errCode(ErrCd.ERR600).errMsg(symkeyResponseVO.getErrCode().getCode() + " " + symkeyResponseVO.getErrMsg()).build(); +// return ResponseVO.errRsltBuilder().errCode(ErrCd.ERR600).errMsg(symkeyResponseVO.getErrCode().getCode() + " " + symkeyResponseVO.getErrMsg()).build(); ObjectMapper mapper = new ObjectMapper(); DataBodySymkeyResp dataBodySymkeyResp = null; if (SymmetricKey.isValidStat()) { @@ -114,11 +105,23 @@ public class NiceCiGenerator { } } + + return ResponseVO.builder().errCode(ErrCd.OK).errMsg(ErrCd.OK.getCodeNm()).build(); + } catch (Exception e) { + return ResponseVO.builder().errCode(ErrCd.ERR699).errMsg(e.getMessage()).build(); + } + } + + public ResponseVO getCI(String jid, String clientIp) { + + NiceCiApiExecutor executor = this.buildExecutor(); + try { + /* ========================================================================== * 4. 아이핀 CI 요청 ========================================================================== */ NiceCiRespVO ciResponseVO = executor.ci(jid, clientIp); - if (!NiceCiApiCd.OK.equals(pubkeyResponseVO.getErrCode())) + if (!NiceCiApiCd.OK.equals(ciResponseVO.getErrCode())) return ResponseVO.builder().errCode(ErrCd.ERR600).errMsg(ciResponseVO.getErrCode().getCode() + " " + ciResponseVO.getErrMsg()).build(); @@ -127,4 +130,17 @@ public class NiceCiGenerator { return ResponseVO.builder().errCode(ErrCd.ERR699).errMsg(e.getMessage()).build(); } } + + private NiceCiApiExecutor buildExecutor(){ + return NiceCiApiExecutor.builder() + .HOST(this.HOST) + .CLIENT_ID(this.CLIENT_ID) + .CLIENT_SECRET(this.CLIENT_SECRET) + .API_GENERATE_TOKEN(this.API_GENERATE_TOKEN) + .API_REVOKE_TOKEN(this.API_REVOKE_TOKEN) + .API_PUBLICKEY(this.API_PUBLICKEY) + .API_SYMMETRICKEY(this.API_SYMMETRICKEY) + .API_CI(this.API_CI) + .build(); + } }