HMAC필터를 위한 처리 수정

This commit is contained in:
cho
2026-01-15 15:01:51 +09:00
parent cafebb528f
commit ec6c5a8b34
2 changed files with 35 additions and 16 deletions
@@ -114,6 +114,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
public static final String HTTP_HEADER_SETTING = "HTTP_HEADER_SETTING"; public static final String HTTP_HEADER_SETTING = "HTTP_HEADER_SETTING";
public static final String PAYLOAD_PARAM_NAME_CLIENT_ID = "client_id"; // jwhong public static final String PAYLOAD_PARAM_NAME_CLIENT_ID = "client_id"; // jwhong
static final String KJB_ROOTLESS_ARRAY = "{ \"KJB_ROOTLESS_ARRAY\" : ";
private boolean useAdapterToken; private boolean useAdapterToken;
private boolean encryptResponseApply; private boolean encryptResponseApply;
@@ -612,7 +614,13 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
"RECV [" + new String(responseMessage, vo.getEncode()) + "]" "RECV [" + new String(responseMessage, vo.getEncode()) + "]"
+ CommonLib.getDumpMessage(responseMessage)); + CommonLib.getDumpMessage(responseMessage));
} }
String jsonStr = new String(responseMessage, vo.getEncode());
if ( jsonStr.trim().startsWith("[") ) {
jsonStr = KJB_ROOTLESS_ARRAY + jsonStr + "}";
responseMessage = jsonStr.getBytes(vo.getEncode());
}
return assignResponseHeaders(method, responseMessage, headerGroupName, vo.getEncode(), messageType, return assignResponseHeaders(method, responseMessage, headerGroupName, vo.getEncode(), messageType,
relayResponseHeaderKeys, status, responseHeaderProp); relayResponseHeaderKeys, status, responseHeaderProp);
@@ -1502,22 +1510,11 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private JSONObject parseJson(String message) throws Exception { private JSONObject parseJson(String message) throws Exception {
if (message == null || message.trim().isEmpty()) { if (message == null) {
return null; return null;
} }
Object obj = JSONValue.parse(message); return (JSONObject) JSONValue.parse(message);
if (obj instanceof JSONObject) {
return (JSONObject) obj;
} else if (obj instanceof JSONArray) {
// 배열일 경우 새로운 객체로 감싸서 반환
JSONObject wrapper = new JSONObject();
wrapper.put("KJB_ROOTLESS_ARRAY", obj);
return wrapper;
}
return null; // 혹은 상황에 맞는 예외 처리
} }
private Document convertXmlDocument(String message) throws Exception { private Document convertXmlDocument(String message) throws Exception {
@@ -14,6 +14,8 @@ import javax.servlet.http.HttpServletResponse;
//import org.apache.commons.net.util.Base64; //import org.apache.commons.net.util.Base64;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import com.eactive.eai.adapter.http.HttpMethodType; import com.eactive.eai.adapter.http.HttpMethodType;
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey; import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
@@ -24,6 +26,8 @@ import com.eactive.eai.common.TransactionContextKeys;
import com.eactive.eai.common.util.Logger; import com.eactive.eai.common.util.Logger;
public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter { public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter {
static final String KJB_ROOTLESS_ARRAY = "{ \"KJB_ROOTLESS_ARRAY\" : ";
static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER); static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
@@ -58,6 +62,14 @@ public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter {
String chkBody = inboundBody; String chkBody = inboundBody;
String clientSecret = assignClientSecret(prop, request); String clientSecret = assignClientSecret(prop, request);
if (chkBody.startsWith(KJB_ROOTLESS_ARRAY)) {
chkBody = chkBody.substring(KJB_ROOTLESS_ARRAY.length());
if (chkBody.endsWith("}")) {
chkBody = chkBody.substring(0, chkBody.length() - 1);
}
}
String macUrl = calculateHMAC(chkUrl, clientSecret); String macUrl = calculateHMAC(chkUrl, clientSecret);
String macBody = calculateHMAC(chkBody, clientSecret); String macBody = calculateHMAC(chkBody, clientSecret);
@@ -145,6 +157,15 @@ public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter {
String outboundBody = (String) resultMessage; String outboundBody = (String) resultMessage;
try { try {
if (outboundBody.startsWith(KJB_ROOTLESS_ARRAY)) {
outboundBody = outboundBody.substring(KJB_ROOTLESS_ARRAY.length());
if (outboundBody.endsWith("}")) {
outboundBody = outboundBody.substring(0, outboundBody.length() - 1);
}
}
String clientSecret = assignClientSecret(prop, request); String clientSecret = assignClientSecret(prop, request);
String macBody = calculateHMAC(outboundBody, clientSecret); String macBody = calculateHMAC(outboundBody, clientSecret);
@@ -157,5 +178,6 @@ public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter {
return resultMessage; return resultMessage;
} }
} }