|
|
|
@ -115,15 +115,62 @@ public class CryptographySupport extends MybatisPlugin {
|
|
|
|
|
} else {
|
|
|
|
|
target.getObjectProperties().stream()
|
|
|
|
|
.filter(property -> Property.readable(obj, property))
|
|
|
|
|
// .filter(property -> PropertyUtils.isReadable(obj, property))
|
|
|
|
|
.forEach(property -> {
|
|
|
|
|
try {
|
|
|
|
|
Object val = Property.value(obj, property);
|
|
|
|
|
if (isEmpty(val)) return;
|
|
|
|
|
|
|
|
|
|
if (val instanceof String str) {
|
|
|
|
|
val = converter.apply(crypto, str);
|
|
|
|
|
} else if (val.getClass().isArray()) {
|
|
|
|
|
Object[] vals = ((Object[])val).clone();
|
|
|
|
|
for (int i = 0; i < vals.length; ++i) {
|
|
|
|
|
vals[i] = converter.apply(crypto, vals[i]);
|
|
|
|
|
}
|
|
|
|
|
val = vals;
|
|
|
|
|
} else if (val instanceof List<?> list) {
|
|
|
|
|
val = list.stream()
|
|
|
|
|
.map(e -> converter.apply(crypto, e))
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
Property.write(obj, property, val);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
private void convert(Object obj, BiFunction<Cryptography, Object, Object> converter) {
|
|
|
|
|
List<Cryptography.TargetValue> targetValues = Cryptography.Config.get().getTargetValues(obj);
|
|
|
|
|
if (targetValues.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (Cryptography.TargetValue target: targetValues) {
|
|
|
|
|
for (String cryptoDef: target.getCryptoDefs()) {
|
|
|
|
|
Cryptography crypto = cryptos.get(cryptoDef);
|
|
|
|
|
if (crypto == null) continue;
|
|
|
|
|
|
|
|
|
|
if (obj instanceof Map) {
|
|
|
|
|
Map<String, Object> map = (Map<String, Object>)obj;
|
|
|
|
|
target.getMapKeys().stream()
|
|
|
|
|
.filter(key -> map.containsKey(key))
|
|
|
|
|
.forEach(key -> {
|
|
|
|
|
Object val = map.get(key);
|
|
|
|
|
map.put(key, converter.apply(crypto, val));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
target.getObjectProperties().stream()
|
|
|
|
|
.filter(property -> Property.readable(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);
|
|
|
|
|
}
|
|
|
|
@ -135,7 +182,7 @@ public class CryptographySupport extends MybatisPlugin {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
private void decrypt(Object obj) {
|
|
|
|
|
if (!isEnabled(obj)) return;
|
|
|
|
|
|
|
|
|
|