|
|
@ -7,8 +7,6 @@ import java.util.Map;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
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.Executor;
|
|
|
|
import org.apache.ibatis.executor.resultset.ResultSetHandler;
|
|
|
|
import org.apache.ibatis.executor.resultset.ResultSetHandler;
|
|
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
|
@ -18,6 +16,7 @@ import org.apache.ibatis.session.ResultHandler;
|
|
|
|
import org.apache.ibatis.session.RowBounds;
|
|
|
|
import org.apache.ibatis.session.RowBounds;
|
|
|
|
|
|
|
|
|
|
|
|
import cokr.xit.base.crypto.Cryptography.Config;
|
|
|
|
import cokr.xit.base.crypto.Cryptography.Config;
|
|
|
|
|
|
|
|
import cokr.xit.foundation.data.Property;
|
|
|
|
import cokr.xit.foundation.data.paging.MybatisPlugin;
|
|
|
|
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));
|
|
|
|
this.cryptos = cryptos.stream().collect(Collectors.toMap(Cryptography::name, crypto -> crypto));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: 파라미터 추출 및 검사 방식 변경할 것: BoundSql, ParameterMapping을 사용하여 구분 및 추출
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Object query(Executor executor, MappedStatement mappedStatement, Object obj, RowBounds rowBounds, ResultHandler<?> resultHandler) throws SQLException {
|
|
|
|
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));
|
|
|
|
return encrypt(obj, () -> super.query(executor, mappedStatement, obj, rowBounds, resultHandler));
|
|
|
@ -113,11 +114,16 @@ public class CryptographySupport extends MybatisPlugin {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
target.getObjectProperties().stream()
|
|
|
|
target.getObjectProperties().stream()
|
|
|
|
.filter(property -> PropertyUtils.isReadable(obj, property))
|
|
|
|
.filter(property -> Property.readable(obj, property))
|
|
|
|
|
|
|
|
// .filter(property -> PropertyUtils.isReadable(obj, property))
|
|
|
|
.forEach(property -> {
|
|
|
|
.forEach(property -> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
String val = Property.read(obj, property);
|
|
|
|
|
|
|
|
Property.write(obj, property, converter.apply(crypto, val));
|
|
|
|
|
|
|
|
/*
|
|
|
|
String val = BeanUtils.getProperty(obj, property);
|
|
|
|
String val = BeanUtils.getProperty(obj, property);
|
|
|
|
BeanUtils.setProperty(obj, property, converter.apply(crypto, val));
|
|
|
|
BeanUtils.setProperty(obj, property, converter.apply(crypto, val));
|
|
|
|
|
|
|
|
*/
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw runtimeException(e);
|
|
|
|
throw runtimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|