From 8e44080b002863ce4fb03b13c576ac19575351af Mon Sep 17 00:00:00 2001 From: EightMonth <1099139462@qq.com> Date: Thu, 20 Jun 2024 17:57:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=84=B1=E6=95=8F=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E@Sensitive=E8=84=B1=E6=95=8F=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=EF=BC=8C=E4=B8=8D=E4=BE=9D=E8=B5=96=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=84=B1=E6=95=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Serialize.java => SensitiveSerialize.java} | 10 +++---- .../desensitization/annotation/Sensitive.java | 26 +++++++++++++++++++ .../annotation/SensitiveEncode.java | 2 +- .../annotation/SensitiveField.java | 2 -- .../aspect/SensitiveDataAspect.java | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) rename jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/{SensitiveFieldSerialize.java => SensitiveSerialize.java} (89%) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/SensitiveFieldSerialize.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/SensitiveSerialize.java similarity index 89% rename from jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/SensitiveFieldSerialize.java rename to jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/SensitiveSerialize.java index d65de555..f5deb5e8 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/SensitiveFieldSerialize.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/SensitiveSerialize.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.databind.ser.ContextualSerializer; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.desensitization.annotation.SensitiveField; +import org.jeecg.common.desensitization.annotation.Sensitive; import org.jeecg.common.desensitization.enums.SensitiveEnum; import org.jeecg.common.desensitization.util.SensitiveInfoUtil; import org.jeecg.common.util.encryption.AesEncryptUtil; @@ -24,7 +24,7 @@ import java.util.Objects; @NoArgsConstructor @AllArgsConstructor @Slf4j -public class SensitiveFieldSerialize extends JsonSerializer implements ContextualSerializer { +public class SensitiveSerialize extends JsonSerializer implements ContextualSerializer { private SensitiveEnum type; @@ -72,12 +72,12 @@ public class SensitiveFieldSerialize extends JsonSerializer implements C public JsonSerializer createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { if (beanProperty != null) { if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) { - SensitiveField sensitive = beanProperty.getAnnotation(SensitiveField.class); + Sensitive sensitive = beanProperty.getAnnotation(Sensitive.class); if (sensitive == null) { - sensitive = beanProperty.getContextAnnotation(SensitiveField.class); + sensitive = beanProperty.getContextAnnotation(Sensitive.class); } if (sensitive != null) { - return new SensitiveFieldSerialize(sensitive.type()); + return new SensitiveSerialize(sensitive.type()); } } return serializerProvider.findValueSerializer(beanProperty.getType(), beanProperty); diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java new file mode 100644 index 00000000..e4df8053 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java @@ -0,0 +1,26 @@ +package org.jeecg.common.desensitization.annotation; + + +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.jeecg.common.desensitization.SensitiveSerialize; +import org.jeecg.common.desensitization.enums.SensitiveEnum; + +import java.lang.annotation.*; + +/** + * 在字段上定义 标识字段存储的信息是敏感的 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@JacksonAnnotationsInside +@JsonSerialize(using = SensitiveSerialize.class) +public @interface SensitiveField { + + /** + * 不同类型处理不同 + * @return + */ + SensitiveEnum type() default SensitiveEnum.ENCODE; +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveEncode.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveEncode.java index b3a98afc..1ebd473d 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveEncode.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveEncode.java @@ -6,7 +6,7 @@ import java.lang.annotation.*; * 加密注解 * * 在方法上声明 将方法返回对象中的敏感字段 加密/格式化 - * @deprecated 直接在实体的字段中使用@{@link SensitiveField}即可 + * @deprecated 直接在实体的字段中使用@{@link Sensitive}即可 */ @Documented @Retention(RetentionPolicy.RUNTIME) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveField.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveField.java index 72d1f5e9..c0ca46cd 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveField.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/SensitiveField.java @@ -14,8 +14,6 @@ import java.lang.annotation.*; @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -@JacksonAnnotationsInside -@JsonSerialize(using = SensitiveFieldSerialize.class) public @interface SensitiveField { /** diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/aspect/SensitiveDataAspect.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/aspect/SensitiveDataAspect.java index 8b80b155..da69702b 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/aspect/SensitiveDataAspect.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/aspect/SensitiveDataAspect.java @@ -27,7 +27,7 @@ public class SensitiveDataAspect { /** * 定义切点Pointcut */ - @Pointcut("@annotation(org.jeecg.common.desensitization.annotation.SensitiveDecode)") + @Pointcut("@annotation(org.jeecg.common.desensitization.annotation.SensitiveEncode) || @annotation(org.jeecg.common.desensitization.annotation.SensitiveDecode)") public void sensitivePointCut() { } From c687c7a9167be567a832d08c135ab753718cad94 Mon Sep 17 00:00:00 2001 From: EightMonth <1099139462@qq.com> Date: Thu, 20 Jun 2024 18:03:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/desensitization/annotation/Sensitive.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java index e4df8053..466a3a01 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/desensitization/annotation/Sensitive.java @@ -16,7 +16,7 @@ import java.lang.annotation.*; @Target(ElementType.FIELD) @JacksonAnnotationsInside @JsonSerialize(using = SensitiveSerialize.class) -public @interface SensitiveField { +public @interface Sensitive { /** * 不同类型处理不同