|
|
|
@ -17,7 +17,10 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -34,7 +37,7 @@ public class EncryptorManager {
|
|
|
|
|
/**
|
|
|
|
|
* 缓存加密器
|
|
|
|
|
*/
|
|
|
|
|
Map<EncryptContext, IEncryptor> encryptorMap = new ConcurrentHashMap<>();
|
|
|
|
|
Map<Integer, IEncryptor> encryptorMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 类加密字段缓存
|
|
|
|
@ -67,11 +70,12 @@ public class EncryptorManager {
|
|
|
|
|
* @param encryptContext 加密执行者需要的相关配置参数
|
|
|
|
|
*/
|
|
|
|
|
public IEncryptor registAndGetEncryptor(EncryptContext encryptContext) {
|
|
|
|
|
if (encryptorMap.containsKey(encryptContext)) {
|
|
|
|
|
return encryptorMap.get(encryptContext);
|
|
|
|
|
int key = encryptContext.hashCode();
|
|
|
|
|
if (encryptorMap.containsKey(key)) {
|
|
|
|
|
return encryptorMap.get(key);
|
|
|
|
|
}
|
|
|
|
|
IEncryptor encryptor = ReflectUtil.newInstance(encryptContext.getAlgorithm().getClazz(), encryptContext);
|
|
|
|
|
encryptorMap.put(encryptContext, encryptor);
|
|
|
|
|
encryptorMap.put(key, encryptor);
|
|
|
|
|
return encryptor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -81,7 +85,7 @@ public class EncryptorManager {
|
|
|
|
|
* @param encryptContext 加密执行者需要的相关配置参数
|
|
|
|
|
*/
|
|
|
|
|
public void removeEncryptor(EncryptContext encryptContext) {
|
|
|
|
|
this.encryptorMap.remove(encryptContext);
|
|
|
|
|
this.encryptorMap.remove(encryptContext.hashCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|