mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-02-01 14:31:56 +08:00
Compare commits
3 Commits
616def4d0a
...
c5f7bb12cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5f7bb12cd | ||
|
|
50a9337ee8 | ||
|
|
2622d9147e |
@@ -22,7 +22,12 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- RuoYi Common Sensitive -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-sensitive</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.system.api;
|
package com.ruoyi.system.api;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.NoSensitive;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@@ -16,6 +17,7 @@ import com.ruoyi.system.api.factory.RemoteLogFallbackFactory;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@NoSensitive
|
||||||
@FeignClient(contextId = "remoteLogService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteLogFallbackFactory.class)
|
@FeignClient(contextId = "remoteLogService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteLogFallbackFactory.class)
|
||||||
public interface RemoteLogService
|
public interface RemoteLogService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.system.api;
|
package com.ruoyi.system.api;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.NoSensitive;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@@ -19,6 +20,7 @@ import com.ruoyi.system.api.model.LoginUser;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@NoSensitive
|
||||||
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
||||||
public interface RemoteUserService
|
public interface RemoteUserService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.ruoyi.system.api.domain;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.NoSensitive;
|
||||||
|
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
||||||
|
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
@@ -44,6 +48,7 @@ public class SysUser extends BaseEntity
|
|||||||
|
|
||||||
/** 手机号码 */
|
/** 手机号码 */
|
||||||
@Excel(name = "手机号码", cellType = ColumnType.TEXT)
|
@Excel(name = "手机号码", cellType = ColumnType.TEXT)
|
||||||
|
@Sensitive(desensitizedType = DesensitizedType.PHONE)
|
||||||
private String phonenumber;
|
private String phonenumber;
|
||||||
|
|
||||||
/** 用户性别 */
|
/** 用户性别 */
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.ruoyi.common.security.interceptor;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.NoSensitive;
|
||||||
|
import com.ruoyi.common.core.context.SensitiveContextHolder;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description @NoSensitive 注解的请求拦截器,主要用于对请求的注解,在请求的整个生命周期内有效
|
||||||
|
* @Author AhYi
|
||||||
|
* @Date 2025-07-07 10:35
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class NoSensitiveInterceptor implements HandlerInterceptor {
|
||||||
|
private static final String SENSITIVE_INTERCEPTOR_APPLIED = "SENSITIVE_INTERCEPTOR_APPLIED";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
if (handler instanceof HandlerMethod) {
|
||||||
|
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||||
|
NoSensitive noSensitive = handlerMethod.getMethodAnnotation(NoSensitive.class);
|
||||||
|
if (noSensitive == null) {
|
||||||
|
noSensitive = handlerMethod.getBeanType().getAnnotation(NoSensitive.class);
|
||||||
|
}
|
||||||
|
if (noSensitive != null) {
|
||||||
|
SensitiveContextHolder.enterNoSensitiveScope();
|
||||||
|
request.setAttribute(SENSITIVE_INTERCEPTOR_APPLIED, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||||
|
Object applied = request.getAttribute(SENSITIVE_INTERCEPTOR_APPLIED);
|
||||||
|
if (applied != null && (Boolean) applied) {
|
||||||
|
SensitiveContextHolder.exitNoSensitiveScope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
|
|||||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||||
|
import com.ruoyi.common.core.context.SensitiveContextHolder;
|
||||||
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
||||||
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ public class SensitiveJsonSerializer extends JsonSerializer<String> implements C
|
|||||||
@Override
|
@Override
|
||||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException
|
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException
|
||||||
{
|
{
|
||||||
if (desensitization())
|
if (desensitization() && !SensitiveContextHolder.isNoSensitiveScope())
|
||||||
{
|
{
|
||||||
gen.writeString(desensitizedType.desensitizer().apply(value));
|
gen.writeString(desensitizedType.desensitizer().apply(value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,11 @@
|
|||||||
<artifactId>ruoyi-common-swagger</artifactId>
|
<artifactId>ruoyi-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- RuoYi Common Sensitive -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-sensitive</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.ruoyi.system;
|
||||||
|
|
||||||
|
import com.ruoyi.common.security.interceptor.NoSensitiveInterceptor;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description WebMvcConfig
|
||||||
|
* @Author AhYi
|
||||||
|
* @Date 2025-07-07 10:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(new NoSensitiveInterceptor())
|
||||||
|
.addPathPatterns("/**")
|
||||||
|
.order(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.ruoyi.system.controller;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.NoSensitive;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -49,6 +51,7 @@ public class SysProfileController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 个人信息
|
* 个人信息
|
||||||
*/
|
*/
|
||||||
|
@NoSensitive
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public AjaxResult profile()
|
public AjaxResult profile()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.annotation.NoSensitive;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -117,6 +119,7 @@ public class SysUserController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 获取当前用户信息
|
* 获取当前用户信息
|
||||||
*/
|
*/
|
||||||
|
@NoSensitive
|
||||||
@InnerAuth
|
@InnerAuth
|
||||||
@GetMapping("/info/{username}")
|
@GetMapping("/info/{username}")
|
||||||
public R<LoginUser> info(@PathVariable("username") String username)
|
public R<LoginUser> info(@PathVariable("username") String username)
|
||||||
@@ -171,6 +174,7 @@ public class SysUserController extends BaseController
|
|||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
|
@NoSensitive
|
||||||
@GetMapping("getInfo")
|
@GetMapping("getInfo")
|
||||||
public AjaxResult getInfo()
|
public AjaxResult getInfo()
|
||||||
{
|
{
|
||||||
@@ -221,6 +225,7 @@ public class SysUserController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 根据用户编号获取详细信息
|
* 根据用户编号获取详细信息
|
||||||
*/
|
*/
|
||||||
|
@NoSensitive
|
||||||
@RequiresPermissions("system:user:query")
|
@RequiresPermissions("system:user:query")
|
||||||
@GetMapping(value = { "/", "/{userId}" })
|
@GetMapping(value = { "/", "/{userId}" })
|
||||||
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
||||||
|
|||||||
@@ -76,6 +76,15 @@ public interface SysUserMapper
|
|||||||
*/
|
*/
|
||||||
public int updateUserAvatar(@Param("userId") Long userId, @Param("avatar") String avatar);
|
public int updateUserAvatar(@Param("userId") Long userId, @Param("avatar") String avatar);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户状态
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param status 状态
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateUserStatus(@Param("userId") Long userId, @Param("status") String status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户登录信息(IP和登录时间)
|
* 更新用户登录信息(IP和登录时间)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|||||||
@Override
|
@Override
|
||||||
public int updateUserStatus(SysUser user)
|
public int updateUserStatus(SysUser user)
|
||||||
{
|
{
|
||||||
return userMapper.updateUser(user);
|
return userMapper.updateUserStatus(user.getUserId(), user.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -374,7 +374,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|||||||
@Override
|
@Override
|
||||||
public int resetPwd(SysUser user)
|
public int resetPwd(SysUser user)
|
||||||
{
|
{
|
||||||
return userMapper.updateUser(user);
|
return userMapper.resetUserPwd(user.getUserId(), user.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -528,6 +528,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|||||||
checkUserDataScope(u.getUserId());
|
checkUserDataScope(u.getUserId());
|
||||||
deptService.checkDeptDataScope(user.getDeptId());
|
deptService.checkDeptDataScope(user.getDeptId());
|
||||||
user.setUserId(u.getUserId());
|
user.setUserId(u.getUserId());
|
||||||
|
user.setDeptId(u.getDeptId());
|
||||||
user.setUpdateBy(operName);
|
user.setUpdateBy(operName);
|
||||||
userMapper.updateUser(user);
|
userMapper.updateUser(user);
|
||||||
successNum++;
|
successNum++;
|
||||||
|
|||||||
@@ -198,11 +198,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateUserStatus" parameterType="SysUser">
|
<update id="updateUserStatus" parameterType="SysUser">
|
||||||
update sys_user set status = #{status} where user_id = #{userId}
|
update sys_user set status = #{status}, update_time = sysdate() where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateUserAvatar" parameterType="SysUser">
|
<update id="updateUserAvatar" parameterType="SysUser">
|
||||||
update sys_user set avatar = #{avatar} where user_id = #{userId}
|
update sys_user set avatar = #{avatar}, update_time = sysdate() where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateLoginInfo" parameterType="SysUser">
|
<update id="updateLoginInfo" parameterType="SysUser">
|
||||||
@@ -210,7 +210,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="resetUserPwd" parameterType="SysUser">
|
<update id="resetUserPwd" parameterType="SysUser">
|
||||||
update sys_user set pwd_update_date = sysdate(), password = #{password} where user_id = #{userId}
|
update sys_user set pwd_update_date = sysdate(), password = #{password}, update_time = sysdate() where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteUserById" parameterType="Long">
|
<delete id="deleteUserById" parameterType="Long">
|
||||||
|
|||||||
Reference in New Issue
Block a user