Niceon 암호화 key 생성 수정
This commit is contained in:
+40
-10
@@ -91,7 +91,7 @@ import com.kjbank.encrypt.exchange.crypto.AES256GCMCipher;
|
||||
import com.kjbank.encrypt.exchange.crypto.ECDHESA256Cipher;
|
||||
import com.eactive.eai.authserver.service.OAuth2Manager;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* 1. 기능 : EAI HTTP OutBound 용 어댑터로 수동 시스템의 HTTP 웹 컴포넌트를 GET/POST 방식으로 호출할 수 있는
|
||||
@@ -325,9 +325,10 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
if ( niceToken == null || niceToken == "") {
|
||||
throw new Exception("NiceOn Token is empty, TOKEN failed to be issued, TOKEN = [" + niceToken + "]");
|
||||
}
|
||||
String clientId = JwtClientIdExtractor(niceToken);
|
||||
String clientId = accessToken.getClientId(); // HttpClientAccessTokenServiceWithBase64NiceOn 서 넣어줌
|
||||
long currentTime = System.currentTimeMillis();
|
||||
auth = niceToken + ":" + currentTime + ":" + clientId ;
|
||||
logger.debug("HttpClientAdapterServiceRest] NiceOn auth = [" + auth + "]");
|
||||
auth = Base64.getEncoder().encodeToString(auth.getBytes("UTF-8"));
|
||||
|
||||
setNiceOnAuthHeaders(method, auth);
|
||||
@@ -853,21 +854,50 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
jwtToken = authorization.substring(7); // "Bearer " 이후의 JWT만 추출
|
||||
}
|
||||
|
||||
|
||||
String headerRelay = PropManager.getInstance().getProperty("HEADER_RELAY_ADAPTER","adapter.name");
|
||||
Set<String> values = new HashSet<>(Arrays.asList(headerRelay.split(",")));
|
||||
String inputAdapter = tempProp.getProperty(HttpAdapterServiceKey.OUT_ADAPTER_GROUP_NAME, "");
|
||||
|
||||
String[] parts = inputAdapter.split("_");
|
||||
String target = parts[1]; // adapter name의 앞의 3자리
|
||||
String adapterName = target.substring(0, 3);
|
||||
|
||||
if (values.contains(adapterName)) {
|
||||
|
||||
/* 업체정보 */
|
||||
String clientId = JwtClientIdExtractor(jwtToken);
|
||||
method.setHeader("clientId", clientId);
|
||||
|
||||
/* APIM 거래추적자 */
|
||||
String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
|
||||
method.setHeader("traceId", uuid);
|
||||
|
||||
/* GUID */
|
||||
String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
|
||||
method.setHeader("guid", guid);
|
||||
|
||||
/* 최초요청시간 */
|
||||
String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
|
||||
method.setHeader("receivedTimestamp", receivedTimestamp);
|
||||
}
|
||||
|
||||
|
||||
/* 업체정보 */
|
||||
String clientId = JwtClientIdExtractor(jwtToken);
|
||||
method.setHeader("clientId", clientId);
|
||||
//String clientId = JwtClientIdExtractor(jwtToken);
|
||||
//method.setHeader("clientId", clientId);
|
||||
|
||||
/* APIM 거래추적자 */
|
||||
String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
|
||||
method.setHeader("traceId", uuid);
|
||||
//String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
|
||||
//method.setHeader("traceId", uuid);
|
||||
|
||||
/* GUID */
|
||||
String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
|
||||
method.setHeader("guid", guid);
|
||||
//String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
|
||||
//method.setHeader("guid", guid);
|
||||
|
||||
/* 최초요청시간 */
|
||||
String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
|
||||
method.setHeader("receivedTimestamp", receivedTimestamp);
|
||||
//String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
|
||||
//method.setHeader("receivedTimestamp", receivedTimestamp);
|
||||
|
||||
return jwtToken;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public interface HttpAdapterServiceKey {
|
||||
static final String INBOUND_REQUESTED_TIME = "INBOUND_REQUESTED_TIME"; // jwhong
|
||||
static final String GUID = "GUID"; // jwhong
|
||||
static final String API_SERVICE_CODE = "API_SERVICE_CODE"; // jwhong
|
||||
static final String OUT_ADAPTER_GROUP_NAME = "OUT_ADAPTER_GROUP_NAME"; // jwhong
|
||||
|
||||
//응답 처리 용 표준 전문 오브젝트
|
||||
static final String STANDARD_MESSAGE_OBJECT = "STANDARD_MESSAGE_OBJECT";
|
||||
|
||||
+27
-21
@@ -115,12 +115,11 @@ public class HttpClientAccessTokenServiceWithBase64NiceOn implements HttpClientA
|
||||
uri, encode, timeout, connectionTimeout, useForwardProxy, forwardProxyUrl);
|
||||
|
||||
List<NameValuePair> formParams = new ArrayList<>();
|
||||
formParams.add(new BasicNameValuePair("client_id", oAuthCredentialVo.getClientId()));
|
||||
formParams.add(new BasicNameValuePair("client_secret", oAuthCredentialVo.getClientSecret()));
|
||||
formParams.add(new BasicNameValuePair("scope", oAuthCredentialVo.getScope()));
|
||||
//formParams.add(new BasicNameValuePair("client_id", oAuthCredentialVo.getClientId()));
|
||||
//formParams.add(new BasicNameValuePair("client_secret", oAuthCredentialVo.getClientSecret()));
|
||||
formParams.add(new BasicNameValuePair("grant_type", oAuthCredentialVo.getGrantType()));
|
||||
|
||||
String postParameters = "client_id=" + oAuthCredentialVo.getClientId() + "&client_secret=" + oAuthCredentialVo.getClientSecret() + "&scope=" + oAuthCredentialVo.getScope() + "&grant_type=" + oAuthCredentialVo.getGrantType();
|
||||
formParams.add(new BasicNameValuePair("scope", oAuthCredentialVo.getScope()));
|
||||
//String postParameters = "grant_type=" + oAuthCredentialVo.getGrantType() + "&scope=" + oAuthCredentialVo.getScope();
|
||||
|
||||
|
||||
// mTLS config with default connection parameters
|
||||
@@ -198,9 +197,9 @@ public class HttpClientAccessTokenServiceWithBase64NiceOn implements HttpClientA
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();) {
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
//httpPost.setEntity(new UrlEncodedFormEntity(formParams, charset));
|
||||
httpPost.setEntity(new StringEntity(postParameters, StandardCharsets.UTF_8));
|
||||
httpPost.setHeader("Content-Type", contentType+" charset=" + encode);
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(formParams, charset));
|
||||
//httpPost.setEntity(new StringEntity(postParameters, StandardCharsets.UTF_8));
|
||||
httpPost.setHeader("Content-Type", contentType+";charset=" + encode); // 중간에 ; 주어야 함
|
||||
|
||||
//HTTP HEADER에 client id, client secret를 base64Encode 한 후 추가
|
||||
String cId = oAuthCredentialVo.getClientId();
|
||||
@@ -228,32 +227,38 @@ public class HttpClientAccessTokenServiceWithBase64NiceOn implements HttpClientA
|
||||
.setResponseTimeout(Timeout.ofMilliseconds(timeout)).build();
|
||||
httpPost.setConfig(requestConfig);
|
||||
|
||||
logger.debug("uri = [" + uri + "]");
|
||||
logger.debug("oauthClientId = [" + oAuthCredentialVo.getClientId() + "]");
|
||||
logger.debug("oauthClientSecret = [" + oAuthCredentialVo.getClientSecret() + "]");
|
||||
logger.debug("oauthScope = [" + oAuthCredentialVo.getScope() + "]");
|
||||
logger.debug("oauthGrantType = [" + oAuthCredentialVo.getGrantType() + "]");
|
||||
logger.debug("oauthauthValue = [" + authValue + "]");
|
||||
logger.debug("uri = [" + uri + "]");
|
||||
logger.debug("oauthClientId = [" + oAuthCredentialVo.getClientId() + "]");
|
||||
logger.debug("oauthClientSecret = [" + oAuthCredentialVo.getClientSecret() + "]");
|
||||
logger.debug("oauthScope = [" + oAuthCredentialVo.getScope() + "]");
|
||||
logger.debug("oauthGrantType = [" + oAuthCredentialVo.getGrantType() + "]");
|
||||
logger.debug("oauthauthValue = [" + authValue + "]");
|
||||
logger.debug("oauthauthEncodedAuth = [" + encodedAuth + "]");
|
||||
logger.debug("contentType = [" + contentType + "]");
|
||||
logger.debug("encode = [" + encode + "]");
|
||||
logger.debug("contentType = [" + contentType + "]");
|
||||
logger.debug("encode = [" + encode + "]");
|
||||
|
||||
OAuth2AccessTokenVO accessToken = new OAuth2AccessTokenVO();
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||
if (response.getCode() != 200) {
|
||||
throw new Exception("NiceOn token receive status fail value= " + response.getCode());
|
||||
throw new Exception("NiceOn token receive status fail value== " + response.getCode());
|
||||
}
|
||||
|
||||
logger.info("HttpClientAccessTokenServiceWithBase64NiceOn==>" + response.getCode());
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
String responseString = EntityUtils.toString(entity, encode);
|
||||
logger.debug("Base64NiceOn oauthToken RECV = [" + responseString + "]");
|
||||
logger.debug("Base64NiceOn oauthToken RECV == [" + responseString + "]");
|
||||
|
||||
if (StringUtils.isNotBlank(responseString)) {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode responseJSON = objectMapper.readTree(responseString);
|
||||
JsonNode responseJSONRtn = objectMapper.readTree(responseString);
|
||||
JsonNode responseJSON = null;
|
||||
String gwRsltCd = responseJSONRtn.get("dataHeader").get("GW_RSLT_CD").asText();
|
||||
|
||||
if ("1200".equals(gwRsltCd)) {
|
||||
responseJSON = responseJSONRtn.get("dataBody");
|
||||
}
|
||||
|
||||
if (responseJSON.has("access_token") && responseJSON.has("token_type")
|
||||
&& responseJSON.has("expires_in") && responseJSON.has("scope")) {
|
||||
@@ -263,13 +268,14 @@ public class HttpClientAccessTokenServiceWithBase64NiceOn implements HttpClientA
|
||||
long expiresIn = responseJSON.get("expires_in").asLong();
|
||||
accessToken.setExpiration(new Date(currentTime + expiresIn * 1000L));
|
||||
accessToken.setScope(responseJSON.get("scope").asText());
|
||||
accessToken.setClientId(cId);
|
||||
}
|
||||
|
||||
if (responseJSON.has("client_use_code")) {
|
||||
accessToken.setClientUseCode(responseJSON.get("client_use_code").asText());
|
||||
}
|
||||
|
||||
logger.debug("oauthToken =" + accessToken.toString());
|
||||
logger.debug("NiceOn oauthToken =" + accessToken.toString());
|
||||
|
||||
return accessToken;
|
||||
} else {
|
||||
@@ -277,7 +283,7 @@ public class HttpClientAccessTokenServiceWithBase64NiceOn implements HttpClientA
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("[HttpClientAccessTokenServiceWithBase64NiceOn] retrieve accessToken exception :" + e.getMessage());
|
||||
logger.error("[HttpClientAccessTokenServiceWithBase64NiceOn] retrieve accessToken exception :" + e.getMessage());
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user