Commit 7b3fca28447d2947136048b5d5052462ffb44d96
1 parent
32d7d6ab
feat: 脱敏组件代码规范更新
Showing
37 changed files
with
378 additions
and
197 deletions
yudao-dependencies/pom.xml
| @@ -143,7 +143,7 @@ | @@ -143,7 +143,7 @@ | ||
| 143 | </dependency> | 143 | </dependency> |
| 144 | <dependency> | 144 | <dependency> |
| 145 | <groupId>cn.iocoder.boot</groupId> | 145 | <groupId>cn.iocoder.boot</groupId> |
| 146 | - <artifactId>yudao-spring-boot-starter-biz-desensitize</artifactId> | 146 | + <artifactId>yudao-spring-boot-starter-desensitize</artifactId> |
| 147 | <version>${revision}</version> | 147 | <version>${revision}</version> |
| 148 | </dependency> | 148 | </dependency> |
| 149 | 149 |
yudao-framework/pom.xml
| @@ -41,7 +41,7 @@ | @@ -41,7 +41,7 @@ | ||
| 41 | <module>yudao-spring-boot-starter-flowable</module> | 41 | <module>yudao-spring-boot-starter-flowable</module> |
| 42 | <module>yudao-spring-boot-starter-captcha</module> | 42 | <module>yudao-spring-boot-starter-captcha</module> |
| 43 | <module>yudao-spring-boot-starter-websocket</module> | 43 | <module>yudao-spring-boot-starter-websocket</module> |
| 44 | - <module>yudao-spring-boot-starter-biz-desensitize</module> | 44 | + <module>yudao-spring-boot-starter-desensitize</module> |
| 45 | </modules> | 45 | </modules> |
| 46 | 46 | ||
| 47 | <artifactId>yudao-framework</artifactId> | 47 | <artifactId>yudao-framework</artifactId> |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | ||
| 4 | - | ||
| 5 | -import java.lang.annotation.Annotation; | ||
| 6 | - | ||
| 7 | -public abstract class AbstractRegexDesensitizationHandler<T extends Annotation> implements DesensitizationHandler<T> { | ||
| 8 | - | ||
| 9 | - @Override | ||
| 10 | - public String desensitize(String origin, T anno) { | ||
| 11 | - Object[] args = getArgs(anno); | ||
| 12 | - String regex = (String) args[0]; | ||
| 13 | - String replacer = (String) args[1]; | ||
| 14 | - | ||
| 15 | - return origin.replaceAll(regex, replacer); | ||
| 16 | - } | ||
| 17 | - | ||
| 18 | - // TODO @城:是不是抽象两个方法,一个拿 regex;一个拿 replacer | ||
| 19 | - | ||
| 20 | - /** | ||
| 21 | - * 获取注解的参数 | ||
| 22 | - * | ||
| 23 | - * @param anno 注解信息 | ||
| 24 | - * @return 注解的参数 | ||
| 25 | - */ | ||
| 26 | - abstract Object[] getArgs(T anno); | ||
| 27 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; | ||
| 4 | - | ||
| 5 | -public class BankCardDesensitization extends AbstractDesensitizationHandler<BankCard> { | ||
| 6 | - | ||
| 7 | - @Override | ||
| 8 | - Object[] getArgs(BankCard anno) { | ||
| 9 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 10 | - } | ||
| 11 | -} | ||
| 12 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; | ||
| 4 | - | ||
| 5 | -public class CarLicenseDesensitization extends AbstractDesensitizationHandler<CarLicense> { | ||
| 6 | - @Override | ||
| 7 | - Object[] getArgs(CarLicense anno) { | ||
| 8 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 9 | - } | ||
| 10 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; | ||
| 4 | - | ||
| 5 | -public class ChineseNameDesensitization extends AbstractDesensitizationHandler<ChineseName> { | ||
| 6 | - @Override | ||
| 7 | - Object[] getArgs(ChineseName anno) { | ||
| 8 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 9 | - } | ||
| 10 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; | ||
| 4 | - | ||
| 5 | -public class FixedPhoneDesensitization extends AbstractDesensitizationHandler<FixedPhone> { | ||
| 6 | - @Override | ||
| 7 | - Object[] getArgs(FixedPhone anno) { | ||
| 8 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 9 | - } | ||
| 10 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; | ||
| 4 | - | ||
| 5 | -public class IdCardDesensitization extends AbstractDesensitizationHandler<IdCard> { | ||
| 6 | - @Override | ||
| 7 | - Object[] getArgs(IdCard anno) { | ||
| 8 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 9 | - } | ||
| 10 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; | ||
| 4 | - | ||
| 5 | -public class PasswordDesensitization extends AbstractDesensitizationHandler<Password> { | ||
| 6 | - @Override | ||
| 7 | - Object[] getArgs(Password anno) { | ||
| 8 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 9 | - } | ||
| 10 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java deleted
| 1 | -package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; | ||
| 4 | - | ||
| 5 | -public class PhoneNumberDesensitization extends AbstractDesensitizationHandler<PhoneNumber> { | ||
| 6 | - | ||
| 7 | - @Override | ||
| 8 | - Object[] getArgs(PhoneNumber anno) { | ||
| 9 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | ||
| 10 | - } | ||
| 11 | -} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml renamed to yudao-framework/yudao-spring-boot-starter-desensitize/pom.xml
| @@ -9,16 +9,8 @@ | @@ -9,16 +9,8 @@ | ||
| 9 | <version>${revision}</version> | 9 | <version>${revision}</version> |
| 10 | </parent> | 10 | </parent> |
| 11 | 11 | ||
| 12 | - <!-- TODO 城:yudao-spring-boot-starter-biz-desensitize =》yudao-spring-boot-starter-desensitize,不属于业务哈 --> | ||
| 13 | - <artifactId>yudao-spring-boot-starter-biz-desensitize</artifactId> | ||
| 14 | - <!-- TODO 城:这个组件的说明; --> | ||
| 15 | - | ||
| 16 | - <!-- TODO 城:这里去掉哈 --> | ||
| 17 | - <properties> | ||
| 18 | - <maven.compiler.source>11</maven.compiler.source> | ||
| 19 | - <maven.compiler.target>11</maven.compiler.target> | ||
| 20 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 21 | - </properties> | 12 | + <artifactId>yudao-spring-boot-starter-desensitize</artifactId> |
| 13 | + <description>脱敏组件</description> | ||
| 22 | 14 | ||
| 23 | <dependencies> | 15 | <dependencies> |
| 24 | <dependency> | 16 | <dependency> |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerHolder.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/DesensitizationHandlerFactory.java
| @@ -2,33 +2,28 @@ package cn.iocoder.yudao.framework.desensitize.core.base; | @@ -2,33 +2,28 @@ package cn.iocoder.yudao.framework.desensitize.core.base; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.ReflectUtil; | 3 | import cn.hutool.core.util.ReflectUtil; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | 4 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; |
| 5 | -import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; | ||
| 6 | -import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; | ||
| 7 | 5 | ||
| 8 | import java.util.Map; | 6 | import java.util.Map; |
| 9 | import java.util.concurrent.ConcurrentHashMap; | 7 | import java.util.concurrent.ConcurrentHashMap; |
| 10 | 8 | ||
| 11 | -// TODO @城:DesensitizationHandlerHolder =》 DesensitizationHandlerFactory? Holder 没有太多工厂的味道哈 | ||
| 12 | /** | 9 | /** |
| 13 | * 脱敏处理器 Holder | 10 | * 脱敏处理器 Holder |
| 11 | + * | ||
| 12 | + * @author gaibu | ||
| 14 | */ | 13 | */ |
| 15 | -public class DesensitizationHandlerHolder { | 14 | +public class DesensitizationHandlerFactory { |
| 16 | 15 | ||
| 17 | /** | 16 | /** |
| 18 | * handler 缓存,默认初始化内置的处理器 | 17 | * handler 缓存,默认初始化内置的处理器 |
| 19 | */ | 18 | */ |
| 20 | - private static final Map<Class<? extends DesensitizationHandler>, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap<>() {{ | ||
| 21 | - // TODO @城:这 2 个,是不是不用呀?需要的时候初始化 | ||
| 22 | - put(DefaultRegexDesensitizationHandler.class, new DefaultRegexDesensitizationHandler()); | ||
| 23 | - put(DefaultDesensitizationHandler.class, new DefaultDesensitizationHandler()); | ||
| 24 | - }}; | 19 | + private static final Map<Class<? extends DesensitizationHandler>, DesensitizationHandler> HANDLER_MAP = new ConcurrentHashMap<Class<? extends DesensitizationHandler>, DesensitizationHandler>(); |
| 25 | 20 | ||
| 26 | public static DesensitizationHandler getDesensitizationHandler(Class<? extends DesensitizationHandler> clazz) { | 21 | public static DesensitizationHandler getDesensitizationHandler(Class<? extends DesensitizationHandler> clazz) { |
| 27 | DesensitizationHandler handler = HANDLER_MAP.get(clazz); | 22 | DesensitizationHandler handler = HANDLER_MAP.get(clazz); |
| 28 | if (handler != null) { | 23 | if (handler != null) { |
| 29 | return handler; | 24 | return handler; |
| 30 | } | 25 | } |
| 31 | - synchronized (DesensitizationHandlerHolder.class) { | 26 | + synchronized (DesensitizationHandlerFactory.class) { |
| 32 | handler = HANDLER_MAP.get(clazz); | 27 | handler = HANDLER_MAP.get(clazz); |
| 33 | // 双重校验锁 | 28 | // 双重校验锁 |
| 34 | if (handler != null) { | 29 | if (handler != null) { |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/Desensitize.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/annotation/DesensitizeBy.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.base.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.base.annotation; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | 3 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; |
| 4 | -import cn.iocoder.yudao.framework.desensitize.serializer.StringDesensitizeSerializer; | 4 | +import cn.iocoder.yudao.framework.desensitize.core.base.serializer.StringDesensitizeSerializer; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; | 6 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| 7 | 7 | ||
| @@ -11,21 +11,20 @@ import java.lang.annotation.Retention; | @@ -11,21 +11,20 @@ import java.lang.annotation.Retention; | ||
| 11 | import java.lang.annotation.RetentionPolicy; | 11 | import java.lang.annotation.RetentionPolicy; |
| 12 | import java.lang.annotation.Target; | 12 | import java.lang.annotation.Target; |
| 13 | 13 | ||
| 14 | -// TODO @城:每个接口上,author 写下哈。 | ||
| 15 | -// TODO @城:Desensitize = 》DesensitizeBy | ||
| 16 | -// TODO @城:Desensitize 类注释,方便读者阅读理解 | ||
| 17 | /** | 14 | /** |
| 18 | - * Desensitize 顶级脱敏注解 | 15 | + * 顶级脱敏注解,自定义注解需要使用此注解。 |
| 16 | + * | ||
| 17 | + * @author gaibu | ||
| 19 | */ | 18 | */ |
| 20 | @Documented | 19 | @Documented |
| 21 | @Target(ElementType.ANNOTATION_TYPE) | 20 | @Target(ElementType.ANNOTATION_TYPE) |
| 22 | @Retention(RetentionPolicy.RUNTIME) | 21 | @Retention(RetentionPolicy.RUNTIME) |
| 23 | -@JacksonAnnotationsInside // TODO @城:这个的作用,也可以写下 | ||
| 24 | -@JsonSerialize(using = StringDesensitizeSerializer.class) // TODO @城:这个的作用,也可以写下 | ||
| 25 | -public @interface Desensitize { | 22 | +@JacksonAnnotationsInside // 此注解是其他所有 jackson 注解的元注解,打上了此注解的注解表明是 jackson 注解的一部分 |
| 23 | +@JsonSerialize(using = StringDesensitizeSerializer.class) // 指定序列化器 | ||
| 24 | +public @interface DesensitizeBy { | ||
| 26 | 25 | ||
| 27 | /** | 26 | /** |
| 28 | * 脱敏处理器 | 27 | * 脱敏处理器 |
| 29 | */ | 28 | */ |
| 30 | - Class<? extends DesensitizationHandler> desensitizationBy(); // TODO @城:desensitizationBy -> handler | 29 | + Class<? extends DesensitizationHandler> handler(); |
| 31 | } | 30 | } |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java
| @@ -10,10 +10,10 @@ public interface DesensitizationHandler<T extends Annotation> { | @@ -10,10 +10,10 @@ public interface DesensitizationHandler<T extends Annotation> { | ||
| 10 | /** | 10 | /** |
| 11 | * 脱敏 | 11 | * 脱敏 |
| 12 | * | 12 | * |
| 13 | - * @param origin 原始字符串 | ||
| 14 | - * @param anno 注解信息 // TODO 不要这样的缩写哈,anno -> annotation | 13 | + * @param origin 原始字符串 |
| 14 | + * @param annotation 注解信息 | ||
| 15 | * @return 脱敏后的字符串 | 15 | * @return 脱敏后的字符串 |
| 16 | */ | 16 | */ |
| 17 | - String desensitize(String origin, T anno); | 17 | + String desensitize(String origin, T annotation); |
| 18 | 18 | ||
| 19 | } | 19 | } |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/serializer/StringDesensitizeSerializer.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/serializer/StringDesensitizeSerializer.java
| 1 | -package cn.iocoder.yudao.framework.desensitize.serializer; | 1 | +package cn.iocoder.yudao.framework.desensitize.core.base.serializer; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.annotation.AnnotationUtil; | 3 | import cn.hutool.core.annotation.AnnotationUtil; |
| 4 | import cn.hutool.core.util.ArrayUtil; | 4 | import cn.hutool.core.util.ArrayUtil; |
| 5 | import cn.hutool.core.util.ReflectUtil; | 5 | import cn.hutool.core.util.ReflectUtil; |
| 6 | import cn.hutool.core.util.StrUtil; | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 7 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 8 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | 8 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; |
| 9 | -import cn.iocoder.yudao.framework.desensitize.core.base.DesensitizationHandlerHolder; | 9 | +import cn.iocoder.yudao.framework.desensitize.core.base.DesensitizationHandlerFactory; |
| 10 | import com.fasterxml.jackson.core.JsonGenerator; | 10 | import com.fasterxml.jackson.core.JsonGenerator; |
| 11 | import com.fasterxml.jackson.databind.BeanProperty; | 11 | import com.fasterxml.jackson.databind.BeanProperty; |
| 12 | import com.fasterxml.jackson.databind.JsonMappingException; | 12 | import com.fasterxml.jackson.databind.JsonMappingException; |
| @@ -14,40 +14,36 @@ import com.fasterxml.jackson.databind.JsonSerializer; | @@ -14,40 +14,36 @@ import com.fasterxml.jackson.databind.JsonSerializer; | ||
| 14 | import com.fasterxml.jackson.databind.SerializerProvider; | 14 | import com.fasterxml.jackson.databind.SerializerProvider; |
| 15 | import com.fasterxml.jackson.databind.ser.ContextualSerializer; | 15 | import com.fasterxml.jackson.databind.ser.ContextualSerializer; |
| 16 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; | 16 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; |
| 17 | +import lombok.Getter; | ||
| 18 | +import lombok.Setter; | ||
| 17 | 19 | ||
| 18 | import java.io.IOException; | 20 | import java.io.IOException; |
| 19 | import java.lang.annotation.Annotation; | 21 | import java.lang.annotation.Annotation; |
| 20 | import java.lang.reflect.Field; | 22 | import java.lang.reflect.Field; |
| 21 | 23 | ||
| 22 | -// TODO @城:挪到 base/serializer 包下 | ||
| 23 | /** | 24 | /** |
| 24 | * 脱敏序列化器 | 25 | * 脱敏序列化器 |
| 26 | + * | ||
| 27 | + * @author gaibu | ||
| 25 | */ | 28 | */ |
| 26 | public class StringDesensitizeSerializer extends StdSerializer<String> implements ContextualSerializer { | 29 | public class StringDesensitizeSerializer extends StdSerializer<String> implements ContextualSerializer { |
| 27 | 30 | ||
| 31 | + @Getter | ||
| 32 | + @Setter | ||
| 28 | private DesensitizationHandler desensitizationHandler; | 33 | private DesensitizationHandler desensitizationHandler; |
| 29 | 34 | ||
| 30 | protected StringDesensitizeSerializer() { | 35 | protected StringDesensitizeSerializer() { |
| 31 | super(String.class); | 36 | super(String.class); |
| 32 | } | 37 | } |
| 33 | 38 | ||
| 34 | - // TODO @城:get 和 set 方法是必须的么?如果是的话,可以换成 lombok 注解哈,简洁一点~ | ||
| 35 | - public DesensitizationHandler getDesensitizationHandler() { | ||
| 36 | - return desensitizationHandler; | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - public void setDesensitizationHandler(DesensitizationHandler desensitizationHandler) { | ||
| 40 | - this.desensitizationHandler = desensitizationHandler; | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | @Override | 39 | @Override |
| 44 | public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { | 40 | public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException { |
| 45 | - Desensitize annotation = beanProperty.getAnnotation(Desensitize.class); | 41 | + DesensitizeBy annotation = beanProperty.getAnnotation(DesensitizeBy.class); |
| 46 | if (annotation == null) { | 42 | if (annotation == null) { |
| 47 | return this; | 43 | return this; |
| 48 | } | 44 | } |
| 49 | StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); | 45 | StringDesensitizeSerializer serializer = new StringDesensitizeSerializer(); |
| 50 | - serializer.setDesensitizationHandler(DesensitizationHandlerHolder.getDesensitizationHandler(annotation.desensitizationBy())); | 46 | + serializer.setDesensitizationHandler(DesensitizationHandlerFactory.getDesensitizationHandler(annotation.handler())); |
| 51 | return serializer; | 47 | return serializer; |
| 52 | } | 48 | } |
| 53 | 49 | ||
| @@ -57,21 +53,17 @@ public class StringDesensitizeSerializer extends StdSerializer<String> implement | @@ -57,21 +53,17 @@ public class StringDesensitizeSerializer extends StdSerializer<String> implement | ||
| 57 | gen.writeNull(); | 53 | gen.writeNull(); |
| 58 | return; | 54 | return; |
| 59 | } | 55 | } |
| 60 | - | ||
| 61 | - // TODO @城:抽个 private getField 方法。让这个方法的逻辑主干,更清晰 | ||
| 62 | - String currentName = gen.getOutputContext().getCurrentName(); | ||
| 63 | - Object currentValue = gen.getCurrentValue(); | ||
| 64 | - Class<?> currentValueClass = currentValue.getClass(); | ||
| 65 | - Field field = ReflectUtil.getField(currentValueClass, currentName); | 56 | + // 获取序列化字段 |
| 57 | + Field field = getField(gen); | ||
| 66 | 58 | ||
| 67 | // 自定义处理器 | 59 | // 自定义处理器 |
| 68 | - Desensitize[] annotations = AnnotationUtil.getCombinationAnnotations(field, Desensitize.class); | 60 | + DesensitizeBy[] annotations = AnnotationUtil.getCombinationAnnotations(field, DesensitizeBy.class); |
| 69 | if (ArrayUtil.isEmpty(annotations)) { | 61 | if (ArrayUtil.isEmpty(annotations)) { |
| 70 | gen.writeString(value); | 62 | gen.writeString(value); |
| 71 | return; | 63 | return; |
| 72 | } | 64 | } |
| 73 | for (Annotation annotation : field.getAnnotations()) { | 65 | for (Annotation annotation : field.getAnnotations()) { |
| 74 | - if (AnnotationUtil.hasAnnotation(annotation.annotationType(), Desensitize.class)) { | 66 | + if (AnnotationUtil.hasAnnotation(annotation.annotationType(), DesensitizeBy.class)) { |
| 75 | value = this.desensitizationHandler.desensitize(value, annotation); | 67 | value = this.desensitizationHandler.desensitize(value, annotation); |
| 76 | gen.writeString(value); | 68 | gen.writeString(value); |
| 77 | return; | 69 | return; |
| @@ -80,4 +72,17 @@ public class StringDesensitizeSerializer extends StdSerializer<String> implement | @@ -80,4 +72,17 @@ public class StringDesensitizeSerializer extends StdSerializer<String> implement | ||
| 80 | gen.writeString(value); | 72 | gen.writeString(value); |
| 81 | } | 73 | } |
| 82 | 74 | ||
| 75 | + /** | ||
| 76 | + * 获取字段 | ||
| 77 | + * | ||
| 78 | + * @param gen JsonGenerator | ||
| 79 | + * @return 字段 | ||
| 80 | + */ | ||
| 81 | + private Field getField(JsonGenerator gen) { | ||
| 82 | + String currentName = gen.getOutputContext().getCurrentName(); | ||
| 83 | + Object currentValue = gen.getCurrentValue(); | ||
| 84 | + Class<?> currentValueClass = currentValue.getClass(); | ||
| 85 | + return ReflectUtil.getField(currentValueClass, currentName); | ||
| 86 | + } | ||
| 87 | + | ||
| 83 | } | 88 | } |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.regex.handler.EmailDesensitizationHandler; | 4 | import cn.iocoder.yudao.framework.desensitize.core.regex.handler.EmailDesensitizationHandler; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,17 +12,20 @@ import java.lang.annotation.Target; | @@ -12,17 +12,20 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 邮箱 | 14 | * 邮箱 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = EmailDesensitizationHandler.class) | 22 | +@DesensitizeBy(handler = EmailDesensitizationHandler.class) |
| 21 | public @interface EmailDesensitize { | 23 | public @interface EmailDesensitize { |
| 24 | + | ||
| 22 | /** | 25 | /** |
| 23 | * 匹配的正则表达式 | 26 | * 匹配的正则表达式 |
| 24 | */ | 27 | */ |
| 25 | - String regex() default "(^.)[^@]*(@.*$)"; | 28 | + String regex() default "(^.)[^@]*(@.*$)"; |
| 26 | 29 | ||
| 27 | /** | 30 | /** |
| 28 | * 替换规则,邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com | 31 | * 替换规则,邮箱;比如:example@gmail.com脱敏之后为e****@gmail.com |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.regex.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; | 4 | import cn.iocoder.yudao.framework.desensitize.core.regex.handler.DefaultRegexDesensitizationHandler; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,13 +12,16 @@ import java.lang.annotation.Target; | @@ -12,13 +12,16 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 正则脱敏注解 | 14 | * 正则脱敏注解 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) | 19 | @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = DefaultRegexDesensitizationHandler.class) | 22 | +@DesensitizeBy(handler = DefaultRegexDesensitizationHandler.class) |
| 21 | public @interface RegexDesensitize { | 23 | public @interface RegexDesensitize { |
| 24 | + | ||
| 22 | /** | 25 | /** |
| 23 | * 匹配的正则表达式(默认匹配所有) | 26 | * 匹配的正则表达式(默认匹配所有) |
| 24 | */ | 27 | */ |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | ||
| 4 | + | ||
| 5 | +import java.lang.annotation.Annotation; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 正则表达式脱敏处理器抽象类,已实现通用的方法 | ||
| 9 | + * | ||
| 10 | + * @author gaibu | ||
| 11 | + */ | ||
| 12 | +public abstract class AbstractRegexDesensitizationHandler<T extends Annotation> implements DesensitizationHandler<T> { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public String desensitize(String origin, T annotation) { | ||
| 16 | + String regex = getRegex(annotation); | ||
| 17 | + String replacer = getReplacer(annotation); | ||
| 18 | + | ||
| 19 | + return origin.replaceAll(regex, replacer); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 获取注解上的 regex 参数 | ||
| 24 | + * | ||
| 25 | + * @param annotation 注解信息 | ||
| 26 | + * @return 正则表达式 | ||
| 27 | + */ | ||
| 28 | + abstract String getRegex(T annotation); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 获取注解上的 replacer 参数 | ||
| 32 | + * | ||
| 33 | + * @param annotation 注解信息 | ||
| 34 | + * @return 待替换的字符串 | ||
| 35 | + */ | ||
| 36 | + abstract String getReplacer(T annotation); | ||
| 37 | +} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java
| @@ -3,12 +3,20 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | @@ -3,12 +3,20 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | ||
| 3 | import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; | 3 | import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.RegexDesensitize; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | - * 正则脱敏处理器 | 6 | + * 默认正则脱敏处理器 |
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 7 | */ | 9 | */ |
| 8 | public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler<RegexDesensitize> { | 10 | public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitizationHandler<RegexDesensitize> { |
| 9 | 11 | ||
| 12 | + | ||
| 13 | + @Override | ||
| 14 | + String getRegex(RegexDesensitize annotation) { | ||
| 15 | + return annotation.regex(); | ||
| 16 | + } | ||
| 17 | + | ||
| 10 | @Override | 18 | @Override |
| 11 | - Object[] getArgs(RegexDesensitize anno) { | ||
| 12 | - return new Object[]{anno.regex(), anno.replacer()}; | 19 | + String getReplacer(RegexDesensitize annotation) { |
| 20 | + return annotation.replacer(); | ||
| 13 | } | 21 | } |
| 14 | } | 22 | } |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/EmailDesensitizationHandler.java
| @@ -2,10 +2,20 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | @@ -2,10 +2,20 @@ package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; | 3 | import cn.iocoder.yudao.framework.desensitize.core.regex.annotation.EmailDesensitize; |
| 4 | 4 | ||
| 5 | +/** | ||
| 6 | + * 邮箱脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 5 | public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler<EmailDesensitize> { | 10 | public class EmailDesensitizationHandler extends AbstractRegexDesensitizationHandler<EmailDesensitize> { |
| 6 | 11 | ||
| 7 | @Override | 12 | @Override |
| 8 | - Object[] getArgs(EmailDesensitize anno) { | ||
| 9 | - return new Object[]{anno.regex(), anno.replacer()}; | 13 | + String getRegex(EmailDesensitize annotation) { |
| 14 | + return annotation.regex(); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + String getReplacer(EmailDesensitize annotation) { | ||
| 19 | + return annotation.replacer(); | ||
| 10 | } | 20 | } |
| 11 | } | 21 | } |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCard.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.BankCardDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.BankCardDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 银行卡号 | 14 | * 银行卡号 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = BankCardDesensitization.class) | 22 | +@DesensitizeBy(handler = BankCardDesensitization.class) |
| 21 | public @interface BankCard { | 23 | public @interface BankCard { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicense.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.CarLicenseDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.CarLicenseDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 车牌号 | 14 | * 车牌号 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = CarLicenseDesensitization.class) | 22 | +@DesensitizeBy(handler = CarLicenseDesensitization.class) |
| 21 | public @interface CarLicense { | 23 | public @interface CarLicense { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseName.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.ChineseNameDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.ChineseNameDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 中文名 | 14 | * 中文名 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = ChineseNameDesensitization.class) | 22 | +@DesensitizeBy(handler = ChineseNameDesensitization.class) |
| 21 | public @interface ChineseName { | 23 | public @interface ChineseName { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhone.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.FixedPhoneDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.FixedPhoneDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 固定电话 | 14 | * 固定电话 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = FixedPhoneDesensitization.class) | 22 | +@DesensitizeBy(handler = FixedPhoneDesensitization.class) |
| 21 | public @interface FixedPhone { | 23 | public @interface FixedPhone { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCard.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.IdCardDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.IdCardDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 身份证 | 14 | * 身份证 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = IdCardDesensitization.class) | 22 | +@DesensitizeBy(handler = IdCardDesensitization.class) |
| 21 | public @interface IdCard { | 23 | public @interface IdCard { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Password.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PasswordDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PasswordDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 密码 | 14 | * 密码 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = PasswordDesensitization.class) | 22 | +@DesensitizeBy(handler = PasswordDesensitization.class) |
| 21 | public @interface Password { | 23 | public @interface Password { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PhoneNumber.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PhoneNumberDesensitization; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.PhoneNumberDesensitization; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 手机号 | 14 | * 手机号 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD}) | 19 | @Target({ElementType.FIELD}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = PhoneNumberDesensitization.class) | 22 | +@DesensitizeBy(handler = PhoneNumberDesensitization.class) |
| 21 | public @interface PhoneNumber { | 23 | public @interface PhoneNumber { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/Slider.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.annotation; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.desensitize.core.base.annotation.Desensitize; | 3 | +import cn.iocoder.yudao.framework.desensitize.core.base.annotation.DesensitizeBy; |
| 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; | 4 | import cn.iocoder.yudao.framework.desensitize.core.slider.handler.DefaultDesensitizationHandler; |
| 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | 5 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; |
| 6 | 6 | ||
| @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | @@ -12,12 +12,14 @@ import java.lang.annotation.Target; | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 滑动脱敏注解 | 14 | * 滑动脱敏注解 |
| 15 | + * | ||
| 16 | + * @author gaibu | ||
| 15 | */ | 17 | */ |
| 16 | @Documented | 18 | @Documented |
| 17 | @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) | 19 | @Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) |
| 18 | @Retention(RetentionPolicy.RUNTIME) | 20 | @Retention(RetentionPolicy.RUNTIME) |
| 19 | @JacksonAnnotationsInside | 21 | @JacksonAnnotationsInside |
| 20 | -@Desensitize(desensitizationBy = DefaultDesensitizationHandler.class) | 22 | +@DesensitizeBy(handler = DefaultDesensitizationHandler.class) |
| 21 | public @interface Slider { | 23 | public @interface Slider { |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractDesensitizationHandler.java
| @@ -4,14 +4,18 @@ import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationH | @@ -4,14 +4,18 @@ import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationH | ||
| 4 | 4 | ||
| 5 | import java.lang.annotation.Annotation; | 5 | import java.lang.annotation.Annotation; |
| 6 | 6 | ||
| 7 | +/** | ||
| 8 | + * 滑动脱敏处理器抽象类,已实现通用的方法 | ||
| 9 | + * | ||
| 10 | + * @author gaibu | ||
| 11 | + */ | ||
| 7 | public abstract class AbstractDesensitizationHandler<T extends Annotation> implements DesensitizationHandler<T> { | 12 | public abstract class AbstractDesensitizationHandler<T extends Annotation> implements DesensitizationHandler<T> { |
| 8 | 13 | ||
| 9 | @Override | 14 | @Override |
| 10 | - public String desensitize(String origin, T anno) { | ||
| 11 | - Object[] args = getArgs(anno); | ||
| 12 | - int prefixKeep = (Integer) args[0]; | ||
| 13 | - int suffixKeep = (Integer) args[1]; | ||
| 14 | - String replacer = (String) args[2]; | 15 | + public String desensitize(String origin, T annotation) { |
| 16 | + int prefixKeep = getPrefixKeep(annotation); | ||
| 17 | + int suffixKeep = getSuffixKeep(annotation); | ||
| 18 | + String replacer = getReplacer(annotation); | ||
| 15 | int length = origin.length(); | 19 | int length = origin.length(); |
| 16 | 20 | ||
| 17 | // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换 | 21 | // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换 |
| @@ -19,26 +23,41 @@ public abstract class AbstractDesensitizationHandler<T extends Annotation> imple | @@ -19,26 +23,41 @@ public abstract class AbstractDesensitizationHandler<T extends Annotation> imple | ||
| 19 | return buildReplacerByLength(replacer, length); | 23 | return buildReplacerByLength(replacer, length); |
| 20 | } | 24 | } |
| 21 | 25 | ||
| 22 | - // 情况二:如果原始字符串小于等于前后缀保留字符串长度,则原始字符串全部替换 | 26 | + // 情况二:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换 |
| 23 | if ((prefixKeep + suffixKeep) >= length) { | 27 | if ((prefixKeep + suffixKeep) >= length) { |
| 24 | return buildReplacerByLength(replacer, length); | 28 | return buildReplacerByLength(replacer, length); |
| 25 | } | 29 | } |
| 26 | 30 | ||
| 27 | - // 情况三:TODO 城 | 31 | + // 情况三:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串 |
| 28 | int interval = length - prefixKeep - suffixKeep; | 32 | int interval = length - prefixKeep - suffixKeep; |
| 29 | return origin.substring(0, prefixKeep) + | 33 | return origin.substring(0, prefixKeep) + |
| 30 | buildReplacerByLength(replacer, interval) + | 34 | buildReplacerByLength(replacer, interval) + |
| 31 | origin.substring(prefixKeep + interval); | 35 | origin.substring(prefixKeep + interval); |
| 32 | } | 36 | } |
| 33 | 37 | ||
| 34 | - // TODO @城:类似,子类直接获取到参数哈 | ||
| 35 | /** | 38 | /** |
| 36 | - * 获取注解的参数 | 39 | + * 前缀保留长度 |
| 37 | * | 40 | * |
| 38 | - * @param anno 注解信息 | ||
| 39 | - * @return 注解的参数 | 41 | + * @param annotation 注解信息 |
| 42 | + * @return 前缀保留长度 | ||
| 40 | */ | 43 | */ |
| 41 | - abstract Object[] getArgs(T anno); | 44 | + abstract Integer getPrefixKeep(T annotation); |
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 后缀保留长度 | ||
| 48 | + * | ||
| 49 | + * @param annotation 注解信息 | ||
| 50 | + * @return 后缀保留长度 | ||
| 51 | + */ | ||
| 52 | + abstract Integer getSuffixKeep(T annotation); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 替换符 | ||
| 56 | + * | ||
| 57 | + * @param annotation 注解信息 | ||
| 58 | + * @return 替换符 | ||
| 59 | + */ | ||
| 60 | + abstract String getReplacer(T annotation); | ||
| 42 | 61 | ||
| 43 | /** | 62 | /** |
| 44 | * 根据长度循环构建替换符 | 63 | * 根据长度循环构建替换符 |
| @@ -48,7 +67,11 @@ public abstract class AbstractDesensitizationHandler<T extends Annotation> imple | @@ -48,7 +67,11 @@ public abstract class AbstractDesensitizationHandler<T extends Annotation> imple | ||
| 48 | * @return 构建后的替换符 | 67 | * @return 构建后的替换符 |
| 49 | */ | 68 | */ |
| 50 | private String buildReplacerByLength(String replacer, int length) { | 69 | private String buildReplacerByLength(String replacer, int length) { |
| 51 | - return String.valueOf(replacer).repeat(Math.max(0, length)); | 70 | + StringBuilder builder = new StringBuilder(); |
| 71 | + for (int i = 0; i < length; i++) { | ||
| 72 | + builder.append(replacer); | ||
| 73 | + } | ||
| 74 | + return builder.toString(); | ||
| 52 | } | 75 | } |
| 53 | 76 | ||
| 54 | } | 77 | } |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.BankCard; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 银行卡脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class BankCardDesensitization extends AbstractDesensitizationHandler<BankCard> { | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + Integer getPrefixKeep(BankCard annotation) { | ||
| 14 | + return annotation.prefixKeep(); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + Integer getSuffixKeep(BankCard annotation) { | ||
| 19 | + return annotation.suffixKeep(); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + String getReplacer(BankCard annotation) { | ||
| 24 | + return annotation.replacer(); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | +} | ||
| 0 | \ No newline at end of file | 28 | \ No newline at end of file |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicense; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 车牌号脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class CarLicenseDesensitization extends AbstractDesensitizationHandler<CarLicense> { | ||
| 11 | + @Override | ||
| 12 | + Integer getPrefixKeep(CarLicense annotation) { | ||
| 13 | + return annotation.prefixKeep(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + Integer getSuffixKeep(CarLicense annotation) { | ||
| 18 | + return annotation.suffixKeep(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + String getReplacer(CarLicense annotation) { | ||
| 23 | + return annotation.replacer(); | ||
| 24 | + } | ||
| 25 | +} |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/ChineseNameDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.ChineseName; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 中文姓名脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class ChineseNameDesensitization extends AbstractDesensitizationHandler<ChineseName> { | ||
| 11 | + @Override | ||
| 12 | + Integer getPrefixKeep(ChineseName annotation) { | ||
| 13 | + return annotation.prefixKeep(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + Integer getSuffixKeep(ChineseName annotation) { | ||
| 18 | + return annotation.suffixKeep(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + String getReplacer(ChineseName annotation) { | ||
| 23 | + return annotation.replacer(); | ||
| 24 | + } | ||
| 25 | +} |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java renamed to yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java
| @@ -4,11 +4,22 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; | @@ -4,11 +4,22 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Slider; | ||
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * 滑动脱敏处理器 | 6 | * 滑动脱敏处理器 |
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 7 | */ | 9 | */ |
| 8 | public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler<Slider> { | 10 | public class DefaultDesensitizationHandler extends AbstractDesensitizationHandler<Slider> { |
| 11 | + @Override | ||
| 12 | + Integer getPrefixKeep(Slider annotation) { | ||
| 13 | + return annotation.prefixKeep(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + Integer getSuffixKeep(Slider annotation) { | ||
| 18 | + return annotation.suffixKeep(); | ||
| 19 | + } | ||
| 9 | 20 | ||
| 10 | @Override | 21 | @Override |
| 11 | - Object[] getArgs(Slider anno) { | ||
| 12 | - return new Object[]{anno.prefixKeep(), anno.suffixKeep(), anno.replacer()}; | 22 | + String getReplacer(Slider annotation) { |
| 23 | + return annotation.replacer(); | ||
| 13 | } | 24 | } |
| 14 | } | 25 | } |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhone; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 固定电话脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class FixedPhoneDesensitization extends AbstractDesensitizationHandler<FixedPhone> { | ||
| 11 | + @Override | ||
| 12 | + Integer getPrefixKeep(FixedPhone annotation) { | ||
| 13 | + return annotation.prefixKeep(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + Integer getSuffixKeep(FixedPhone annotation) { | ||
| 18 | + return annotation.suffixKeep(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + String getReplacer(FixedPhone annotation) { | ||
| 23 | + return annotation.replacer(); | ||
| 24 | + } | ||
| 25 | +} |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.IdCard; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 身份证脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class IdCardDesensitization extends AbstractDesensitizationHandler<IdCard> { | ||
| 11 | + @Override | ||
| 12 | + Integer getPrefixKeep(IdCard annotation) { | ||
| 13 | + return annotation.prefixKeep(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + Integer getSuffixKeep(IdCard annotation) { | ||
| 18 | + return annotation.suffixKeep(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + String getReplacer(IdCard annotation) { | ||
| 23 | + return annotation.replacer(); | ||
| 24 | + } | ||
| 25 | +} |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.Password; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 密码脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class PasswordDesensitization extends AbstractDesensitizationHandler<Password> { | ||
| 11 | + @Override | ||
| 12 | + Integer getPrefixKeep(Password annotation) { | ||
| 13 | + return annotation.prefixKeep(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + Integer getSuffixKeep(Password annotation) { | ||
| 18 | + return annotation.suffixKeep(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + String getReplacer(Password annotation) { | ||
| 23 | + return annotation.replacer(); | ||
| 24 | + } | ||
| 25 | +} |
yudao-framework/yudao-spring-boot-starter-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PhoneNumberDesensitization.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.PhoneNumber; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 手机号脱敏处理器 | ||
| 7 | + * | ||
| 8 | + * @author gaibu | ||
| 9 | + */ | ||
| 10 | +public class PhoneNumberDesensitization extends AbstractDesensitizationHandler<PhoneNumber> { | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + Integer getPrefixKeep(PhoneNumber annotation) { | ||
| 14 | + return annotation.prefixKeep(); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + Integer getSuffixKeep(PhoneNumber annotation) { | ||
| 19 | + return annotation.suffixKeep(); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + String getReplacer(PhoneNumber annotation) { | ||
| 24 | + return annotation.replacer(); | ||
| 25 | + } | ||
| 26 | +} |