headerGroupName null 체크 추가
This commit is contained in:
+26
-3
@@ -6,6 +6,7 @@ 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.common.util.JacksonUtil;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.util.JsonPathUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -15,6 +16,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
*/
|
||||
public class DouzoneEncFieldOutCryptoFilter extends EncFieldOutCryptoFilter {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||
|
||||
private final OutCryptoFilter filter = new OutCryptoFilter();
|
||||
|
||||
protected Properties setProp(Properties tempProp) {
|
||||
@@ -31,13 +34,22 @@ public class DouzoneEncFieldOutCryptoFilter extends EncFieldOutCryptoFilter {
|
||||
|
||||
JsonNode root = JacksonUtil.readTree(message);
|
||||
ObjectNode rootObjectNode = (ObjectNode) root;
|
||||
JsonNode header = rootObjectNode.get(headerGroupName);
|
||||
JsonNode header = (headerGroupName == null) ? null : rootObjectNode.get(headerGroupName);
|
||||
|
||||
// 더존은 헤더의 x-emp-nm(AAD), x-chnl-nm(DYNAMIC 키 도출 컨텍스트)이 있어야 암호화가 가능하다.
|
||||
// 값이 없으면 잘못된 컨텍스트로 암호화되지 않도록 암호화를 스킵하고 원본을 그대로 전달한다.
|
||||
String xEmpNm = getHeaderText(header, "x-emp-nm");
|
||||
String xChnlNm = getHeaderText(header, "x-chnl-nm");
|
||||
if (xEmpNm == null || xChnlNm == null) {
|
||||
logger.warn("더존 암호화 컨텍스트 헤더 없음, 암호화 스킵. adptGrpName={}, adptName={}, headerGroup={}",
|
||||
adptGrpName, adptName, headerGroupName);
|
||||
return message;
|
||||
}
|
||||
|
||||
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));
|
||||
@@ -48,6 +60,17 @@ public class DouzoneEncFieldOutCryptoFilter extends EncFieldOutCryptoFilter {
|
||||
return encJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 헤더 그룹에서 지정한 헤더 값을 조회한다. 헤더 그룹 또는 해당 항목이 없으면 null을 반환한다.
|
||||
*/
|
||||
private String getHeaderText(JsonNode header, String name) {
|
||||
if (header == null) {
|
||||
return null;
|
||||
}
|
||||
JsonNode node = header.get(name);
|
||||
return (node == null) ? null : node.asText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object doPostFilter(String adptGrpName, String adptName, Properties prop, Object message,
|
||||
Properties tempProp) throws Exception {
|
||||
|
||||
+7
-3
@@ -29,13 +29,17 @@ public class EncFieldOutCryptoFilter implements HttpClientAdapterFilter {
|
||||
|
||||
JsonNode root = JacksonUtil.readTree(message);
|
||||
ObjectNode rootObjectNode = (ObjectNode) root;
|
||||
JsonNode header = rootObjectNode.get(headerGroupName);
|
||||
rootObjectNode.remove(headerGroupName);
|
||||
JsonNode header = null;
|
||||
if (headerGroupName != null) {
|
||||
header = rootObjectNode.get(headerGroupName);
|
||||
rootObjectNode.remove(headerGroupName);
|
||||
}
|
||||
|
||||
Object enc = filter.doPreFilter(adptGrpName, adptName, prop, rootObjectNode, setProp(tempProp));
|
||||
|
||||
ObjectNode encJson = (ObjectNode)JacksonUtil.readTree(enc);
|
||||
encJson.set(headerGroupName, header);
|
||||
if (header != null)
|
||||
encJson.set(headerGroupName, header);
|
||||
|
||||
return encJson;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user