增加 @NoSensitive 注解

- 在 SysUser 实体类中为手机号码字段添加 @Sensitive 注解
- 新增 @NoSensitive 注解和相关切面、拦截器,用于 “关闭” 数据脱敏
- 在用户信息相关接口中添加 @NoSensitive 注解,以 “关闭” 数据脱敏
- 新增 WebMvcConfig 配置类,注册 NoSensitiveInterceptor 拦截器
This commit is contained in:
ayi
2025-07-07 11:10:52 +08:00
parent e549210ad6
commit 2622d9147e
13 changed files with 176 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
package com.ruoyi.common.core.annotation;
import java.lang.annotation.*;
/**
* @Description “关闭” 数据脱敏
* @Author AhYi
* @Date 2025-07-07 10:23
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NoSensitive {
}

View File

@@ -0,0 +1,29 @@
package com.ruoyi.common.core.aspect;
import com.ruoyi.common.core.annotation.NoSensitive;
import com.ruoyi.common.core.context.SensitiveContextHolder;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
/**
* @Description @NoSensitive 注解切面,主要用户对方法的注解
* @Author AhYi
* @Date 2025-07-07 10:31
*/
@Aspect
@Component
public class NoSensitiveAspect {
@Around("@annotation(noSensitive)")
public Object around(ProceedingJoinPoint joinPoint, NoSensitive noSensitive) throws Throwable {
try {
SensitiveContextHolder.enterNoSensitiveScope();
return joinPoint.proceed();
} finally {
SensitiveContextHolder.exitNoSensitiveScope();
}
}
}

View File

@@ -0,0 +1,36 @@
package com.ruoyi.common.core.context;
/**
* @Description Sensitive 数据脱敏上下文管理,存储当前线程是否需要脱敏
* @Author AhYi
* @Date 2025-07-07 10:27
*/
public class SensitiveContextHolder {
private static final ThreadLocal<Integer> COUNTER = new ThreadLocal<>();
public static void enterNoSensitiveScope() {
Integer count = COUNTER.get();
if (count == null) {
count = 0;
}
COUNTER.set(count + 1);
}
public static void exitNoSensitiveScope() {
Integer count = COUNTER.get();
if (count != null) {
if (count <= 1) {
COUNTER.remove();
} else {
COUNTER.set(count - 1);
}
}
}
public static boolean isNoSensitiveScope() {
Integer count = COUNTER.get();
return count != null && count > 0;
}
}