From 6d75f1870f9fc8729bf551a01e8b4e3ed8e3482d Mon Sep 17 00:00:00 2001 From: "Yunsam.Eo" Date: Sun, 21 Dec 2025 16:24:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Outbound=20Filter=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/HttpClient5AdapterServiceRest.java | 24 ++++++++++++++++++- .../http/dynamic/HttpAdapterServiceKey.java | 2 +- .../com/eactive/eai/outbound/RESTProcess.java | 3 +++ 3 files changed, 27 insertions(+), 2 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 50eb1f9..5c92523 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 @@ -91,6 +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.Map.Entry; import java.util.HashSet; /** @@ -165,6 +166,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // 레이아웃 메시지 타입 REST URL 추출 시 활용. Default JSON String messageType = prop.getProperty("MESSAGE_TYPE", MessageType.JSON); String inboundMethod = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_METHOD, "POST"); + String inboundToken = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_TOKEN, ""); //Outbound 요청에 대한 응답 메시지의 복호화 여부 결정위해 jwhong encryptResponseApply = StringUtils.equalsIgnoreCase(prop.getProperty("ENCRYPT_RESPONSE_APPLY", "N"), "Y"); @@ -349,6 +351,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // 여기 까지 configureHttpClient(requestConfigBuilder, vo, method); + assignFilterHeaders(method, tempProp); // OutBound PreFilter에서 설정한 Header내용 설정. switch (HttpMethodType.getValue(rmethod)) { case GET: @@ -373,7 +376,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // assignPostBody(dataObject, contentType, vo.getEncode(), method); //assignPostBody(dataContent, contentType, vo.getEncode(), method); // jwhong commnet // KJBank API 추적정보를 Header에 제공. jwhong - String inboundToken= assignRequestKJHeaders(method, prop, tempProp ); +// String inboundToken= assignRequestKJHeaders(method, prop, tempProp ); Filter에서 처리함. assignPostBody(dataContent, contentType, vo.getEncode(), method, vo.getAdapterName(), auth, inboundToken); break; default: @@ -804,6 +807,25 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp } } } + + private void assignFilterHeaders(HttpUriRequestBase method, Properties tempProp) { + try { + Properties filterHeaders = (Properties)tempProp.get("FILTERHEADER"); + if (filterHeaders != null){ + for (Entry e : filterHeaders.entrySet()) { + String key = (String) e.getKey(); + String value = (String) e.getValue(); + method.setHeader(key, value); + + if (logger.isDebugEnabled()) { + logger.debug("OutBound Filter] Request Header :" + key + "=[" + value + "]"); + } + } + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + } /* * KJBank Target System으로 요청 보낼때 header에 clientId(업체정보), APIM거래추적자(UUID), 최초 요청시간, guid 추가해서 보낸다. jwhong diff --git a/src/main/java/com/eactive/eai/adapter/http/dynamic/HttpAdapterServiceKey.java b/src/main/java/com/eactive/eai/adapter/http/dynamic/HttpAdapterServiceKey.java index cbc6ad4..c617084 100644 --- a/src/main/java/com/eactive/eai/adapter/http/dynamic/HttpAdapterServiceKey.java +++ b/src/main/java/com/eactive/eai/adapter/http/dynamic/HttpAdapterServiceKey.java @@ -73,7 +73,7 @@ public interface HttpAdapterServiceKey { static final String ENC_PATHS = "ENC_PATHS"; static final String ENCRYPT_ALGORITHM = "ENCRYPT_ALGORITHM"; //jwhong - static final String INBOUND_TOKEN = "authorization"; // jwhong + static final String INBOUND_TOKEN = "AUTHORIZATION"; // jwhong static final String ENCRYPT_BASE_TYPE = "ENCRYPT_BASE_TYPE"; // jwhong static final String ENCRYPT_AES256_IV = "ENCRYPT_AES256_IV"; // jwhong static final String ENCRYPT_AES256_KEY = "ENCRYPT_AES256_KEY"; // jwhong diff --git a/src/main/java/com/eactive/eai/outbound/RESTProcess.java b/src/main/java/com/eactive/eai/outbound/RESTProcess.java index bc4f0cf..5d364ee 100644 --- a/src/main/java/com/eactive/eai/outbound/RESTProcess.java +++ b/src/main/java/com/eactive/eai/outbound/RESTProcess.java @@ -21,6 +21,7 @@ import com.eactive.eai.adapter.AdapterVO; import com.eactive.eai.adapter.http.HttpStatusException; import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey; import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey; +import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceSupport; import com.eactive.eai.common.EAIKeys; import com.eactive.eai.common.exception.ExceptionUtil; import com.eactive.eai.common.header.HeaderAction; @@ -441,6 +442,8 @@ public class RESTProcess extends HTTPProcess { PropertiesUtil.copyPropertyIfPresent(this.callProp, this.tempProp, HttpAdapterServiceKey.INBOUND_SCHEME); PropertiesUtil.copyPropertyIfPresent(this.callProp, this.tempProp, HttpAdapterServiceKey.INBOUND_REQUESTED_TIME); // jwhong PropertiesUtil.copyPropertyIfPresent(this.callProp, this.tempProp, HttpAdapterServiceKey.GUID); // jwhong + PropertiesUtil.copyPropertyIfPresent(this.callProp, this.tempProp, HttpAdapterServiceKey.INBOUND_TOKEN); // jwhong + PropertiesUtil.copyPropertyIfPresent(this.callProp, this.tempProp, HttpAdapterServiceSupport.PROPERTIES_NAME_CLIENT_ID); // jwhong String svcName = getServiceId(this.reqEaiMsg); if (svcName == null) { From 4b7ee9ee5587f81984f5768471af27ab2e967f12 Mon Sep 17 00:00:00 2001 From: "Yunsam.Eo" Date: Sun, 21 Dec 2025 17:20:16 +0900 Subject: [PATCH 2/2] Merge --- .../impl/HttpClient5AdapterServiceRest.java | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 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 b238093..f220556 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 @@ -7,10 +7,12 @@ import java.net.ConnectException; import java.net.SocketTimeoutException; import java.net.URI; import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,8 +53,6 @@ import org.springframework.security.oauth2.provider.ClientDetails; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; -import com.eactive.eai.adapter.AdapterGroupVO; -import com.eactive.eai.adapter.AdapterManager; import com.eactive.eai.adapter.AdapterPropManager; import com.eactive.eai.adapter.http.HttpMemoryLogger; import com.eactive.eai.adapter.http.HttpMethodType; @@ -60,12 +60,6 @@ import com.eactive.eai.adapter.http.client.HttpClient5AdapterServiceSupport; import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey; import com.eactive.eai.adapter.http.client.HttpClientAdapterVO; import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey; -import com.eactive.eai.adapter.http.dynamic.filter.AdapterAllowIPListFilter; -import com.eactive.eai.adapter.http.dynamic.filter.ApiAuthFilter; -import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilter; -import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilterType; -import com.eactive.eai.adapter.http.dynamic.filter.IpWhiteListFilter; -import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthFilter; import com.eactive.eai.common.TransactionContextKeys; import com.eactive.eai.common.authoutbound.AccessTokenManagerByDB; import com.eactive.eai.common.exception.ExceptionUtil; @@ -91,8 +85,8 @@ 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.Map.Entry; import java.util.HashSet; +import java.util.Date; /** * 1. 기능 : EAI HTTP OutBound 용 어댑터로 수동 시스템의 HTTP 웹 컴포넌트를 GET/POST 방식으로 호출할 수 있는 @@ -303,6 +297,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // OAuth2AccessToken check 부분을 뒤에서 여기로 위치를 옮김, 나이스지키미 암호화 KEY를 얻기 위해서. JWHONG OAuth2AccessTokenVO accessToken = null; String auth =""; + Date currentDate = new Date(); if (useAdapterToken) { AccessTokenManagerByDB tokenManager = AccessTokenManagerByDB.getInstance(); accessToken = (OAuth2AccessTokenVO) tokenManager.getAccessTokenVO(vo.getAdapterGroupName()); @@ -327,8 +322,8 @@ 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 = accessToken.getClientId(); // HttpClientAccessTokenServiceWithBase64NiceOn 서 넣어줌 - long currentTime = System.currentTimeMillis(); + String clientId = accessToken.getClientId(); // HttpClientAccessTokenServiceWithBase64NiceOn 서 넣어줌 + long currentTime = currentDate.getTime() / 1000; auth = niceToken + ":" + currentTime + ":" + clientId ; logger.debug("HttpClientAdapterServiceRest] NiceOn auth = [" + auth + "]"); auth = Base64.getEncoder().encodeToString(auth.getBytes("UTF-8")); @@ -341,7 +336,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp if (logger.isDebug()) { logger.debug("HttpClientAdapterServiceRest] SEND (" + vo.getAdapterGroupName() - + ") RequestHeader [Authorization=" + method.getHeader("Authorization") + "]"); + + ") RequestHeader [" + method.getHeader("Authorization").getName() + ": " + method.getHeader("Authorization").getValue() + "]"); } } @@ -376,8 +371,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // assignPostBody(dataObject, contentType, vo.getEncode(), method); //assignPostBody(dataContent, contentType, vo.getEncode(), method); // jwhong commnet // KJBank API 추적정보를 Header에 제공. jwhong -// String inboundToken= assignRequestKJHeaders(method, prop, tempProp ); Filter에서 처리함. - assignPostBody(dataContent, contentType, vo.getEncode(), method, vo.getAdapterName(), auth, inboundToken); +// String inboundToken= assignRequestKJHeaders(method, prop, tempProp ); + assignPostBody(dataContent, contentType, vo.getEncode(), method, vo.getAdapterName(), auth, inboundToken, currentDate); break; default: break; @@ -392,7 +387,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // 전달 header 셋팅 // Adapter 레벨 header 보다 data로 넘어온 httpHeader를 우선 적용(header명이 같다면 덮어씀) - assignRequestHeaders(method, httpHeader); + assignRequestHeaders(method, httpHeader); // KJBank API 추적정보를 Header에 제공. jwhong //assignRequestKJHeaders(method, prop, tempProp ); @@ -730,7 +725,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp private void setNiceOnAuthHeaders(HttpUriRequestBase method, String auth) throws Exception { method.setHeader("Authorization", String.format("%s %s", AccessTokenVO.BEARER_TYPE, auth)); // 나이스지키미 format임 - method.setHeader("ProductID", "2303345072"); + String productId = PropManager.getInstance().getProperty("NiceOnProperty","productId.value"); + method.setHeader("ProductID", productId); //method.setHeader("Authorization", // String.format("%s %s", AccessTokenVO.BEARER_TYPE, accessToken.getAccessToken())); } @@ -946,7 +942,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp } @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, Date currentDate) { if (eaiBody == null) { return; } @@ -967,7 +963,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp } else { ContentType contentTypeObj = ContentType.create(contentType, charset); - String eaiBodyMessage = doOutboundPreFilter(eaiBody, adapterName, niceAuth, inboundToken); // jwhong + String eaiBodyMessage = doOutboundPreFilter(eaiBody, adapterName, niceAuth, inboundToken, currentDate); // jwhong StringEntity entity = new StringEntity(eaiBodyMessage, contentTypeObj); // 요청 본문을 StringEntity 객체로 생성 //StringEntity entity = new StringEntity(eaiBody.toString(), contentTypeObj); @@ -978,7 +974,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp } // from here by jwhong - private String doOutboundPreFilter(Object eaiBody, String adapterName, String niceAuth, String inboundToken) { + private String doOutboundPreFilter(Object eaiBody, String adapterName, String niceAuth, String inboundToken, Date currentDate) { Properties properties = AdapterPropManager.getInstance().getProperties(adapterName); // jwhong String encryptAlgorithm = properties.getProperty("ENCRYPT_ALGORITHM",""); // jwhong @@ -1013,12 +1009,12 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp // 여기서 SECRETY인지 nice-auth 인지 check 하여 clientSecret 값을 정하는 logic 추가하여 넘겨야한다. - String responseMessage = doOutboundPreEncrypt(eaiBody, encryptAlgorithm, clientSecret, encryptAES256Iv, encryptAES256Key, certPath); + String responseMessage = doOutboundPreEncrypt(eaiBody, encryptAlgorithm, clientSecret, encryptAES256Iv, encryptAES256Key, certPath, currentDate); logger.debug("outbound pre encrypte value is :"+responseMessage); return responseMessage; } - private String doOutboundPreEncrypt(Object eaiBody, String encryptAlgorithm, String clientSecretKey, String encryptAES256Iv, String encryptAES256Key, String certPath ) { + private String doOutboundPreEncrypt(Object eaiBody, String encryptAlgorithm, String clientSecretKey, String encryptAES256Iv, String encryptAES256Key, String certPath, Date currentDate) { String encryptedMessage = ""; String encryptedJsonKey = ""; @@ -1121,11 +1117,27 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp //break; } - Map map = new HashMap<>(); - map.put(encryptedJsonKey, encryptedMessage); - JSONObject json = new JSONObject(); - json.putAll(map); - return json.toJSONString(); + if (encryptAlgorithm.equals("AES256-NICEON")) { + String goodsCls = PropManager.getInstance().getProperty("NiceOnProperty","goods.cls.value"); + Map map = new HashMap<>(); + SimpleDateFormat sdfDateTime =new SimpleDateFormat("yyyyMMddHHmmss"); + map.put("req_dtm", sdfDateTime.format(currentDate)); + map.put("goods_cls", goodsCls); + map.put(encryptedJsonKey, encryptedMessage); + JSONObject dataBody = new JSONObject(); + dataBody.putAll(map); + + JSONObject json = new JSONObject(); + json.put("dataBody", dataBody); + return json.toJSONString(); + } else { + Map map = new HashMap<>(); + map.put(encryptedJsonKey, encryptedMessage); + JSONObject json = new JSONObject(); + json.putAll(map); + return json.toJSONString(); + } + //return encryptedMessage; } @@ -1323,7 +1335,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp jsonKey = "encryptedData"; break; case "AES256-NICEON": - jsonKey = "preScreeningRequest"; + jsonKey = "enc_data"; break; case "AES256GCM": break;