safedb reflection 에서 직접 호출로 변경

This commit is contained in:
Rinjae
2025-09-25 16:20:03 +09:00
parent 36f9c7e016
commit dd5ff97549
5 changed files with 42 additions and 17 deletions
+1 -2
View File
@@ -109,8 +109,7 @@ dependencies {
// 광주은행 safedb 용 임시 라이브러리
compileOnly(fileTree(dir: "tmp/safedb", include: ["*.jar"]))
// implementation(fileTree(dir: "tmp/safedb", include: ["*.jar"]))
compileOnly(fileTree(dir: "ext-libs/safedb", include: ["*.jar"]))
}
test {
+2
View File
@@ -0,0 +1,2 @@
SafeDBSDK_v4.0.19.jar 파일은 빌드결과에 포함되지 않고 compileOnly 로만 사용
실제 라이브러리는 WAS classpath 로 지정
Binary file not shown.
@@ -1,7 +1,18 @@
package com.eactive.ext.kjb.safedb;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import com.initech.safedb.SimpleSafeDB;
import com.initech.safedb.sdk.exception.SafeDBSDKException;
import java.util.Base64;
@Slf4j
public class SafeDBWrapper extends SafeDBBroker {
private static SafeDBWrapper instance;
private SimpleSafeDB safedb;
@Getter
private boolean isRealSafeDB = false;
@@ -30,11 +41,23 @@ public class SafeDBWrapper extends SafeDBBroker {
// "com.initech.safedb.SimpleSafeDB" 클래스 존재 여부 확인
try {
Class.forName("com.initech.safedb.SimpleSafeDB");
if (SafeDBWrapper.class.getClassLoader().getResource("SafeDBMap_config.xml") == null) {
isRealSafeDB = false;
return;
}
this.safedb = SimpleSafeDB.getInstance();
if (safedb.getSafeDBConfigMgr().isLoginCheck()) {
log.debug("[SafeDBWrapper] isLoginCheck : {}", safedb.getSafeDBConfigMgr().isLoginCheck());
} else {
log.warn("[SafeDBWrapper] isLoginCheck : {}", safedb.getSafeDBConfigMgr().isLoginCheck());
}
isRealSafeDB = true; // 클래스가 존재하면 true로 설정
} catch (ClassNotFoundException e) {
isRealSafeDB = false; // 클래스가 존재하지 않으면 false로 설정
} catch (Exception e) {
throw new SafeDBWrapperException(("[SafeDBWrapper] Classloader error: " + e.getMessage()), e);
isRealSafeDB = false; // 클래스가 존재하지 않으면 false로 설정
log.info("SafeDB 클래스 로딩 실패 - 로컬 환경이거나 설정 오류 / Fake 모드로 동작함", e);
}
if (isRealSafeDB) {
@@ -51,9 +74,10 @@ public class SafeDBWrapper extends SafeDBBroker {
public byte[] encrypt(String userId, String table, String column, String data) throws SafeDBWrapperSdkException {
if (isRealSafeDB) {
try {
return (byte[]) super.methodInvoke("encrypt",
new Class<?>[]{String.class, String.class, String.class, String.class},
new Object[]{userId, table, column, data});
// return (byte[]) super.methodInvoke("encrypt",
// new Class<?>[]{String.class, String.class, String.class, String.class},
// new Object[]{userId, table, column, data});
return safedb.encrypt(userId, table, column, data);
} catch (Exception e) {
throw new SafeDBWrapperSdkException("[SafeDBWrapper] Encrypt error: " + e.getMessage(), e);
}
@@ -70,9 +94,11 @@ public class SafeDBWrapper extends SafeDBBroker {
public byte[] decrypt(String userId, String table, String column, String data) throws SafeDBWrapperSdkException {
if (isRealSafeDB) {
try {
return (byte[]) super.methodInvoke("decrypt",
new Class<?>[]{String.class, String.class, String.class, String.class},
new Object[]{userId, table, column, data});
// return (byte[]) super.methodInvoke("decrypt",
// new Class<?>[]{String.class, String.class, String.class, String.class},
// new Object[]{userId, table, column, data});
byte[] dataBytes = Base64.getDecoder().decode(data);
return safedb.decrypt(userId, table, column, dataBytes);
} catch (Exception e) {
throw new SafeDBWrapperException("[SafeDBWrapper] Decrypt error: " + e.getMessage(), e);
}
@@ -84,8 +110,4 @@ public class SafeDBWrapper extends SafeDBBroker {
public String decryptNotRnno(String data) throws SafeDBWrapperSdkException {
return new String(this.decrypt("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data));
}
public boolean isRealSafeDB() {
return isRealSafeDB;
}
}
@@ -35,13 +35,13 @@ public class SafeDbWrapperTest {
String originalData = repeat("A", len); // JDK8 호환 반복 문자열
try {
// 암호화 (Base64 인코딩 결과 가정)
String encryptedData = wrapper.encrypt("userId", "tableName", "columnName", originalData);
String encryptedData = wrapper.encryptNotRnnoString(originalData);
// 예상 암호문 길이 계산
int expectedLen = getExpectedCipherLength(len, true);
// 복호화
String decryptedData = wrapper.decrypt("userId", "tableName", "columnName", encryptedData);
String decryptedData = wrapper.decryptNotRnno(encryptedData);
assertEquals(originalData, decryptedData, "Decrypted data does not match original at plain length=" + len);
// 로그 출력
@@ -69,6 +69,7 @@ public class SafeDbWrapperTest {
/**
* 암호문 예상 길이 계산 (AES/SEED/ARIA CBC 기준, PKCS5Padding)
*/
@SuppressWarnings("SameParameterValue")
private int getExpectedCipherLength(int plainLength, boolean base64Encoding) {
int blockSize = 16;
int paddedLength = ((plainLength / blockSize) + 1) * blockSize;
@@ -81,6 +82,7 @@ public class SafeDbWrapperTest {
}
/** JDK8에서 문자열 반복 (String.repeat 대체) */
@SuppressWarnings("SameParameterValue")
private String repeat(String s, int count) {
StringBuilder sb = new StringBuilder(s.length() * count);
for (int i = 0; i < count; i++) {