Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db78cbac2e | |||
| 403b201168 | |||
| ec0cdfd221 | |||
| d277e37798 | |||
| e4851999ba | |||
| 110b0c0039 | |||
| d85642c5a8 | |||
| 49620c5e21 |
Vendored
+163
@@ -0,0 +1,163 @@
|
|||||||
|
pipeline {
|
||||||
|
agent { label 'djb-vm' }
|
||||||
|
|
||||||
|
options {
|
||||||
|
timestamps()
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
JAVA_HOME = '/apps/opts/jdk8'
|
||||||
|
JAVA_HOME_TOMCAT = '/apps/opts/jdk17'
|
||||||
|
GRADLE_HOME = '/apps/opts/gradle-8.7'
|
||||||
|
GRADLE_USER_HOME = '/apps/opts/gradle-home'
|
||||||
|
NODE_HOME = '/apps/opts/node-v24'
|
||||||
|
PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}"
|
||||||
|
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
|
||||||
|
CATALINA_BASE = '/prod/eapim/apigw'
|
||||||
|
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
|
||||||
|
CATALINA_PID = '/prod/eapim/apigw/logs/catalina.pid'
|
||||||
|
DEPLOY_HTTP_PORT = '39110'
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Checkout modules') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
for REPO in elink-online-core elink-online-transformer elink-online-common elink-online-emsclient elink-online-core-jpa; do
|
||||||
|
if [ ! -e "$REPO/.git" ]; then
|
||||||
|
rm -rf "$REPO"
|
||||||
|
git clone --depth=1 --branch master \
|
||||||
|
"ssh://git@172.30.1.50:2222/djb-eapim/$REPO.git" \
|
||||||
|
"$REPO"
|
||||||
|
else
|
||||||
|
git -C "$REPO" fetch --depth=1 origin master
|
||||||
|
git -C "$REPO" reset --hard origin/master
|
||||||
|
git -C "$REPO" clean -fdx
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Verify toolchain') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
java -version
|
||||||
|
gradle --version
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build WAR') {
|
||||||
|
steps {
|
||||||
|
sh 'gradle clean build -x test --no-daemon'
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
cd build/libs
|
||||||
|
sha1sum eapim-online.war > eapim-online.war.sha1
|
||||||
|
sha256sum eapim-online.war > eapim-online.war.sha256
|
||||||
|
md5sum eapim-online.war > eapim-online.war.md5
|
||||||
|
'''
|
||||||
|
archiveArtifacts artifacts: 'build/libs/eapim-online.war,build/libs/eapim-online.war.sha1,build/libs/eapim-online.war.sha256,build/libs/eapim-online.war.md5', fingerprint: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Stop Tomcat') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set +e
|
||||||
|
systemctl --user stop eapim-apigw 2>/dev/null
|
||||||
|
|
||||||
|
if [ -f "$CATALINA_PID" ] && kill -0 "$(cat "$CATALINA_PID")" 2>/dev/null; then
|
||||||
|
JAVA_HOME="$JAVA_HOME_TOMCAT" "$CATALINA_HOME/bin/shutdown.sh" 30 -force || true
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
[ -f "$CATALINA_PID" ] && kill -0 "$(cat "$CATALINA_PID")" 2>/dev/null || break
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
rm -f "$CATALINA_PID"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy ROOT.war') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
DEPLOY_DIR="$CATALINA_BASE/webapps"
|
||||||
|
rm -rf "$DEPLOY_DIR/ROOT" "$DEPLOY_DIR/ROOT.war"
|
||||||
|
cp build/libs/eapim-online.war "$DEPLOY_DIR/ROOT.war"
|
||||||
|
ls -la "$DEPLOY_DIR"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Start Tomcat and readiness') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -eu
|
||||||
|
LOG="$CATALINA_BASE/logs/catalina.$(date +%Y-%m-%d).log"
|
||||||
|
BEFORE=0
|
||||||
|
[ -f "$LOG" ] && BEFORE=$(stat -c %s "$LOG")
|
||||||
|
|
||||||
|
systemctl --user start eapim-apigw
|
||||||
|
|
||||||
|
PROBE_URL="http://localhost:$DEPLOY_HTTP_PORT/"
|
||||||
|
DEADLINE=$(($(date +%s) + 300))
|
||||||
|
STATUS=000
|
||||||
|
|
||||||
|
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
|
||||||
|
STATUS=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 \
|
||||||
|
"$PROBE_URL" 2>/dev/null || echo "000")
|
||||||
|
case "$STATUS" in
|
||||||
|
200|302|401|403|404)
|
||||||
|
echo "Readiness OK ($PROBE_URL HTTP $STATUS)"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | grep -qE "Application listener .* Exception|SEVERE.*startup.Catalina"; then
|
||||||
|
echo "Startup error detected in log"
|
||||||
|
tail -c +$((BEFORE+1)) "$LOG" | tail -80
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
case "$STATUS" in
|
||||||
|
200|302|401|403|404) ;;
|
||||||
|
*)
|
||||||
|
echo "Readiness probe failed within 300s, last HTTP status: $STATUS"
|
||||||
|
echo "--- last 300 lines of catalina log ---"
|
||||||
|
[ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | tail -300
|
||||||
|
echo "--- systemd unit status ---"
|
||||||
|
systemctl --user status eapim-apigw --no-pager || true
|
||||||
|
echo "--- listening ports ---"
|
||||||
|
ss -tlnp 2>/dev/null | grep -E ":$DEPLOY_HTTP_PORT\\b" || echo "(port $DEPLOY_HTTP_PORT not listening)"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "--- key boot log lines ---"
|
||||||
|
tail -c +$((BEFORE+1)) "$LOG" | grep -E "Server startup|Deployment of web" | head -10 || true
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import com.eactive.eai.adapter.AdapterVO;
|
|||||||
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
||||||
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandlerFactory;
|
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandlerFactory;
|
||||||
import com.eactive.eai.adapter.http.HttpStatusException;
|
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.HttpAdapterServiceKey;
|
||||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceSupport;
|
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceSupport;
|
||||||
import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterManager;
|
import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterManager;
|
||||||
@@ -136,29 +137,36 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||||
|
|
||||||
String errorMsg = null;
|
String responseErrorMsg = null;
|
||||||
|
|
||||||
errorMsg = genErrorResponseMessage(adapterGroupName, adapterName,
|
|
||||||
transactionProp, e, adptMsgType, encode, errorResponseFormat);
|
|
||||||
if (e instanceof FilterException) {
|
if (e instanceof FilterException) {
|
||||||
|
responseErrorMsg = genErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
|
transactionProp, MessageUtil.ERROR_CODE_AP_ERROR, e, adptMsgType, encode, errorResponseFormat);
|
||||||
FilterException e1 = (FilterException) e;
|
FilterException e1 = (FilterException) e;
|
||||||
this.logError(servletRequest, uuid, adapterGroupName, e1.getCode(), errorMsg, transactionProp, e);
|
this.logError(servletRequest, adapterGroupName, e1.getCode(), responseErrorMsg, transactionProp, e);
|
||||||
logger.error("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
logger.error("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
||||||
responseEntity = ResponseEntity.status(e1.getStatus()).contentType(mediaType).body(errorMsg);
|
responseEntity = ResponseEntity.status(e1.getStatus()).contentType(mediaType).body(responseErrorMsg);
|
||||||
} else if (e instanceof JwtAuthException) {
|
} else if (e instanceof JwtAuthException) {
|
||||||
|
responseErrorMsg = genErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
|
transactionProp, MessageUtil.ERROR_CODE_AP_ERROR, e, adptMsgType, encode, errorResponseFormat);
|
||||||
JwtAuthException e1 = (JwtAuthException) e;
|
JwtAuthException e1 = (JwtAuthException) e;
|
||||||
this.logError(servletRequest, uuid, adapterGroupName, e1.getCode(), errorMsg, transactionProp, e);
|
this.logError(servletRequest, adapterGroupName, e1.getCode(), responseErrorMsg, transactionProp, e);
|
||||||
logger.error("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
logger.error("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||||
responseEntity = ResponseEntity.status(HttpStatus.UNAUTHORIZED).contentType(mediaType).body(errorMsg);
|
responseEntity = ResponseEntity.status(HttpStatus.UNAUTHORIZED).contentType(mediaType).body(responseErrorMsg);
|
||||||
} else if (e instanceof HttpStatusException) {
|
} else if (e instanceof HttpStatusException) {
|
||||||
|
responseErrorMsg = genErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
|
transactionProp, MessageUtil.ERROR_CODE_AUTH_FAIL, e, adptMsgType, encode, errorResponseFormat);
|
||||||
logger.error("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
logger.error("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
||||||
HttpStatusException e1 = (HttpStatusException) e;
|
HttpStatusException e1 = (HttpStatusException) e;
|
||||||
responseEntity = ResponseEntity.status(e1.getStatus()).contentType(mediaType).body(errorMsg);
|
responseEntity = ResponseEntity.status(e1.getStatus()).contentType(mediaType).body(responseErrorMsg);
|
||||||
} else {
|
} else {
|
||||||
|
responseErrorMsg = genErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
|
transactionProp, MessageUtil.ERROR_CODE_AP_ERROR, e, adptMsgType, encode, errorResponseFormat);
|
||||||
|
this.logError(servletRequest, adapterGroupName, MessageUtil.ERROR_CODE_AP_ERROR, responseErrorMsg, transactionProp, e);
|
||||||
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(mediaType).body(errorMsg);
|
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(mediaType).body(responseErrorMsg);
|
||||||
}
|
}
|
||||||
responseData = errorMsg;
|
responseData = responseErrorMsg;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +186,7 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String genErrorResponseMessage(String adapterGroupName, String adapterName,
|
private String genErrorResponseMessage(String adapterGroupName, String adapterName,
|
||||||
Properties callProp, Throwable e, String adptMsgType, String encode, String errorResponseFormat) {
|
Properties callProp, String code, Throwable e, String adptMsgType, String encode, String errorResponseFormat) {
|
||||||
String errorHandlerClass = AdapterPropManager.getInstance().getProperty(adapterName, "ERR_MSG_HANDLER");
|
String errorHandlerClass = AdapterPropManager.getInstance().getProperty(adapterName, "ERR_MSG_HANDLER");
|
||||||
if (StringUtils.isNotBlank(errorHandlerClass)) {
|
if (StringUtils.isNotBlank(errorHandlerClass)) {
|
||||||
if (logger.isInfo())
|
if (logger.isInfo())
|
||||||
@@ -187,6 +195,7 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
Object resposne;
|
Object resposne;
|
||||||
try {
|
try {
|
||||||
|
callProp.put("INBOUND_RESULT_CODE", code);
|
||||||
resposne = handler.generateNonStandardInboundErrorResponseMessage(adapterGroupName, adapterName,
|
resposne = handler.generateNonStandardInboundErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
callProp, null, null, e);
|
callProp, null, null, e);
|
||||||
return (String)resposne;
|
return (String)resposne;
|
||||||
@@ -197,7 +206,7 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
return MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
||||||
MessageUtil.ERROR_CODE_AP_ERROR, e.getMessage(), errorResponseFormat);
|
code, e.getMessage(), errorResponseFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,21 +259,14 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
String errorCode = "RECEAIIRP010";
|
String errorCode = "RECEAIIRP010";
|
||||||
String[] msgArgs = new String[1];
|
String[] msgArgs = new String[1];
|
||||||
msgArgs[0] = request.getRequestURI();
|
msgArgs[0] = request.getRequestURI();
|
||||||
EAIServerManager eaiServerManager = EAIServerManager.getInstance();
|
this.logError(request, "HTTP_IN_NO_URI", errorCode,
|
||||||
String serverName = eaiServerManager.getLocalServerName();
|
|
||||||
|
|
||||||
String instanceid1 = serverName.substring(0, 2);
|
|
||||||
String instanceid2 = serverName.substring(serverName.length() - 2, serverName.length());
|
|
||||||
String instid = instanceid1 + instanceid2;
|
|
||||||
String uuid = instid + UUIDGenerator.getUUID();
|
|
||||||
this.logError(request, uuid, "HTTP_IN_NO_URI", errorCode,
|
|
||||||
ExceptionUtil.make(new Exception("cat not find uri"), errorCode, msgArgs), null, null);
|
ExceptionUtil.make(new Exception("cat not find uri"), errorCode, msgArgs), null, null);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.warn("inbound logging failed", t);
|
logger.warn("inbound logging failed", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logError(HttpServletRequest request, String uuid, String adapterGroupName, String errorCode,
|
private void logError(HttpServletRequest request, String adapterGroupName, String errorCode,
|
||||||
String errorMsg, Properties prop, Exception e) {
|
String errorMsg, Properties prop, Exception e) {
|
||||||
try {
|
try {
|
||||||
EAIServerManager eaiServerManager = EAIServerManager.getInstance();
|
EAIServerManager eaiServerManager = EAIServerManager.getInstance();
|
||||||
@@ -272,7 +274,15 @@ public class DJBApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
|
|
||||||
InboundErrorInfoVO errorInfoVO = new InboundErrorInfoVO();
|
InboundErrorInfoVO errorInfoVO = new InboundErrorInfoVO();
|
||||||
|
|
||||||
errorInfoVO.setEaiSvcSno(uuid); // EAI서비스일련번호
|
String txId = prop.getProperty(TransactionContextKeys.TRANSACTION_UUID);
|
||||||
|
if (StringUtils.isEmpty(txId)) {
|
||||||
|
String instanceid1 = serverName.substring(0, 2);
|
||||||
|
String instanceid2 = serverName.substring(serverName.length() - 2, serverName.length());
|
||||||
|
String instid = instanceid1 + instanceid2;
|
||||||
|
txId = instid + UUIDGenerator.getUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorInfoVO.setEaiSvcSno(txId); // EAI서비스일련번호
|
||||||
errorInfoVO.setAdptBwkGrpNm(adapterGroupName); // 어댑터업무그룹명
|
errorInfoVO.setAdptBwkGrpNm(adapterGroupName); // 어댑터업무그룹명
|
||||||
errorInfoVO.setErrCd(errorCode); // 에러코드
|
errorInfoVO.setErrCd(errorCode); // 에러코드
|
||||||
errorInfoVO.setErrTxt(errorMsg); // 에러내용
|
errorInfoVO.setErrTxt(errorMsg); // 에러내용
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenCo
|
|||||||
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
|
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
|
||||||
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
|
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
|
||||||
|
|
||||||
|
import com.eactive.eai.agent.encryption.EncryptionManager;
|
||||||
import com.eactive.eai.authserver.dao.TokenIssuanceLogDAO;
|
import com.eactive.eai.authserver.dao.TokenIssuanceLogDAO;
|
||||||
import com.eactive.eai.authserver.jwt.PssJwtAccessTokenConverter;
|
import com.eactive.eai.authserver.jwt.PssJwtAccessTokenConverter;
|
||||||
import com.eactive.eai.authserver.service.OAuth2Manager;
|
import com.eactive.eai.authserver.service.OAuth2Manager;
|
||||||
@@ -131,10 +132,11 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
|
|||||||
String keyAlias = "elink-oauth";
|
String keyAlias = "elink-oauth";
|
||||||
String keyPassword = "elink1234";
|
String keyPassword = "elink1234";
|
||||||
if (vo != null) {
|
if (vo != null) {
|
||||||
keystorePath = vo.getProperty(PROP_KEYSTORE_PATH);
|
EncryptionManager encManager = EncryptionManager.getInstance();
|
||||||
keystorePassword = vo.getProperty(PROP_KEYSTORE_PW);
|
keystorePath = encManager.decryptDBData(vo.getProperty(PROP_KEYSTORE_PATH));
|
||||||
keyAlias = vo.getProperty(PROP_KEY_ALIAS);
|
keystorePassword = encManager.decryptDBData(vo.getProperty(PROP_KEYSTORE_PW));
|
||||||
keyPassword = vo.getProperty(PROP_KEY_PW);
|
keyAlias = encManager.decryptDBData(vo.getProperty(PROP_KEY_ALIAS));
|
||||||
|
keyPassword = encManager.decryptDBData(vo.getProperty(PROP_KEY_PW));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("The properties has not been set.[" + PROP_GROUP_AUTH_SERVER + "]");
|
logger.warn("The properties has not been set.[" + PROP_GROUP_AUTH_SERVER + "]");
|
||||||
}
|
}
|
||||||
|
|||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
package com.eactive.eai.custom.adapter.http.dynamic.filter;
|
||||||
|
|
||||||
|
import java.security.KeyStore;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import com.eactive.eai.adapter.http.dynamic.filter.FilterException;
|
||||||
|
import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilter;
|
||||||
|
import com.eactive.eai.common.hsm.HsmManager;
|
||||||
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
public class HSMKeyCryptoFilter implements HttpAdapterFilter {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||||
|
|
||||||
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object doPreFilter(String adptGrpName, String adptName, Object message, Properties prop,
|
||||||
|
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
try {
|
||||||
|
ObjectNode rootNode = null;
|
||||||
|
String jsonStr = null;
|
||||||
|
if (message instanceof String) {
|
||||||
|
jsonStr = (String) message;
|
||||||
|
} else if (message instanceof JSONObject) {
|
||||||
|
jsonStr = ((JSONObject) message).toJSONString();
|
||||||
|
} else {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
rootNode = (ObjectNode)OBJECT_MAPPER.readTree(jsonStr);
|
||||||
|
|
||||||
|
JsonNode hsmKeyAlias = rootNode.get("hsmKeyAlias");
|
||||||
|
if (hsmKeyAlias != null) {
|
||||||
|
String hsmKeyAliasValue = hsmKeyAlias.textValue();
|
||||||
|
KeyStore keyStore = HsmManager.getInstance().getKeyStore();
|
||||||
|
|
||||||
|
java.security.Key key = keyStore.getKey(hsmKeyAliasValue, null);
|
||||||
|
if (key instanceof SecretKey) {
|
||||||
|
SecretKey secretKey = (SecretKey) key;
|
||||||
|
byte[] encoded = secretKey.getEncoded();
|
||||||
|
if (encoded != null) {
|
||||||
|
String encBase64 = Base64.getEncoder().encodeToString(encoded);
|
||||||
|
logger.debug("HsmManager] HSM - {} : [{}]", hsmKeyAliasValue, encBase64);
|
||||||
|
rootNode.put("hsmKeyBase64", encBase64);
|
||||||
|
rootNode.put("hsmKeyRaw", new String(encoded));
|
||||||
|
} else {
|
||||||
|
logger.debug("HsmManager] HSM - secretKey null {} : [{}]", hsmKeyAliasValue, secretKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String jsonString = OBJECT_MAPPER.writeValueAsString(rootNode);
|
||||||
|
return jsonString;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new FilterException("HSM key 가져오기 실패", ERROR_PRE_FAIL, HttpStatus.INTERNAL_SERVER_ERROR.value(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object doPostFilter(String adptGrpName, String adptName, Object resultMessage, Properties prop,
|
||||||
|
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
return resultMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user