From cad250f02a66237258d1e96addd4704a1fdefb2f Mon Sep 17 00:00:00 2001 From: _老马_ <mayuanfei@163.com> Date: 星期三, 17 一月 2024 13:47:44 +0800 Subject: [PATCH] !479 update 优化 使用预扫描实体类提升代码性能 * 优化了数据库字段加解密的缓存机制.在自动配置类启动时,就把有加密注解的类进行缓存,以提高速度. --- ruoyi-common/ruoyi-common-sensitive/src/main/java/org/dromara/common/sensitive/handler/SensitiveHandler.java | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/ruoyi-common/ruoyi-common-sensitive/src/main/java/org/dromara/common/sensitive/handler/SensitiveHandler.java b/ruoyi-common/ruoyi-common-sensitive/src/main/java/org/dromara/common/sensitive/handler/SensitiveHandler.java index 3c8b78a..c76c83a 100644 --- a/ruoyi-common/ruoyi-common-sensitive/src/main/java/org/dromara/common/sensitive/handler/SensitiveHandler.java +++ b/ruoyi-common/ruoyi-common-sensitive/src/main/java/org/dromara/common/sensitive/handler/SensitiveHandler.java @@ -26,12 +26,14 @@ public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer { private SensitiveStrategy strategy; + private String roleKey; + private String perms; @Override public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { try { SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class); - if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive()) { + if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive(roleKey, perms)) { gen.writeString(strategy.desensitizer().apply(value)); } else { gen.writeString(value); @@ -47,6 +49,8 @@ Sensitive annotation = property.getAnnotation(Sensitive.class); if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) { this.strategy = annotation.strategy(); + this.roleKey = annotation.roleKey(); + this.perms = annotation.perms(); return this; } return prov.findValueSerializer(property.getType(), property); -- Gitblit v1.9.3