From 5357eb8f635bcaccf6a76453664a825a73ff0d02 Mon Sep 17 00:00:00 2001 From: jaewohong Date: Tue, 16 Dec 2025 11:08:36 +0900 Subject: [PATCH] =?UTF-8?q?Niceon=20token=EB=B0=9C=EC=83=9D=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/HttpClient5AdapterServiceRest.java | 87 ++++++++++++------- ...entAccessTokenServiceWithBase64Header.java | 14 +-- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java index 86a47aa..fe84003 100644 --- a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java +++ b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java @@ -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 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 parseInboundHeader(String str) { + java.util.HashMap 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) { diff --git a/src/main/java/com/eactive/eai/authoutbound/client/impl/HttpClientAccessTokenServiceWithBase64Header.java b/src/main/java/com/eactive/eai/authoutbound/client/impl/HttpClientAccessTokenServiceWithBase64Header.java index 295c2f3..07f7864 100644 --- a/src/main/java/com/eactive/eai/authoutbound/client/impl/HttpClientAccessTokenServiceWithBase64Header.java +++ b/src/main/java/com/eactive/eai/authoutbound/client/impl/HttpClientAccessTokenServiceWithBase64Header.java @@ -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; } } }