Commit e637bff8cdc7071a04489fcbe3ffa60dd5b7c344
1 parent
bbb27df5
feat: 支持 vo 返回的脱敏
Showing
7 changed files
with
173 additions
and
0 deletions
yudao-framework/pom.xml
| ... | ... | @@ -41,6 +41,7 @@ |
| 41 | 41 | <module>yudao-spring-boot-starter-flowable</module> |
| 42 | 42 | <module>yudao-spring-boot-starter-captcha</module> |
| 43 | 43 | <module>yudao-spring-boot-starter-websocket</module> |
| 44 | + <module>yudao-spring-boot-starter-biz-desensitize</module> | |
| 44 | 45 | </modules> |
| 45 | 46 | |
| 46 | 47 | <artifactId>yudao-framework</artifactId> | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 5 | + <modelVersion>4.0.0</modelVersion> | |
| 6 | + <parent> | |
| 7 | + <groupId>cn.iocoder.boot</groupId> | |
| 8 | + <artifactId>yudao-framework</artifactId> | |
| 9 | + <version>1.6.6-snapshot</version> | |
| 10 | + </parent> | |
| 11 | + | |
| 12 | + <artifactId>yudao-spring-boot-starter-biz-desensitize</artifactId> | |
| 13 | + | |
| 14 | + <properties> | |
| 15 | + <maven.compiler.source>11</maven.compiler.source> | |
| 16 | + <maven.compiler.target>11</maven.compiler.target> | |
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 18 | + </properties> | |
| 19 | + | |
| 20 | + <dependencies> | |
| 21 | + <dependency> | |
| 22 | + <groupId>cn.iocoder.boot</groupId> | |
| 23 | + <artifactId>yudao-common</artifactId> | |
| 24 | + </dependency> | |
| 25 | + </dependencies> | |
| 26 | +</project> | |
| 0 | 27 | \ No newline at end of file | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/annotation/Desensitize.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.annotation; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.desensitize.enums.DesensitizationStrategyEnum; | |
| 4 | +import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler; | |
| 5 | + | |
| 6 | +import java.lang.annotation.Documented; | |
| 7 | +import java.lang.annotation.ElementType; | |
| 8 | +import java.lang.annotation.Retention; | |
| 9 | +import java.lang.annotation.RetentionPolicy; | |
| 10 | +import java.lang.annotation.Target; | |
| 11 | + | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Desensitize 注解配置会覆盖 DesensitizationStrategyEnum 配置 | |
| 15 | + */ | |
| 16 | +@Target({ElementType.FIELD}) | |
| 17 | +@Retention(RetentionPolicy.RUNTIME) | |
| 18 | +@Documented | |
| 19 | +public @interface Desensitize { | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 脱敏策略 | |
| 23 | + */ | |
| 24 | + DesensitizationStrategyEnum strategy(); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 脱敏替换字符 | |
| 28 | + */ | |
| 29 | + String replacer(); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 正则表达式 | |
| 33 | + */ | |
| 34 | + String regex(); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 前缀保留长度 | |
| 38 | + */ | |
| 39 | + int preKeep(); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 后缀保留长度 | |
| 43 | + */ | |
| 44 | + int suffixKeep(); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 脱敏处理器 | |
| 48 | + */ | |
| 49 | + Class<? extends DesensitizationHandler> handler(); | |
| 50 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/constants/DesensitizeConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.constants; | |
| 2 | + | |
| 3 | +import lombok.AccessLevel; | |
| 4 | +import lombok.NoArgsConstructor; | |
| 5 | + | |
| 6 | +@NoArgsConstructor(access = AccessLevel.PRIVATE) | |
| 7 | +public class DesensitizeConstants { | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * 默认正则 | |
| 11 | + */ | |
| 12 | + public static final String DEFAULT_REGEX = null; | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 默认保持长度 | |
| 16 | + */ | |
| 17 | + public static final int DEFAULT_KEEP_LENGTH = -1; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 默认替换字符 | |
| 21 | + */ | |
| 22 | + public static final String DEFAULT_REPLACER = "****"; | |
| 23 | + | |
| 24 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/enums/DesensitizationStrategyEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.desensitize.enums; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | +import lombok.RequiredArgsConstructor; | |
| 5 | + | |
| 6 | +import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_KEEP_LENGTH; | |
| 7 | +import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_REGEX; | |
| 8 | +import static cn.iocoder.yudao.framework.desensitize.constants.DesensitizeConstants.DEFAULT_REPLACER; | |
| 9 | + | |
| 10 | +@Getter | |
| 11 | +@RequiredArgsConstructor | |
| 12 | +public enum DesensitizationStrategyEnum { | |
| 13 | + // 常用脱敏业务 | |
| 14 | + PHONE_NUMBER(DEFAULT_REGEX, 3, 4, DEFAULT_REPLACER), // 手机号;比如:13248765917脱敏之后为132****5917 | |
| 15 | + FIXED_PHONE(DEFAULT_REGEX, 4, 2, DEFAULT_REPLACER), // 固定电话;比如:01086551122脱敏之后为0108*****22 | |
| 16 | + ID_CARD(DEFAULT_REGEX, 6, 2, DEFAULT_REPLACER), // 身份证号码;比如:530321199204074611脱敏之后为530321**********11 | |
| 17 | + BANK_CARD(DEFAULT_REGEX, 6, 2, DEFAULT_REPLACER), // 银行卡号;比如:9988002866797031脱敏之后为998800********31 | |
| 18 | + CHINESE_NAME(DEFAULT_REGEX, 1, 0, "**"),// 中文名;比如:刘子豪脱敏之后为刘** | |
| 19 | + ADDRESS("[\\s\\S]+区", DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 地址只显示到地区,不显示详细地址;比如:广州市天河区幸福小区102号脱敏之后为广州市天河区******** | |
| 20 | + EMAIL("(^.)[^@]*(@.*$)", DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, "$1****$2"), // 邮箱;比如:example@gmail.com脱敏之后为e******@gmail.com | |
| 21 | + CAR_LICENSE(DEFAULT_REGEX, 3, 1, DEFAULT_REPLACER), // 车牌号;比如:粤A66666脱敏之后为粤A6***6 | |
| 22 | + PASSWORD(DEFAULT_REGEX, 0, 0, DEFAULT_REPLACER), // 密码;比如:123456脱敏之后为****** | |
| 23 | + | |
| 24 | + // 自定义脱敏业务 | |
| 25 | + REGEX(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 自定义正则表达式 | |
| 26 | + SLIDE(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER), // 滑动脱敏 | |
| 27 | + CUSTOM_HANDLE(DEFAULT_REGEX, DEFAULT_KEEP_LENGTH, DEFAULT_KEEP_LENGTH, DEFAULT_REPLACER); // 自定义处理器 | |
| 28 | + ; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 正则表达式 | |
| 32 | + */ | |
| 33 | + private final String regex; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 前缀保留长度 | |
| 37 | + */ | |
| 38 | + private final int preKeep; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 后缀保留长度 | |
| 42 | + */ | |
| 43 | + private final int suffixKeep; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 脱敏替换字符 | |
| 47 | + */ | |
| 48 | + private final String replacer; | |
| 49 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DefaultDesensitizationHandler.java
0 → 100644
yudao-framework/yudao-spring-boot-starter-biz-desensitize/src/main/java/cn/iocoder/yudao/framework/desensitize/handler/DesensitizationHandler.java
0 → 100644