Skip to content

Commit

Permalink
Merge pull request #6339 from EightMonth/master
Browse files Browse the repository at this point in the history
还原原有数据脱敏功能并新增@sensitive脱敏注解,不依赖原有数据脱敏功能
  • Loading branch information
zhangdaiscott authored Jun 20, 2024
2 parents 56ca53c + c687c7a commit c582efd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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;
Expand All @@ -24,7 +24,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
public class SensitiveFieldSerialize extends JsonSerializer<String> implements ContextualSerializer {
public class SensitiveSerialize extends JsonSerializer<String> implements ContextualSerializer {

private SensitiveEnum type;

Expand Down Expand Up @@ -72,12 +72,12 @@ public void serialize(String data, JsonGenerator jsonGenerator, SerializerProvid
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 加密注解
*
* 在方法上声明 将方法返回对象中的敏感字段 加密/格式化
* @deprecated 直接在实体的字段中使用@{@link SensitiveField}即可
* @deprecated 直接在实体的字段中使用@{@link Sensitive}即可
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@JacksonAnnotationsInside
@JsonSerialize(using = SensitiveFieldSerialize.class)
public @interface SensitiveField {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

Expand Down

0 comments on commit c582efd

Please sign in to comment.