암복호화 기능 수정

This commit is contained in:
curry772
2026-06-30 16:24:15 +09:00
parent 0dfab56d0c
commit 0a692f8a07
5 changed files with 113 additions and 14 deletions
@@ -75,7 +75,9 @@ public class DJBApiAdapterService extends HttpAdapterServiceSupport {
public static final String PAYLOAD_PARAM_NAME_CLIENT_ID = "client_id"; // jwhong
public String callApi(HttpServletRequest request, HttpServletResponse response, Properties httpProp,
private ObjectMapper mapper = new ObjectMapper();
public String callApi(HttpServletRequest request, HttpServletResponse response, Properties httpProp,
AdapterGroupVO adapterGroupVO, AdapterVO adapterVO, Properties transactionProp) throws Exception {
int traceLevel = 0;
@@ -361,7 +363,6 @@ public class DJBApiAdapterService extends HttpAdapterServiceSupport {
String syncAsyncType = transactionProp.getProperty(INBOUND_SYNC_ASYNC_TYPE);
if (!"ASYN".equals(syncAsyncType) && MessageType.JSON.equals(adptMsgType) && StringUtils.isNotBlank(headerGroupName)) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = (ObjectNode) mapper.readTree(result);
JsonNode headerGroup = rootNode.get(headerGroupName);
if(headerGroup != null) {
@@ -0,0 +1,56 @@
package com.eactive.eai.custom.adapter.http.client.impl.filter;
import java.util.Properties;
import com.eactive.eai.adapter.http.client.impl.HttpClient5AdapterServiceRest;
import com.eactive.eai.adapter.http.client.impl.filter.OutCryptoFilter;
import com.eactive.eai.adapter.http.dynamic.filter.InCryptoFilter;
import com.eactive.eai.util.JsonPathUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* 토스 암복호화에 맟추어 커스텀
*/
public class DouzoneEncFieldOutCryptoFilter extends EncFieldOutCryptoFilter {
private final OutCryptoFilter filter = new OutCryptoFilter();
protected Properties setProp(Properties tempProp) {
tempProp.setProperty(OutCryptoFilter.PROP_DEC_FROM_PATH, "/encryptedData");
tempProp.setProperty(OutCryptoFilter.PROP_ENC_TO_PATH, "/encryptedData");
return tempProp;
}
@Override
public Object doPreFilter(String adptGrpName, String adptName, Properties prop, Object message, Properties tempProp)
throws Exception {
String headerGroupName = prop.getProperty(HttpClient5AdapterServiceRest.HEADER_GROUP);
JsonNode root = JsonPathUtil.toTree(message);
ObjectNode rootObjectNode = (ObjectNode) root;
JsonNode header = rootObjectNode.get(headerGroupName);
rootObjectNode.remove(headerGroupName);
String xEmpNm = header.get("x-emp-nm").asText();
tempProp.setProperty("x-emp-nm", xEmpNm);
tempProp.setProperty(InCryptoFilter.PROP_AAD_HEADER, xEmpNm);
String xChnlNm = header.get("x-chnl-nm").asText();
tempProp.setProperty("x-chnl-nm", xChnlNm);
Object enc = filter.doPreFilter(adptGrpName, adptName, prop, rootObjectNode, setProp(tempProp));
ObjectNode encJson = (ObjectNode)JsonPathUtil.toTree(enc);
encJson.set(headerGroupName, header);
return encJson;
}
@Override
public Object doPostFilter(String adptGrpName, String adptName, Properties prop, Object message,
Properties tempProp) throws Exception {
return filter.doPostFilter(adptGrpName, adptName, setProp(prop), message, setProp(tempProp));
}
}
@@ -15,10 +15,10 @@ public class EncFieldOutCryptoFilter implements HttpClientAdapterFilter {
private final OutCryptoFilter filter = new OutCryptoFilter();
protected Properties setProp(Properties p) {
p.setProperty(OutCryptoFilter.PROP_DEC_FROM_PATH, "/encryptedData");
p.setProperty(OutCryptoFilter.PROP_ENC_TO_PATH, "/encryptedData");
return p;
protected Properties setProp(Properties tempProp) {
tempProp.setProperty(OutCryptoFilter.PROP_DEC_FROM_PATH, "/encryptedData");
tempProp.setProperty(OutCryptoFilter.PROP_ENC_TO_PATH, "/encryptedData");
return tempProp;
}
@Override
@@ -9,10 +9,12 @@ import org.springframework.http.HttpStatus;
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
import com.eactive.eai.adapter.http.dynamic.filter.FilterCryptoException;
import com.eactive.eai.adapter.http.dynamic.filter.FilterException;
import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilter;
import com.eactive.eai.adapter.http.dynamic.filter.InCryptoFilter;
import com.eactive.eai.common.security.keyderiv.KeyDerivationStrategy;
import com.eactive.eai.adapter.service.DJBApiAdapterService;
import com.eactive.eai.util.JsonPathUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* 더존 연동용 수신 암복호화 필터.
@@ -31,8 +33,6 @@ import com.eactive.eai.common.security.keyderiv.KeyDerivationStrategy;
*/
public class DouzoneEncFieldInCryptoFilter implements HttpAdapterFilter {
public static final String ERROR_DEC_FAIL = "E.DECRYPT_FAIL";
public static final String ERROR_ENC_FAIL = "E.ENCRYPT_FAIL";
private final InCryptoFilter filter = new InCryptoFilter();
protected Properties setProp(Properties p) {
@@ -56,7 +56,7 @@ public class DouzoneEncFieldInCryptoFilter implements HttpAdapterFilter {
setContext(prop);
return filter.doPreFilter(adptGrpName, adptName, message, setProp(prop), request, response);
} catch (Exception e) {
throw new FilterCryptoException("복호화 오류", ERROR_DEC_FAIL, HttpStatus.INTERNAL_SERVER_ERROR.value(), e);
throw new FilterCryptoException("복호화 오류", InCryptoFilter.ERROR_DEC_FAIL, HttpStatus.INTERNAL_SERVER_ERROR.value(), e);
}
}
@@ -65,9 +65,25 @@ public class DouzoneEncFieldInCryptoFilter implements HttpAdapterFilter {
HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
setContext(prop);
return filter.doPostFilter(adptGrpName, adptName, resultMessage, setProp(prop), request, response);
JsonNode root = JsonPathUtil.toTree(resultMessage);
ObjectNode rootObjectNode = (ObjectNode) root;
String headerGroupName = prop.getProperty(DJBApiAdapterService.HEADER_GROUP);
JsonNode header = null;
if(headerGroupName != null) {
header = rootObjectNode.get(headerGroupName);
rootObjectNode.remove(headerGroupName);
}
Object enc = filter.doPostFilter(adptGrpName, adptName, rootObjectNode, setProp(prop), request, response);
ObjectNode encJson = (ObjectNode)JsonPathUtil.toTree(enc);
if(header != null)
encJson.set(headerGroupName, header);
return encJson;
} catch (Exception e) {
throw new FilterCryptoException("암호화 오류", ERROR_ENC_FAIL, HttpStatus.INTERNAL_SERVER_ERROR.value(), e);
throw new FilterCryptoException("암호화 오류", InCryptoFilter.ERROR_ENC_FAIL, HttpStatus.INTERNAL_SERVER_ERROR.value(), e);
}
}
@@ -5,7 +5,14 @@ import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import com.eactive.eai.adapter.http.dynamic.filter.InCryptoFilter;
import com.eactive.eai.adapter.service.DJBApiAdapterService;
import com.eactive.eai.util.JsonPathUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.eactive.eai.adapter.http.dynamic.filter.FilterCryptoException;
import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilter;
/**
@@ -27,7 +34,26 @@ public class EncFieldInCryptoFilter implements HttpAdapterFilter {
@Override
public Object doPostFilter(String adptGrpName, String adptName, Object resultMessage, Properties prop,
HttpServletRequest request, HttpServletResponse response) throws Exception {
return filter.doPostFilter(adptGrpName, adptName, resultMessage, setProp(prop), request, response);
try {
JsonNode root = JsonPathUtil.toTree(resultMessage);
ObjectNode rootObjectNode = (ObjectNode) root;
String headerGroupName = prop.getProperty(DJBApiAdapterService.HEADER_GROUP);
JsonNode header = null;
if(headerGroupName != null) {
header = rootObjectNode.get(headerGroupName);
rootObjectNode.remove(headerGroupName);
}
Object enc = filter.doPostFilter(adptGrpName, adptName, rootObjectNode, setProp(prop), request, response);
ObjectNode encJson = (ObjectNode)JsonPathUtil.toTree(enc);
if(header != null)
encJson.set(headerGroupName, header);
return encJson;
} catch (Exception e) {
throw new FilterCryptoException("암호화 오류", InCryptoFilter.ERROR_ENC_FAIL, HttpStatus.INTERNAL_SERVER_ERROR.value(), e);
}
}
protected Properties setProp(Properties p) {