Merge pull request #6339 from EightMonth/master

还原原有数据脱敏功能并新增@sensitive脱敏注解,不依赖原有数据脱敏功能
pull/6345/head
JEECG 2024-06-20 18:11:55 +08:00 committed by GitHub
commit c582efd115
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 9 deletions

View File

@ -9,7 +9,7 @@ import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j; 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.enums.SensitiveEnum;
import org.jeecg.common.desensitization.util.SensitiveInfoUtil; import org.jeecg.common.desensitization.util.SensitiveInfoUtil;
import org.jeecg.common.util.encryption.AesEncryptUtil; import org.jeecg.common.util.encryption.AesEncryptUtil;
@ -24,7 +24,7 @@ import java.util.Objects;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
public class SensitiveFieldSerialize extends JsonSerializer<String> implements ContextualSerializer { public class SensitiveSerialize extends JsonSerializer<String> implements ContextualSerializer {
private SensitiveEnum type; private SensitiveEnum type;
@ -72,12 +72,12 @@ public class SensitiveFieldSerialize extends JsonSerializer<String> implements C
public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException {
if (beanProperty != null) { if (beanProperty != null) {
if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) { if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) {
SensitiveField sensitive = beanProperty.getAnnotation(SensitiveField.class); Sensitive sensitive = beanProperty.getAnnotation(Sensitive.class);
if (sensitive == null) { if (sensitive == null) {
sensitive = beanProperty.getContextAnnotation(SensitiveField.class); sensitive = beanProperty.getContextAnnotation(Sensitive.class);
} }
if (sensitive != null) { if (sensitive != null) {
return new SensitiveFieldSerialize(sensitive.type()); return new SensitiveSerialize(sensitive.type());
} }
} }
return serializerProvider.findValueSerializer(beanProperty.getType(), beanProperty); return serializerProvider.findValueSerializer(beanProperty.getType(), beanProperty);

View File

@ -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 Sensitive {
/**
*
* @return
*/
SensitiveEnum type() default SensitiveEnum.ENCODE;
}

View File

@ -6,7 +6,7 @@ import java.lang.annotation.*;
* *
* *
* / * /
* @deprecated 使@{@link SensitiveField} * @deprecated 使@{@link Sensitive}
*/ */
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -14,8 +14,6 @@ import java.lang.annotation.*;
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@JacksonAnnotationsInside
@JsonSerialize(using = SensitiveFieldSerialize.class)
public @interface SensitiveField { public @interface SensitiveField {
/** /**

View File

@ -27,7 +27,7 @@ public class SensitiveDataAspect {
/** /**
* Pointcut * 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() { public void sensitivePointCut() {
} }