From c32bcfd8adb6e97e5305876e8ad3f7597849303c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 14 Oct 2024 00:39:19 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20EncryptorManager=20?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E5=86=85=E5=AD=98=E8=86=A8=E8=83=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/encrypt/core/EncryptorManager.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/EncryptorManager.java b/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/EncryptorManager.java index a6d3cf9c..2d795e07 100644 --- a/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/EncryptorManager.java +++ b/ruoyi-common/ruoyi-common-encrypt/src/main/java/org/dromara/common/encrypt/core/EncryptorManager.java @@ -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 encryptorMap = new ConcurrentHashMap<>(); + Map 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()); } /**