| | |
| | | package org.dromara.common.encrypt.core; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.ReflectUtil; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.io.Resources; |
| | | import org.dromara.common.core.utils.ObjectUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.encrypt.annotation.EncryptField; |
| | | import org.springframework.context.ConfigurableApplicationContext; |
| | |
| | | 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; |
| | | |
| | |
| | | /** |
| | | * 缓存加密器 |
| | | */ |
| | | Map<EncryptContext, IEncryptor> encryptorMap = new ConcurrentHashMap<>(); |
| | | Map<Integer, IEncryptor> encryptorMap = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * 类加密字段缓存 |
| | |
| | | * 获取类加密字段缓存 |
| | | */ |
| | | public Set<Field> getFieldCache(Class<?> sourceClazz) { |
| | | if (ObjectUtil.isNotNull(fieldCache)) { |
| | | return fieldCache.get(sourceClazz); |
| | | } |
| | | return null; |
| | | return ObjectUtils.notNullGetter(fieldCache, f -> f.get(sourceClazz)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | |
| | | * @param encryptContext 加密执行者需要的相关配置参数 |
| | | */ |
| | | public void removeEncryptor(EncryptContext encryptContext) { |
| | | this.encryptorMap.remove(encryptContext); |
| | | this.encryptorMap.remove(encryptContext.hashCode()); |
| | | } |
| | | |
| | | /** |