|
|
|
@ -3,26 +3,21 @@ package kr.xit.biz.nice.service;
|
|
|
|
|
import egovframework.com.cmm.EgovMessageSource;
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
|
|
import kr.xit.biz.cmm.service.CmmEnsCacheService;
|
|
|
|
|
import kr.xit.biz.common.ApiConstants.NiceCiWrkDiv;
|
|
|
|
|
import kr.xit.biz.common.ApiConstants.SignguCode;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.IpinCiResDataBody;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.IpinCiResponse;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.IpinCiResEncData;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.NiceCiInfo;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.NiceCiRequest;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.NiceTokenResponse;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyResDataBody;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyResponse;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.ResponseDataHeader;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.SymkeyRegInfo;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.SymkeyStatInfo;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.SymmetrickeyResDataBody;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.SymmetrickeyResponse;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenResDataBody;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenRevokeResDataBody;
|
|
|
|
|
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenRevokeResponse;
|
|
|
|
|
import kr.xit.biz.nice.mapper.IBizNiceCiMapper;
|
|
|
|
|
import kr.xit.core.exception.BizRuntimeException;
|
|
|
|
|
import kr.xit.core.support.utils.JsonUtils;
|
|
|
|
|
import kr.xit.ens.cmm.CmmEnsUtils;
|
|
|
|
|
import kr.xit.ens.nice.cmm.CmmNiceCiUtils;
|
|
|
|
|
import kr.xit.ens.nice.service.INiceCiService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
@ -58,7 +53,6 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 기관용 Token
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>
|
|
|
|
|
* NICE 토큰 발급 요청
|
|
|
|
@ -76,8 +70,8 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
final ResponseDataHeader dataHeader = tokenResponse.getDataHeader();
|
|
|
|
|
|
|
|
|
|
if(dataHeader.getGwRsltCd().equals("1200")){
|
|
|
|
|
TokenResDataBody dataBody = tokenResponse.getDataBody();
|
|
|
|
|
NiceCiInfo niceDTO = NiceCiInfo.builder()
|
|
|
|
|
final TokenResDataBody dataBody = tokenResponse.getDataBody();
|
|
|
|
|
final NiceCiInfo niceDTO = NiceCiInfo.builder()
|
|
|
|
|
.signguCode(reqDTO.getSignguCode())
|
|
|
|
|
.ffnlgCode(reqDTO.getFfnlgCode())
|
|
|
|
|
.accessToken(dataBody.getAccessToken())
|
|
|
|
@ -91,7 +85,7 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|
cacheService.removeNiceCiInfoCache(niceDTO.getSignguCode(), niceDTO.getFfnlgCode());
|
|
|
|
|
|
|
|
|
|
updateNiceCerfInfoSync(niceDTO, reqDTO);
|
|
|
|
|
updateNiceCerfInfoSync(niceDTO, reqDTO, NiceCiWrkDiv.TOKEN);
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -112,14 +106,14 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
@Transactional
|
|
|
|
|
@Override
|
|
|
|
|
public TokenRevokeResponse revokeToken(final NiceCiRequest reqDTO){
|
|
|
|
|
TokenRevokeResponse resDTO = niceCiService.revokeToken(reqDTO);
|
|
|
|
|
|
|
|
|
|
final TokenRevokeResponse resDTO = niceCiService.revokeToken(reqDTO);
|
|
|
|
|
final ResponseDataHeader dataHeader = resDTO.getDataHeader();
|
|
|
|
|
|
|
|
|
|
if(dataHeader.getGwRsltCd().equals("1200")){
|
|
|
|
|
TokenRevokeResDataBody dataBody = resDTO.getDataBody();
|
|
|
|
|
final TokenRevokeResDataBody dataBody = resDTO.getDataBody();
|
|
|
|
|
|
|
|
|
|
if(dataBody.isResult()){
|
|
|
|
|
NiceCiInfo niceDTO = NiceCiInfo.builder()
|
|
|
|
|
final NiceCiInfo niceDTO = NiceCiInfo.builder()
|
|
|
|
|
.signguCode(reqDTO.getSignguCode())
|
|
|
|
|
.ffnlgCode(reqDTO.getFfnlgCode())
|
|
|
|
|
.accessToken(null)
|
|
|
|
@ -131,7 +125,7 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|
cacheService.removeNiceCiInfoCache(niceDTO.getSignguCode(), niceDTO.getFfnlgCode());
|
|
|
|
|
|
|
|
|
|
updateNiceCerfInfoSync(niceDTO, reqDTO);
|
|
|
|
|
updateNiceCerfInfoSync(niceDTO, reqDTO, NiceCiWrkDiv.TOKEN);
|
|
|
|
|
}else{
|
|
|
|
|
throw BizRuntimeException.create("토큰을 폐기하지 못했습니다.");
|
|
|
|
|
}
|
|
|
|
@ -139,13 +133,10 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
return resDTO;
|
|
|
|
|
}
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 기관용 Token
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 공개키(Publickey)
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>
|
|
|
|
|
* 공개키 요청
|
|
|
|
@ -157,21 +148,13 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
*/
|
|
|
|
|
@Transactional
|
|
|
|
|
@Override
|
|
|
|
|
public PublickeyResponse requestPublickey(final NiceCiRequest reqDTO) {
|
|
|
|
|
public PublickeyResDataBody requestPublickey(final NiceCiRequest reqDTO) {
|
|
|
|
|
final NiceCiInfo niceDTO = CmmNiceCiUtils.getNiceCiInfo(reqDTO);
|
|
|
|
|
if(ObjectUtils.isEmpty(niceDTO.getAccessToken())) throw BizRuntimeException.create(messageSource.getMessage("fail.api.nice.token.info"));
|
|
|
|
|
|
|
|
|
|
final PublickeyResponse pubResDTO = niceCiService.requestPublickey(reqDTO);
|
|
|
|
|
|
|
|
|
|
//FIXME::공개키 정보 갱신 - Error code enum 전환
|
|
|
|
|
final ResponseDataHeader dataHeader = pubResDTO.getDataHeader();
|
|
|
|
|
final PublickeyResDataBody dataBody = pubResDTO.getDataBody();
|
|
|
|
|
final PublickeyResDataBody dataBody = niceCiService.requestPublickey(reqDTO);
|
|
|
|
|
|
|
|
|
|
// 3. 공개키 정보 update
|
|
|
|
|
if(ObjectUtils.isNotEmpty(dataBody)
|
|
|
|
|
&& dataHeader.getGwRsltCd().equals("1200")
|
|
|
|
|
&& dataBody.getRspCd().equals("P000")
|
|
|
|
|
&& dataBody.getResultCd().equals("0000")){
|
|
|
|
|
niceDTO.setSiteCode(dataBody.getSiteCode());
|
|
|
|
|
niceDTO.setKeyVersion(dataBody.getKeyVersion());
|
|
|
|
|
niceDTO.setPublicKey(dataBody.getPublicKey());
|
|
|
|
@ -180,36 +163,15 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|
cacheService.removeNiceCiInfoCache(niceDTO.getSignguCode(), niceDTO.getFfnlgCode());
|
|
|
|
|
|
|
|
|
|
//FIXME:: 교통시설운영처 또는 장사시설인 경우 sync ----------------------------------------
|
|
|
|
|
if(SignguCode.TRAFFIC.getCode().equals(niceDTO.getSignguCode())){
|
|
|
|
|
niceDTO.setSignguCode(SignguCode.FUNERAL.getCode());
|
|
|
|
|
niceCiMapper.updateNiceCrtfPublickey(niceDTO);
|
|
|
|
|
}
|
|
|
|
|
updateNiceCerfInfoSync(niceDTO, reqDTO, NiceCiWrkDiv.PUBLIC_KEY);
|
|
|
|
|
|
|
|
|
|
if(SignguCode.FUNERAL.getCode().equals(niceDTO.getSignguCode())){
|
|
|
|
|
niceDTO.setSignguCode(SignguCode.TRAFFIC.getCode());
|
|
|
|
|
niceCiMapper.updateNiceCrtfPublickey(niceDTO);
|
|
|
|
|
return dataBody;
|
|
|
|
|
}
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|
cacheService.removeNiceCiInfoCache(niceDTO.getSignguCode(), niceDTO.getFfnlgCode());
|
|
|
|
|
cacheService.logCache();
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
return pubResDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//FIXME::에러처리 방안 설정후 적용 할 것
|
|
|
|
|
throw BizRuntimeException.create(JsonUtils.toJson(dataHeader));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 공개키(Publickey)
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 대칭키 : symmetrickey
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>
|
|
|
|
|
* 0. cache call
|
|
|
|
@ -221,25 +183,14 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
*/
|
|
|
|
|
@Transactional
|
|
|
|
|
@Override
|
|
|
|
|
public SymmetrickeyResponse requestRegSymmetrickey(final NiceCiRequest reqDTO) {
|
|
|
|
|
final String signguCode = reqDTO.getSignguCode();
|
|
|
|
|
final String ffnlgCode = reqDTO.getFfnlgCode();
|
|
|
|
|
|
|
|
|
|
//FIXME::NICE 연계이후 메소드 교체
|
|
|
|
|
public SymkeyStatInfo requestRegSymmetrickey(final NiceCiRequest reqDTO) {
|
|
|
|
|
final SymkeyRegInfo symkeyRegInfo = CmmNiceCiUtils.getSymkeyRegInfo();
|
|
|
|
|
SymmetrickeyResponse symResDTO = niceCiService.requestRegSymmetrickey(reqDTO, symkeyRegInfo);
|
|
|
|
|
|
|
|
|
|
final ResponseDataHeader dataHeader = symResDTO.getDataHeader();
|
|
|
|
|
final SymmetrickeyResDataBody dataBody = symResDTO.getDataBody();
|
|
|
|
|
if(dataHeader.getGwRsltCd().equals("1200")
|
|
|
|
|
&& dataBody.getRspCd().equals("P000")
|
|
|
|
|
//FIXME:: "0007" 인 경우 확인 필요 - result_cd 0000, 0007일 경우 나감 (0007: key 중복 오류 (현재 및 직전에 사용한 Key 사용 불가)
|
|
|
|
|
&& dataBody.getResultCd().equals("0000")){
|
|
|
|
|
SymkeyStatInfo symkeyStatInfo = JsonUtils.toObject(dataBody.getSymkeyStatInfo(), SymkeyStatInfo.class);
|
|
|
|
|
NiceCiInfo niceDTO = NiceCiInfo.builder()
|
|
|
|
|
final SymkeyStatInfo symkeyStatInfo = niceCiService.requestRegSymmetrickey(reqDTO, symkeyRegInfo);
|
|
|
|
|
final NiceCiInfo niceDTO = NiceCiInfo.builder()
|
|
|
|
|
.signguCode(reqDTO.getSignguCode())
|
|
|
|
|
.ffnlgCode(reqDTO.getFfnlgCode())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
niceDTO.setBefSymkeyVersion(symkeyStatInfo.getBefSymkeyVersion());
|
|
|
|
|
niceDTO.setBefSymkeyValidDtim(symkeyStatInfo.getBefValidDtim());
|
|
|
|
|
niceDTO.setBefSymkeyKey(niceDTO.getCurSymkeyKey());
|
|
|
|
@ -256,74 +207,54 @@ public class BizNiceCiService extends EgovAbstractServiceImpl implements IBizNic
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|
cacheService.removeNiceCiInfoCache(niceDTO.getSignguCode(), niceDTO.getFfnlgCode());
|
|
|
|
|
|
|
|
|
|
//FIXME:: 교통시설운영처 또는 장사시설인 경우 sync ----------------------------------------
|
|
|
|
|
if(SignguCode.TRAFFIC.getCode().equals(niceDTO.getSignguCode())){
|
|
|
|
|
niceDTO.setSignguCode(SignguCode.FUNERAL.getCode());
|
|
|
|
|
niceCiMapper.updateNiceCrtfSymkey(niceDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(SignguCode.FUNERAL.getCode().equals(niceDTO.getSignguCode())){
|
|
|
|
|
niceDTO.setSignguCode(SignguCode.TRAFFIC.getCode());
|
|
|
|
|
niceCiMapper.updateNiceCrtfSymkey(niceDTO);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|
cacheService.removeNiceCiInfoCache(niceDTO.getSignguCode(), niceDTO.getFfnlgCode());
|
|
|
|
|
cacheService.logCache();
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
return symResDTO;
|
|
|
|
|
updateNiceCerfInfoSync(niceDTO, reqDTO, NiceCiWrkDiv.SYM_KEY);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
throw BizRuntimeException.create(JsonUtils.toJson(symResDTO));
|
|
|
|
|
return symkeyStatInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 대칭키 : symmetrickey
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 아이핀 CI 요청
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
public IpinCiResponse requestCi(final NiceCiRequest reqDTO) {
|
|
|
|
|
IpinCiResponse ipinCiResponse = niceCiService.requestCi(reqDTO);
|
|
|
|
|
|
|
|
|
|
ResponseDataHeader resHeader = ipinCiResponse.getDataHeader();
|
|
|
|
|
IpinCiResDataBody resBody = ipinCiResponse.getDataBody();
|
|
|
|
|
String resEncData = resBody.getEncData();
|
|
|
|
|
//IpinCiResEncData resEncData = JsonUtils.toObject(resBody.getEncData(), IpinCiResEncData.class);
|
|
|
|
|
|
|
|
|
|
//FIXME::응답무결성 체크
|
|
|
|
|
// 응답으로온 intigrety_value와 응답 enc_data를 Hmac한 값을 비교
|
|
|
|
|
// 무결성체크가 완료되면 데이터를 보낸 대칭키로 복호화하여 데이터를 확인
|
|
|
|
|
NiceCiInfo niceDTO = CmmNiceCiUtils.getSymkeyNiceCiInfo(reqDTO);
|
|
|
|
|
String checkHmac = CmmEnsUtils.encodeHmacSha256(niceDTO.getCurSymkeyHmacKey(), resEncData);
|
|
|
|
|
if(resBody.getIntegrityValue().equals(checkHmac)){
|
|
|
|
|
String decData = CmmEnsUtils.decodeAesData(resEncData, niceDTO.getCurSymkeyKey(), niceDTO.getCurSymkeyIv());
|
|
|
|
|
resBody.setEncData(decData);
|
|
|
|
|
}
|
|
|
|
|
return ipinCiResponse;
|
|
|
|
|
public IpinCiResEncData requestCi(final NiceCiRequest reqDTO) {
|
|
|
|
|
return niceCiService.requestCi(reqDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
// 아이핀 CI 요청
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
private void updateNiceCerfInfoSync(final NiceCiInfo niceDTO, final NiceCiRequest reqDTO) {
|
|
|
|
|
//FIXME:: 교통시설운영처 또는 장사시설인 경우 sync ----------------------------------------
|
|
|
|
|
/**
|
|
|
|
|
* <pre>
|
|
|
|
|
* 교통시설운영처와 승화원의 Nice CI 정보 sync
|
|
|
|
|
* @param niceDTO NiceCiInfo
|
|
|
|
|
* @param reqDTO NiceCiRequest
|
|
|
|
|
* @param wrkDiv NiceCiWrkDiv
|
|
|
|
|
* </pre>
|
|
|
|
|
*/
|
|
|
|
|
private void updateNiceCerfInfoSync(final NiceCiInfo niceDTO, final NiceCiRequest reqDTO, final NiceCiWrkDiv wrkDiv) {
|
|
|
|
|
// 교통시설운영처 또는 장사시설인 경우 sync ----------------------------------------
|
|
|
|
|
if(SignguCode.TRAFFIC.getCode().equals(reqDTO.getSignguCode())){
|
|
|
|
|
niceDTO.setSignguCode(SignguCode.FUNERAL.getCode());
|
|
|
|
|
niceCiMapper.updateNiceCrtfToken(niceDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(SignguCode.FUNERAL.getCode().equals(reqDTO.getSignguCode())){
|
|
|
|
|
niceDTO.setSignguCode(SignguCode.TRAFFIC.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(wrkDiv){
|
|
|
|
|
case TOKEN:
|
|
|
|
|
niceCiMapper.updateNiceCrtfToken(niceDTO);
|
|
|
|
|
break;
|
|
|
|
|
case PUBLIC_KEY:
|
|
|
|
|
niceCiMapper.updateNiceCrtfPublickey(niceDTO);
|
|
|
|
|
break;
|
|
|
|
|
case SYM_KEY:
|
|
|
|
|
niceCiMapper.updateNiceCrtfSymkey(niceDTO);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 공개키 정보 캐쉬 삭제
|
|
|
|
|