diff --git a/src/main/java/cokr/xit/base/crypto/Cryptography.java b/src/main/java/cokr/xit/base/crypto/Cryptography.java index 7569017..f446d93 100644 --- a/src/main/java/cokr/xit/base/crypto/Cryptography.java +++ b/src/main/java/cokr/xit/base/crypto/Cryptography.java @@ -7,12 +7,12 @@ import java.util.Map; import java.util.Set; import java.util.function.Predicate; -import org.apache.commons.beanutils.PropertyUtils; import org.springframework.core.io.ClassPathResource; import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.JSON; +import cokr.xit.foundation.data.Property; /**암복호화를 위한 베이스 클래스. * 암복호화 지원 클래스는 {@link Config 설정파일에서 설정정보}를 읽어들인다. @@ -331,10 +331,15 @@ public abstract class Cryptography extends AbstractComponent { return false; } else { for (String property: valueType.getObjectProperties()) { + if (Property.readable(obj, property) + && Property.writeable(obj, property)) + return true; +/* if (PropertyUtils.isReadable(obj, property) && PropertyUtils.isWriteable(obj, property) ) return true; +*/ } return false; } diff --git a/src/main/java/cokr/xit/base/crypto/CryptographySupport.java b/src/main/java/cokr/xit/base/crypto/CryptographySupport.java index 7e5b4bd..a75de14 100644 --- a/src/main/java/cokr/xit/base/crypto/CryptographySupport.java +++ b/src/main/java/cokr/xit/base/crypto/CryptographySupport.java @@ -7,8 +7,6 @@ import java.util.Map; import java.util.function.BiFunction; import java.util.stream.Collectors; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.beanutils.PropertyUtils; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.executor.resultset.ResultSetHandler; import org.apache.ibatis.mapping.MappedStatement; @@ -18,6 +16,7 @@ import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import cokr.xit.base.crypto.Cryptography.Config; +import cokr.xit.foundation.data.Property; import cokr.xit.foundation.data.paging.MybatisPlugin; /**데이터베이스와 주고받는 파라미터와 데이터를 암복호화하는 마이바티스 플러그인. @@ -43,6 +42,8 @@ public class CryptographySupport extends MybatisPlugin { this.cryptos = cryptos.stream().collect(Collectors.toMap(Cryptography::name, crypto -> crypto)); } + // TODO: 파라미터 추출 및 검사 방식 변경할 것: BoundSql, ParameterMapping을 사용하여 구분 및 추출 + @Override protected Object query(Executor executor, MappedStatement mappedStatement, Object obj, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException { return encrypt(obj, () -> super.query(executor, mappedStatement, obj, rowBounds, resultHandler)); @@ -113,11 +114,16 @@ public class CryptographySupport extends MybatisPlugin { }); } else { target.getObjectProperties().stream() - .filter(property -> PropertyUtils.isReadable(obj, property)) + .filter(property -> Property.readable(obj, property)) +// .filter(property -> PropertyUtils.isReadable(obj, property)) .forEach(property -> { try { + String val = Property.read(obj, property); + Property.write(obj, property, converter.apply(crypto, val)); +/* String val = BeanUtils.getProperty(obj, property); BeanUtils.setProperty(obj, property, converter.apply(crypto, val)); +*/ } catch (Exception e) { throw runtimeException(e); } diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java index 6de42dc..78e344c 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java @@ -4,12 +4,14 @@ import cokr.xit.base.crypto.Cryptography; public class XitAria extends Cryptography { private String key; + private int keySize; private XitBridge bridge; public XitAria(String name) { super(name); setKey(def.settings().string("key")); - bridge = XitBridge.create(key, def.settings().string("charset")); + setKeySize(def.settings().number("keySize").intValue()); + bridge = XitBridge.create(key, def.settings().string("charset"), keySize); } public XitAria setKey(String key) { @@ -17,6 +19,11 @@ public class XitAria extends Cryptography { return this; } + public XitAria setKeySize(int keySize) { + this.keySize = keySize< 1 ? 192 : keySize; + return this; + } + @Override protected String doEncrypt(String plain) throws Exception { return bridge.encrypt(plain); diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java index b0d467f..cdf25c2 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java @@ -313,15 +313,17 @@ public class XitBridge extends AbstractComponent { throw new IllegalArgumentException("num: " + num); } - public static XitBridge create(String key, String charset) { + public static XitBridge create(String key, String charset, int keySize) { XitBridge newAria = new XitBridge(); newAria.encode = true; newAria.key = ""; newAria.charset = charset; - newAria.keySize = 192; + newAria.keySize = keySize; newAria.properties.get("Encode").write(true); newAria.properties.get("Key").write(key); + newAria.properties.get("KeySize").write(keySize); + return newAria; } diff --git a/src/main/resources/xit-crypto.conf b/src/main/resources/xit-crypto.conf index 49a54ec..76cfcfe 100644 --- a/src/main/resources/xit-crypto.conf +++ b/src/main/resources/xit-crypto.conf @@ -14,7 +14,8 @@ "class": "cokr.xit.base.crypto.bean.XitAria", "settings": { "charset": "EUC-KR", - "key": "Copyright (c) 2015 - (주)엑스아이티" + "key": "Copyright (c) 2015 - (주)엑스아이티", + "keySize": 192 } }, { "name": "echelon",