feat: Nice CI API 반영
parent
3b2458d6cd
commit
ba715b954d
@ -0,0 +1,193 @@
|
||||
package kr.xit.ens.support.nice.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyRequest;
|
||||
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.TokenRequest;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenResDataBody;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenResponse;
|
||||
import kr.xit.core.exception.BizRuntimeException;
|
||||
import kr.xit.core.spring.annotation.TraceLogging;
|
||||
import kr.xit.core.spring.util.ApiWebClientUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.logging.log4j.util.Base64Util;
|
||||
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
*
|
||||
* packageName : kr.xit.ens.support.nice.service
|
||||
* fileName : NiceCiService
|
||||
* author : limju
|
||||
* date : 2023-09-06
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-09-06 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
//FIXME : client_id, client_secret, access_token DB 처리후 반영 필요
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class NiceCiDummyTestService extends EgovAbstractServiceImpl {
|
||||
@Value("${contract.nice.host}")
|
||||
private String HOST;
|
||||
@Value("${contract.nice.client-id}")
|
||||
private String CLIENT_ID;
|
||||
@Value("${contract.nice.client-secret}")
|
||||
private String CLIENT_SECRET;
|
||||
@Value("${contract.nice.api.generate-token}")
|
||||
private String API_GENERATE_TOKEN;
|
||||
@Value("${contract.nice.api.revoke-token}")
|
||||
private String API_REVOKE_TOKEN;
|
||||
@Value("${contract.nice.api.publickey}")
|
||||
private String API_PUBLICKEY;
|
||||
@Value("${contract.nice.api.symmetrickey}")
|
||||
private String API_SYMMETRICKEY;
|
||||
@Value("${contract.nice.api.ci}")
|
||||
private String API_CI;
|
||||
|
||||
private static final String AUTH_TYPE_BASIC = "Basic";
|
||||
private static final String AUTH_TYPE_BEARER = "bearer";
|
||||
|
||||
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||
private final ApiWebClientUtil webClient;
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 기관용 Token
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
@TraceLogging
|
||||
public TokenResponse generateToken(final TokenRequest reqDTO){
|
||||
validate(reqDTO);
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
||||
map.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BASIC, Base64Util.encode(String.format("%s:%s", this.CLIENT_ID, this.CLIENT_SECRET))));
|
||||
|
||||
return TokenResponse.builder()
|
||||
.dataHeader(ResponseDataHeader.builder()
|
||||
.gw_rslt_cd("1200")
|
||||
.gw_rslt_cd("오류없음")
|
||||
.build())
|
||||
.dataBody(TokenResDataBody.builder()
|
||||
.access_token("ff5e27fe-8b5d-49db-ab1e-0ccf07de6ac1")
|
||||
.token_type("bearer")
|
||||
.expires_in(1.57698305E9)
|
||||
.scope("default")
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Authorization : Basic + Base64Encoding(access_token:current_timestamp:client_id)
|
||||
* - access_token : 만료할 access_token
|
||||
* - client_id : access_token발급에 사용된 client_id
|
||||
* - current_timestamp
|
||||
* Date currentDate = new Date();
|
||||
* long current_timestamp = currentDate.getTime() /1000
|
||||
* @param token
|
||||
* @return
|
||||
* </pre>
|
||||
*/
|
||||
@TraceLogging
|
||||
public TokenResponse revokeToken(final String token){
|
||||
return webClient.exchange(
|
||||
HOST + API_GENERATE_TOKEN,
|
||||
HttpMethod.POST,
|
||||
null,
|
||||
TokenResponse.class,
|
||||
getHeaderMap(MediaType.APPLICATION_FORM_URLENCODED_VALUE, AUTH_TYPE_BASIC));
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
// 기관용 Token
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 공개키(Publickey)
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
public PublickeyResponse requestPublickey(final PublickeyRequest reqDTO) {
|
||||
validate(reqDTO);
|
||||
|
||||
return PublickeyResponse.builder()
|
||||
.dataHeader(ResponseDataHeader.builder()
|
||||
.gw_rslt_cd("1200")
|
||||
.gw_rslt_msg("오류없음")
|
||||
.tran_id(reqDTO.getDataHeader().getTran_id())
|
||||
.cnty_id(reqDTO.getDataHeader().getCnty_id())
|
||||
.build())
|
||||
.dataBody(PublickeyResDataBody.builder()
|
||||
.rsp_cd("P000")
|
||||
.rsp_msg("")
|
||||
.result_cd("000")
|
||||
.site_code("AAAA==")
|
||||
.key_version("20210121ca8c1612-2c2d-IPaa-aad1-xxxxxxxxxxxx")
|
||||
.public_key("MIIBIjANBgkqhkiG9w0BAQEFAA.....JJxwIDAQAB...")
|
||||
.valid_dtim("20220121181550")
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 공개키(Publickey)
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
private Map<String,String> getHeaderMap(final String contentType, final String type){
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
||||
map.put(
|
||||
HttpHeaders.AUTHORIZATION,
|
||||
String.format("%s %s",
|
||||
type,
|
||||
Base64Util.encode(
|
||||
String.format("%s:%s:%s",
|
||||
"accessToken",
|
||||
(new Date().getTime() / 1000),
|
||||
this.CLIENT_ID)
|
||||
)
|
||||
)
|
||||
);
|
||||
return map;
|
||||
}
|
||||
|
||||
private static <T> void validate(T t) {
|
||||
Set<ConstraintViolation<T>> list = validator.validate(t);
|
||||
|
||||
if (list.size() > 0) {
|
||||
List<String> errors = list.stream()
|
||||
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
throw BizRuntimeException.create(
|
||||
list.stream()
|
||||
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
|
||||
.collect(Collectors.toList()).toString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package kr.xit.ens.support.nice.web;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyRequest;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.ResponseDataHeader;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenRequest;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenResDataBody;
|
||||
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenResponse;
|
||||
import kr.xit.core.exception.BizRuntimeException;
|
||||
import kr.xit.core.model.ApiResponseDTO;
|
||||
import kr.xit.core.spring.annotation.TraceLogging;
|
||||
import kr.xit.core.support.utils.JsonUtils;
|
||||
import kr.xit.ens.support.nice.service.INiceCiService;
|
||||
import kr.xit.ens.support.nice.service.NiceCiDummyTestService;
|
||||
import kr.xit.ens.support.nice.service.NiceCiService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description :
|
||||
*
|
||||
* packageName : kr.xit.ens.support.nice.web
|
||||
* fileName : NiceCiDummyTestController
|
||||
* author : limju
|
||||
* date : 2023-09-06
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-09-06 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Slf4j
|
||||
@Tag(name = "NiceCiDummyTestController", description = "Nice CI Dummy Test")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/nice/test")
|
||||
public class NiceCiDummyTestController {
|
||||
private final NiceCiDummyTestService service;
|
||||
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 기관용 Token
|
||||
//--------------------------------------------------------------------------------
|
||||
@Operation(summary = "기관용 토큰 발급 요청", description = "기관용 토큰 발급 요청")
|
||||
@PostMapping(value = "/generateToken", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ApiResponseDTO<?> generateToken(
|
||||
@RequestBody final TokenRequest reqDTO
|
||||
) {
|
||||
return ApiResponseDTO.success(service.generateToken(reqDTO));
|
||||
}
|
||||
|
||||
@Operation(summary = "기관용 토큰 폐기", description = "기관용 토큰 폐기")
|
||||
@PostMapping(value = "/revokeToken", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ApiResponseDTO<?> revokeToken(
|
||||
@RequestParam final String accessToken
|
||||
) {
|
||||
return ApiResponseDTO.success(service.revokeToken(accessToken));
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
// 기관용 Token
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 공개키(Publickey)
|
||||
//--------------------------------------------------------------------------------
|
||||
/*@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
|
||||
@Content(mediaType = "application/json", examples = {
|
||||
@ExampleObject(value = """
|
||||
{
|
||||
"dataHeader": {
|
||||
"TRAN_ID": "20201119140000",
|
||||
"CNTY_ID": "kr"
|
||||
},
|
||||
"dataBody": {
|
||||
"req_dtim": "2023090612122259"
|
||||
}
|
||||
}
|
||||
""")
|
||||
})
|
||||
})*/
|
||||
@Operation(summary = "공개키 요청", description = "공개키 요청")
|
||||
@PostMapping(value = "/requestPublickey", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ApiResponseDTO<?> requestPublickey(
|
||||
@RequestBody final PublickeyRequest reqDTO
|
||||
) {
|
||||
return ApiResponseDTO.success(service.requestPublickey(reqDTO));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// 공개키(Publickey)
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue