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(); + } }