Niceon token발생 관련수정
This commit is contained in:
+56
-31
@@ -306,7 +306,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
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();
|
||||
accessToken = (OAuth2AccessTokenVO) tokenManager.retryAccessTokenVO(vo.getAdapterGroupName(), prop,
|
||||
oldToken);
|
||||
@@ -321,6 +322,9 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
String encryptAlgorithm = properties.getProperty("ENCRYPT_ALGORITHM"); // jwhong
|
||||
if (useAdapterToken && "AES256-NICEON".equals(encryptAlgorithm)) {
|
||||
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);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
auth = niceToken + ":" + currentTime + ":" + clientId ;
|
||||
@@ -827,46 +831,67 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
// map에 담기
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String entry : entries) {
|
||||
String[] kv = entry.split("=", 2);
|
||||
if (kv.length == 2) {
|
||||
map.put(kv[0].trim(), kv[1].trim());
|
||||
}
|
||||
String[] kv = entry.split("=", 2);
|
||||
if (kv.length == 2) {
|
||||
map.put(kv[0].trim(), kv[1].trim());
|
||||
}
|
||||
}
|
||||
for (String k : map.keySet()) {
|
||||
if (k.equalsIgnoreCase("authorization")) {
|
||||
authorization = map.get(k);
|
||||
break;
|
||||
}
|
||||
if (k.equalsIgnoreCase("authorization")) {
|
||||
authorization = map.get(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
String jwtToken = "";
|
||||
|
||||
|
||||
if (authorization != null && authorization.startsWith("Bearer ")) {
|
||||
jwtToken = authorization.substring(7); // "Bearer " 이후의 JWT만 추출
|
||||
jwtToken = authorization.substring(7); // "Bearer " 이후의 JWT만 추출
|
||||
}
|
||||
|
||||
|
||||
/* 업체정보 */
|
||||
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);
|
||||
|
||||
return jwtToken;
|
||||
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);
|
||||
|
||||
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")
|
||||
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, encode, timeout, connectionTimeout, useForwardProxy, forwardProxyUrl);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// mTLS config with default connection parameters
|
||||
boolean useMtls = StringUtils.equalsIgnoreCase(adapterProp.getProperty(HttpClientAdapterServiceKey.USE_MTLS),
|
||||
"Y");
|
||||
@@ -237,17 +235,19 @@ public class HttpClientAccessTokenServiceWithBase64Header implements HttpClientA
|
||||
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("OAuth token receive status fail value= " + response.getCode());
|
||||
}
|
||||
|
||||
logger.info("HttpClientAccessTokenServiceWithBase64Header==>" + response.getCode());
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
String responseString = EntityUtils.toString(entity, encode);
|
||||
logger.debug("oauthToken RECV = [" + responseString + "]");
|
||||
logger.debug("Base64Header oauthToken RECV = [" + responseString + "]");
|
||||
|
||||
if (StringUtils.isNotBlank(responseString)) {
|
||||
OAuth2AccessTokenVO accessToken = new OAuth2AccessTokenVO();
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode responseJSON = objectMapper.readTree(responseString);
|
||||
@@ -272,6 +272,10 @@ public class HttpClientAccessTokenServiceWithBase64Header implements HttpClientA
|
||||
} else {
|
||||
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