feat: 支持 vo 返回的脱敏
parent
bbb27df5e9
commit
e637bff8cd
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-framework</artifactId>
|
||||
<version>1.6.6-snapshot</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>yudao-spring-boot-starter-biz-desensitize</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.framework.desensitize.annotation;
|
||||
|
||||
import cn.iocoder.yudao.framework.desensitize.enums.DesensitizationStrategyEnum;
|
||||
import cn.iocoder.yudao.framework.desensitize.handler.DesensitizationHandler;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Desensitize 注解配置会覆盖 DesensitizationStrategyEnum 配置
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Desensitize {
|
||||
|
||||
/**
|
||||
* 脱敏策略
|
||||
*/
|
||||
DesensitizationStrategyEnum strategy();
|
||||
|
||||
/**
|
||||
* 脱敏替换字符
|
||||
*/
|
||||
String replacer();
|
||||
|
||||
/**
|
||||
* 正则表达式
|
||||
*/
|
||||
String regex();
|
||||
|
||||
/**
|
||||
* 前缀保留长度
|
||||
*/
|
||||
int preKeep();
|
||||
|
||||
/**
|
||||
* 后缀保留长度
|
||||
*/
|
||||
int suffixKeep();
|
||||
|
||||
/**
|
||||
* 脱敏处理器
|
||||
*/
|
||||
Class<? extends DesensitizationHandler> handler();
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.framework.desensitize.constants;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class DesensitizeConstants {
|
||||
|
||||
/**
|
||||
* 默认正则
|
||||
*/
|
||||
public static final String DEFAULT_REGEX = null;
|
||||
|
||||
/**
|
||||
* 默认保持长度
|
||||
*/
|
||||
public static final int DEFAULT_KEEP_LENGTH = -1;
|
||||
|
||||
/**
|
||||
* 默认替换字符
|
||||
*/
|
||||
public static final String DEFAULT_REPLACER = "****";
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package cn.iocoder.yudao.framework.desensitize.handler;
|
||||
|
||||
public class DefaultDesensitizationHandler implements DesensitizationHandler {
|
||||
|
||||
@Override
|
||||
public String handle(String origin) {
|
||||
return origin;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package cn.iocoder.yudao.framework.desensitize.handler;
|
||||
|
||||
public interface DesensitizationHandler {
|
||||
|
||||
/**
|
||||
* 脱敏
|
||||
*
|
||||
* @param origin 原始字符串
|
||||
* @return 脱敏后的字符串
|
||||
*/
|
||||
String handle(String origin);
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue