init: 导入RuoYi‑Vue‑Plus 6.X完整代码
This commit is contained in:
@@ -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">
|
||||
<parent>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-sensitive</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-sensitive 脱敏模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 序列化模块 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-json</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package org.dromara.common.sensitive.annotation;
|
||||
|
||||
import org.dromara.common.sensitive.core.SensitiveStrategy;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 数据脱敏注解
|
||||
*
|
||||
* @author zhujie
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Documented
|
||||
public @interface Sensitive {
|
||||
|
||||
/**
|
||||
* 脱敏策略。
|
||||
*
|
||||
* @return 脱敏策略
|
||||
*/
|
||||
SensitiveStrategy strategy();
|
||||
|
||||
/**
|
||||
* 角色标识符 多个角色满足一个即可
|
||||
*/
|
||||
String[] roleKey() default {};
|
||||
|
||||
/**
|
||||
* 权限标识符 多个权限满足一个即可
|
||||
*/
|
||||
String[] perms() default {};
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package org.dromara.common.sensitive.config;
|
||||
|
||||
import org.dromara.common.sensitive.handler.SensitiveJsonFieldProcessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* 脱敏模块配置。
|
||||
*/
|
||||
@AutoConfiguration
|
||||
public class SensitiveConfig {
|
||||
|
||||
/**
|
||||
* 创建脱敏 JSON 字段处理器。
|
||||
*
|
||||
* @return 脱敏 JSON 字段处理器
|
||||
*/
|
||||
@Bean
|
||||
public SensitiveJsonFieldProcessor sensitiveJsonFieldProcessor() {
|
||||
return new SensitiveJsonFieldProcessor();
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package org.dromara.common.sensitive.core;
|
||||
|
||||
/**
|
||||
* 脱敏服务
|
||||
* 默认管理员不过滤
|
||||
* 需自行根据业务重写实现
|
||||
*
|
||||
* @author Lion Li
|
||||
* @version 3.6.0
|
||||
*/
|
||||
public interface SensitiveService {
|
||||
|
||||
/**
|
||||
* 是否脱敏
|
||||
*/
|
||||
boolean isSensitive(String[] roleKey, String[] perms);
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package org.dromara.common.sensitive.core;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.dromara.common.core.utils.DesensitizedUtils;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 脱敏策略
|
||||
*
|
||||
* @author Yjoioooo
|
||||
* @version 3.6.0
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public enum SensitiveStrategy {
|
||||
|
||||
/**
|
||||
* 身份证脱敏
|
||||
*/
|
||||
ID_CARD(s -> DesensitizedUtil.idCardNum(s, 3, 4)),
|
||||
|
||||
/**
|
||||
* 手机号脱敏
|
||||
*/
|
||||
PHONE(DesensitizedUtil::mobilePhone),
|
||||
|
||||
/**
|
||||
* 地址脱敏
|
||||
*/
|
||||
ADDRESS(s -> DesensitizedUtil.address(s, 8)),
|
||||
|
||||
/**
|
||||
* 邮箱脱敏
|
||||
*/
|
||||
EMAIL(DesensitizedUtil::email),
|
||||
|
||||
/**
|
||||
* 银行卡
|
||||
*/
|
||||
BANK_CARD(DesensitizedUtil::bankCard),
|
||||
|
||||
/**
|
||||
* 中文名
|
||||
*/
|
||||
CHINESE_NAME(DesensitizedUtil::chineseName),
|
||||
|
||||
/**
|
||||
* 固定电话
|
||||
*/
|
||||
FIXED_PHONE(DesensitizedUtil::fixedPhone),
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
USER_ID(s -> Convert.toStr(DesensitizedUtil.userId())),
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
PASSWORD(DesensitizedUtil::password),
|
||||
|
||||
/**
|
||||
* ipv4
|
||||
*/
|
||||
IPV4(DesensitizedUtil::ipv4),
|
||||
|
||||
/**
|
||||
* ipv6
|
||||
*/
|
||||
IPV6(DesensitizedUtil::ipv6),
|
||||
|
||||
/**
|
||||
* 中国大陆车牌,包含普通车辆、新能源车辆
|
||||
*/
|
||||
CAR_LICENSE(DesensitizedUtil::carLicense),
|
||||
|
||||
/**
|
||||
* 只显示第一个字符
|
||||
*/
|
||||
FIRST_MASK(DesensitizedUtil::firstMask),
|
||||
|
||||
/**
|
||||
* 通用字符串脱敏
|
||||
* 可配置前后可见长度和中间掩码长度
|
||||
* 默认示例:前4位可见,后4位可见,中间固定4个*
|
||||
*/
|
||||
STRING_MASK(s -> DesensitizedUtils.mask(s, 4, 4, 4)),
|
||||
|
||||
/**
|
||||
* 高安全级别脱敏(Token / 私钥):前2位可见,后2位可见,中间全部掩码
|
||||
*/
|
||||
MASK_HIGH_SECURITY(s -> DesensitizedUtils.maskHighSecurity(s, 2, 2)),
|
||||
|
||||
/**
|
||||
* 清空为""
|
||||
*/
|
||||
CLEAR(s -> DesensitizedUtil.clear()),
|
||||
|
||||
/**
|
||||
* 清空为null
|
||||
*/
|
||||
CLEAR_TO_NULL(s -> DesensitizedUtil.clearToNull());
|
||||
|
||||
//可自行添加其他脱敏策略
|
||||
|
||||
/**
|
||||
* 当前策略对应的脱敏函数。
|
||||
*/
|
||||
private final Function<String, String> desensitizer;
|
||||
|
||||
/**
|
||||
* 获取当前策略对应的脱敏函数。
|
||||
*
|
||||
* @return 脱敏函数
|
||||
*/
|
||||
public Function<String, String> desensitizer() {
|
||||
return desensitizer;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package org.dromara.common.sensitive.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.json.enhance.JsonEnhancementContext;
|
||||
import org.dromara.common.json.enhance.JsonFieldContext;
|
||||
import org.dromara.common.json.enhance.JsonFieldProcessor;
|
||||
import org.dromara.common.sensitive.annotation.Sensitive;
|
||||
import org.dromara.common.sensitive.core.SensitiveService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
* 响应脱敏处理器。
|
||||
*/
|
||||
@Slf4j
|
||||
@Order(100)
|
||||
public class SensitiveJsonFieldProcessor implements JsonFieldProcessor {
|
||||
|
||||
@Autowired(required = false)
|
||||
private SensitiveService sensitiveService;
|
||||
|
||||
/**
|
||||
* 判断字段是否声明了脱敏注解。
|
||||
*
|
||||
* @param fieldContext 字段上下文
|
||||
* @return 是否支持脱敏处理
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(JsonFieldContext fieldContext) {
|
||||
return fieldContext.getAnnotation(Sensitive.class) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按字段脱敏策略处理字符串值。
|
||||
*
|
||||
* @param fieldContext 字段上下文
|
||||
* @param value 字段原始值
|
||||
* @param context JSON 增强上下文
|
||||
* @return 脱敏后的字段值
|
||||
*/
|
||||
@Override
|
||||
public Object process(JsonFieldContext fieldContext, Object value, JsonEnhancementContext context) {
|
||||
Sensitive sensitive = fieldContext.getAnnotation(Sensitive.class);
|
||||
if (sensitive == null || !(value instanceof String text)) {
|
||||
return value;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive(sensitive.roleKey(), sensitive.perms())) {
|
||||
return sensitive.strategy().desensitizer().apply(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.dromara.common.sensitive.config.SensitiveConfig
|
||||
Reference in New Issue
Block a user