key, algorithm 디폴트값 수정

master
mjkhan21 12 months ago
parent 5e331b873f
commit d8f9cd21c4

@ -1,6 +1,9 @@
package cokr.xit.foundation.data; package cokr.xit.foundation.data;
import java.util.Base64; import java.util.Base64;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import org.egovframe.rte.fdl.cryptography.EgovPasswordEncoder; import org.egovframe.rte.fdl.cryptography.EgovPasswordEncoder;
import org.egovframe.rte.fdl.cryptography.impl.EgovARIACryptoServiceImpl; import org.egovframe.rte.fdl.cryptography.impl.EgovARIACryptoServiceImpl;
@ -23,7 +26,14 @@ public class ARIA extends AbstractComponent {
* @return * @return
*/ */
public String getKey() { public String getKey() {
return key; if (!isEmpty(key))
return key;
if (properties != null) {
return key = properties.getString("aria.key");
} else {
return key;
}
} }
/** . /** .
@ -39,7 +49,14 @@ public class ARIA extends AbstractComponent {
* @return * @return
*/ */
public String getAlgorithm() { public String getAlgorithm() {
return algorithm; if (!isEmpty(algorithm))
return algorithm;
if (properties != null) {
return algorithm = properties.getString("aria.algorithm");
} else {
return algorithm;
}
} }
/** . SHA-256. /** . SHA-256.
@ -78,6 +95,42 @@ public class ARIA extends AbstractComponent {
return Base64.getEncoder().encodeToString(bytes); return Base64.getEncoder().encodeToString(bytes);
} }
public <T> void encrypt(Function<T, String> getter, BiConsumer<T, String> setter, Iterable<T> objs) {
convert(
obj -> {
String str = getter.apply(obj);
return encrypt(str);
},
setter,
objs
);
}
public <T> void encrypt(Function<T, String> getter, BiConsumer<T, String> setter, T... objs) {
encrypt(getter, setter, List.of(objs));
}
public void encrypt(String fieldName, Iterable<DataObject> rows) {
encrypt(
row -> row.string(fieldName),
(row, str) -> row.set(fieldName, str),
rows
);
}
public void encrypt(String fieldName, DataObject... rows) {
encrypt(fieldName, List.of(rows));
}
private <T> void convert(Function<T, String> converter, BiConsumer<T, String> setter, Iterable<T> objs) {
if (isEmpty(objs)) return;
objs.forEach(obj -> {
String str = converter.apply(obj);
setter.accept(obj, str);
});
}
private EgovPasswordEncoder passwordEncoder() { private EgovPasswordEncoder passwordEncoder() {
if (passwordEncoder == null) { if (passwordEncoder == null) {
passwordEncoder = new EgovPasswordEncoder(); passwordEncoder = new EgovPasswordEncoder();
@ -107,6 +160,33 @@ public class ARIA extends AbstractComponent {
return new String(service().decrypt(bytes, key)); return new String(service().decrypt(bytes, key));
} }
public <T> void decrypt(Function<T, String> getter, BiConsumer<T, String> setter, Iterable<T> objs) {
convert(
obj -> {
String str = getter.apply(obj);
return decrypt(str);
},
setter,
objs
);
}
public <T> void decrypt(Function<T, String> getter, BiConsumer<T, String> setter, T... objs) {
decrypt(getter, setter, List.of(objs));
}
public void decrypt(String fieldName, Iterable<DataObject> rows) {
decrypt(
row -> row.string(fieldName),
(row, str) -> row.set(fieldName, str),
rows
);
}
public void decrypt(String fieldName, DataObject... rows) {
decrypt(fieldName, List.of(rows));
}
/** . /** .
* @return ARIA * @return ARIA
*/ */

@ -0,0 +1,113 @@
package cokr.xit.foundation.data.paging;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import cokr.xit.foundation.AbstractComponent;
/** MyBatis Interceptor
* @author mjkhan
*/
@Intercepts({
@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}),
@Signature(type = StatementHandler.class, method = "parameterize", args = {Statement.class}),
@Signature(type = StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),
@Signature(type = StatementHandler.class, method = "update", args = {Statement.class}),
@Signature(type = ParameterHandler.class, method = "getParameterObject", args = {}),
@Signature(type = ParameterHandler.class, method = "setParameters", args = {PreparedStatement.class}),
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})
})
public class MybatisPlugin extends AbstractComponent implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object target = invocation.getTarget();
Method method = invocation.getMethod();
Object[] args = invocation.getArgs();
String methodName = method.toString();
System.out.println(methodName);
if (methodName.contains("Executor.query"))
return query((Executor)target, (MappedStatement)args[0], args[1], (RowBounds)args[2], (ResultHandler<?>)args[3]);
else if (methodName.contains("Executor.update"))
return update((Executor)target, (MappedStatement)args[0], args[1]);
else if (methodName.contains("StatementHandler.prepare"))
return prepare((StatementHandler)target, (Connection)args[0], (Integer)args[1]);
else if (methodName.contains("StatementHandler.parameterize"))
return parameterize((StatementHandler)target, (Statement)args[0]);
else if (methodName.contains("StatementHandler.query"))
return query((StatementHandler)target, (Statement)args[0], (ResultHandler<?>)args[1]);
else if (methodName.contains("StatementHandler.update"))
return update((StatementHandler)target, (Statement)args[0]);
else if (methodName.contains("ParameterHandler.getParameterObject"))
return getParameterObject((ParameterHandler)target);
else if (methodName.contains("ParameterHandler.setParameters"))
return setParameters((ParameterHandler)target, (PreparedStatement)args[0]);
else if (methodName.contains("ResultSetHandler.handleResultSets"))
return handle((ResultSetHandler)target, (Statement)args[0]);
else
return invocation.proceed();
}
protected Object query(Executor executor, MappedStatement mappedStatement, Object obj, RowBounds rowBounds, ResultHandler<?> resultHandler) throws SQLException {
return executor.query(mappedStatement, obj, rowBounds, resultHandler);
}
protected Object update(Executor executor, MappedStatement mappedStatement, Object obj) throws SQLException {
return executor.update(mappedStatement, obj);
}
protected Object prepare(StatementHandler statementHandler, Connection connection, Integer timeout) throws SQLException {
return statementHandler.prepare(connection, timeout);
}
protected Object parameterize(StatementHandler statementHandler, Statement statement) throws SQLException {
statementHandler.parameterize(statement);
return null;
}
protected Object getParameterObject(ParameterHandler parameterHandler) {
return parameterHandler.getParameterObject();
}
protected Object setParameters(ParameterHandler parameterHandler, PreparedStatement statement) throws SQLException {
parameterHandler.setParameters(statement);
return null;
}
protected Object query(StatementHandler statementHandler, Statement statement, ResultHandler<?> resultHandler) throws SQLException {
return statementHandler.query(statement, resultHandler);
}
protected int update(StatementHandler statementHandler, Statement statement) throws SQLException {
return statementHandler.update(statement);
}
protected Object handle(ResultSetHandler resultSetHandler, Statement statement) throws SQLException {
return resultSetHandler.handleResultSets(statement);
}
}
Loading…
Cancel
Save