Niceon token발생 관련수정
This commit is contained in:
+56
-31
@@ -306,7 +306,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
|||||||
accessToken = (OAuth2AccessTokenVO) tokenManager.getAccessTokenVO(vo.getAdapterGroupName());
|
accessToken = (OAuth2AccessTokenVO) tokenManager.getAccessTokenVO(vo.getAdapterGroupName());
|
||||||
|
|
||||||
// 토큰이 없거나 만료 됐으면 재발급
|
// 토큰이 없거나 만료 됐으면 재발급
|
||||||
if (accessToken == null || accessToken.isExpired()) {
|
//if (accessToken == null || accessToken.isExpired()) {
|
||||||
|
if (accessToken == null || accessToken.isExpired() || accessToken.getAccessToken() == null ) { // jwhong
|
||||||
String oldToken = accessToken == null ? null : accessToken.getAccessToken();
|
String oldToken = accessToken == null ? null : accessToken.getAccessToken();
|
||||||
accessToken = (OAuth2AccessTokenVO) tokenManager.retryAccessTokenVO(vo.getAdapterGroupName(), prop,
|
accessToken = (OAuth2AccessTokenVO) tokenManager.retryAccessTokenVO(vo.getAdapterGroupName(), prop,
|
||||||
oldToken);
|
oldToken);
|
||||||
@@ -321,6 +322,9 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
|||||||
String encryptAlgorithm = properties.getProperty("ENCRYPT_ALGORITHM"); // jwhong
|
String encryptAlgorithm = properties.getProperty("ENCRYPT_ALGORITHM"); // jwhong
|
||||||
if (useAdapterToken && "AES256-NICEON".equals(encryptAlgorithm)) {
|
if (useAdapterToken && "AES256-NICEON".equals(encryptAlgorithm)) {
|
||||||
String niceToken = accessToken.getAccessToken();
|
String niceToken = accessToken.getAccessToken();
|
||||||
|
if ( niceToken == null || niceToken == "") {
|
||||||
|
throw new Exception("NiceOn Token is empty, toke failed to be issued, TOKEN = [" + niceToken + "]");
|
||||||
|
}
|
||||||
String clientId = JwtClientIdExtractor(niceToken);
|
String clientId = JwtClientIdExtractor(niceToken);
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
auth = niceToken + ":" + currentTime + ":" + clientId ;
|
auth = niceToken + ":" + currentTime + ":" + clientId ;
|
||||||
@@ -827,46 +831,67 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
|||||||
// map에 담기
|
// map에 담기
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
for (String entry : entries) {
|
for (String entry : entries) {
|
||||||
String[] kv = entry.split("=", 2);
|
String[] kv = entry.split("=", 2);
|
||||||
if (kv.length == 2) {
|
if (kv.length == 2) {
|
||||||
map.put(kv[0].trim(), kv[1].trim());
|
map.put(kv[0].trim(), kv[1].trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String k : map.keySet()) {
|
for (String k : map.keySet()) {
|
||||||
if (k.equalsIgnoreCase("authorization")) {
|
if (k.equalsIgnoreCase("authorization")) {
|
||||||
authorization = map.get(k);
|
authorization = map.get(k);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
String jwtToken = "";
|
String jwtToken = "";
|
||||||
|
|
||||||
if (authorization != null && authorization.startsWith("Bearer ")) {
|
if (authorization != null && authorization.startsWith("Bearer ")) {
|
||||||
jwtToken = authorization.substring(7); // "Bearer " 이후의 JWT만 추출
|
jwtToken = authorization.substring(7); // "Bearer " 이후의 JWT만 추출
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 업체정보 */
|
/* 업체정보 */
|
||||||
String clientId = JwtClientIdExtractor(jwtToken);
|
String clientId = JwtClientIdExtractor(jwtToken);
|
||||||
method.setHeader("clientId", clientId);
|
method.setHeader("clientId", clientId);
|
||||||
|
|
||||||
/* APIM 거래추적자 */
|
/* APIM 거래추적자 */
|
||||||
String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
|
String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
|
||||||
method.setHeader("traceId", uuid);
|
method.setHeader("traceId", uuid);
|
||||||
|
|
||||||
/* GUID */
|
/* GUID */
|
||||||
String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
|
String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
|
||||||
method.setHeader("guid", guid);
|
method.setHeader("guid", guid);
|
||||||
|
|
||||||
/* 최초요청시간 */
|
/* 최초요청시간 */
|
||||||
String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
|
String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
|
||||||
method.setHeader("receivedTimestamp", receivedTimestamp);
|
method.setHeader("receivedTimestamp", receivedTimestamp);
|
||||||
|
|
||||||
return jwtToken;
|
return jwtToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> parseInboundHeader(String str) {
|
||||||
|
java.util.HashMap<String, String> map = new java.util.HashMap<>();
|
||||||
|
if (str == null || str.isEmpty()) return map;
|
||||||
|
|
||||||
|
// 중괄호 제거
|
||||||
|
str = str.trim();
|
||||||
|
if (str.startsWith("{") && str.endsWith("}")) {
|
||||||
|
str = str.substring(1, str.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// key=value 쌍 분리
|
||||||
|
String[] pairs = str.split(",");
|
||||||
|
for (String pair : pairs) {
|
||||||
|
String[] kv = pair.split("=", 2);
|
||||||
|
if (kv.length == 2) {
|
||||||
|
map.put(kv[0].trim(), kv[1].trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void assignPostBody(Object eaiBody, String contentType, String charset, HttpUriRequestBase method, String adapterName, String niceAuth, String inboundToken) {
|
private void assignPostBody(Object eaiBody, String contentType, String charset, HttpUriRequestBase method, String adapterName, String niceAuth, String inboundToken) {
|
||||||
|
|||||||
+9
-5
@@ -114,9 +114,7 @@ public class HttpClientAccessTokenServiceWithBase64Header implements HttpClientA
|
|||||||
"uri:{}, charset:{}, transactionTimeout:{}, connectionTimeout:{}, useForwardProxy:{}, forwardProxyUrl:{}",
|
"uri:{}, charset:{}, transactionTimeout:{}, connectionTimeout:{}, useForwardProxy:{}, forwardProxyUrl:{}",
|
||||||
uri, encode, timeout, connectionTimeout, useForwardProxy, forwardProxyUrl);
|
uri, encode, timeout, connectionTimeout, useForwardProxy, forwardProxyUrl);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// mTLS config with default connection parameters
|
// mTLS config with default connection parameters
|
||||||
boolean useMtls = StringUtils.equalsIgnoreCase(adapterProp.getProperty(HttpClientAdapterServiceKey.USE_MTLS),
|
boolean useMtls = StringUtils.equalsIgnoreCase(adapterProp.getProperty(HttpClientAdapterServiceKey.USE_MTLS),
|
||||||
"Y");
|
"Y");
|
||||||
@@ -237,17 +235,19 @@ public class HttpClientAccessTokenServiceWithBase64Header implements HttpClientA
|
|||||||
logger.debug("contentType = [" + contentType + "]");
|
logger.debug("contentType = [" + contentType + "]");
|
||||||
logger.debug("encode = [" + encode + "]");
|
logger.debug("encode = [" + encode + "]");
|
||||||
|
|
||||||
|
OAuth2AccessTokenVO accessToken = new OAuth2AccessTokenVO();
|
||||||
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||||
if (response.getCode() != 200) {
|
if (response.getCode() != 200) {
|
||||||
throw new Exception("OAuth token receive status fail value= " + response.getCode());
|
throw new Exception("OAuth token receive status fail value= " + response.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("HttpClientAccessTokenServiceWithBase64Header==>" + response.getCode());
|
||||||
|
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
String responseString = EntityUtils.toString(entity, encode);
|
String responseString = EntityUtils.toString(entity, encode);
|
||||||
logger.debug("oauthToken RECV = [" + responseString + "]");
|
logger.debug("Base64Header oauthToken RECV = [" + responseString + "]");
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(responseString)) {
|
if (StringUtils.isNotBlank(responseString)) {
|
||||||
OAuth2AccessTokenVO accessToken = new OAuth2AccessTokenVO();
|
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
JsonNode responseJSON = objectMapper.readTree(responseString);
|
JsonNode responseJSON = objectMapper.readTree(responseString);
|
||||||
@@ -272,6 +272,10 @@ public class HttpClientAccessTokenServiceWithBase64Header implements HttpClientA
|
|||||||
} else {
|
} else {
|
||||||
throw new Exception("oauth token return null");
|
throw new Exception("oauth token return null");
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error("[HttpClientAccessTokenServiceWithBase64Header] retrieve accessToken exception :" + e.getMessage());
|
||||||
|
return accessToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user