From 09024262dbc30d9aa9f13489cd289d28b52436e4 Mon Sep 17 00:00:00 2001 From: puff <puff@macbookpro-puff.local> Date: Wed, 5 Jun 2024 15:08:47 +0800 Subject: [PATCH] feat:完成用户角色权限的关联,拥有脱敏白名单用户可以看到脱敏前前的数据,白名单之外的看到的数据都是脱敏后的数据 --- huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/plugin/DesensitizationInterceptor.java | 27 +++++++++------------------ huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysRoleService.java | 8 -------- huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java | 28 +--------------------------- 3 files changed, 10 insertions(+), 53 deletions(-) diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/plugin/DesensitizationInterceptor.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/plugin/DesensitizationInterceptor.java index ceeb2db..bdbd992 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/plugin/DesensitizationInterceptor.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/desensitization/plugin/DesensitizationInterceptor.java @@ -4,11 +4,13 @@ package org.jeecg.modules.desensitization.plugin; import cn.hutool.core.util.ObjectUtil; import org.apache.ibatis.executor.resultset.ResultSetHandler; import org.apache.ibatis.plugin.*; +import org.apache.shiro.SecurityUtils; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.desensitization.annotation.SensitiveField; import org.jeecg.modules.desensitization.enums.SensitiveTypeEnums; import org.jeecg.modules.desensitization.strategy.SensitiveContext; import org.jeecg.modules.desensitization.strategy.SensitiveStrategy; +import org.jeecg.modules.system.entity.SysUserRole; import org.jeecg.modules.system.service.ISysRoleService; import org.jeecg.utils.HuahengJwtUtil; import org.reflections.ReflectionUtils; @@ -24,6 +26,8 @@ import java.lang.reflect.Field; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import static org.jeecg.utils.HuahengJwtUtil.getRolesByToken; + /** * 基于拦截器对数据脱敏 @@ -38,8 +42,6 @@ import java.util.concurrent.ConcurrentHashMap; @Order(-1) public class DesensitizationInterceptor implements Interceptor { -// @Resource -// private static ISysRoleService iSysRoleService; private static final Logger log = LoggerFactory.getLogger(DesensitizationInterceptor.class); @@ -90,8 +92,6 @@ public class DesensitizationInterceptor implements Interceptor { } } } - String userName = HuahengJwtUtil.getCurrentOperator(); - for (Handler handler : handlerList) { handler.accept(object); } @@ -131,20 +131,11 @@ public class DesensitizationInterceptor implements Interceptor { SensitiveTypeEnums typeEnums = annotation.value(); String fillValue = annotation.fillValue(); Object o1 = field.get(o); - // 获取当前用户角色权限,管理员不脱敏,其他人员则只能查看加密后的数据 - // 获取当前登陆用户 -// iSysRoleService.desensitizationByUserName(HuahengJwtUtil.getCurrentOperator()); -// if(!iSysRoleService.desensitizationByUserName(HuahengJwtUtil.getCurrentOperator())){ -// SensitiveStrategy sensitiveStrategy = SensitiveContext.get(typeEnums); -// String s = sensitiveStrategy.handle(o1, fillValue); -// field.set(o, s); -// } - -// log.info("加密之前数据 = {}",o1); - SensitiveStrategy sensitiveStrategy = SensitiveContext.get(typeEnums); - String s = sensitiveStrategy.handle(o1, fillValue); -// log.info("加密之后数据 = {}",s); - field.set(o, s); + if(!SecurityUtils.getSubject().hasRole("desensitization")){ + SensitiveStrategy sensitiveStrategy = SensitiveContext.get(typeEnums); + String s = sensitiveStrategy.handle(o1, fillValue); + field.set(o, s); + } } } } diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysRoleService.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysRoleService.java index bffafca..2ddaec4 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysRoleService.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/ISysRoleService.java @@ -45,12 +45,4 @@ public interface ISysRoleService extends IService<SysRole> { * @return */ public SysRole getRoleByName(String roleName); - - /** - * 根据用户名获取角色列表 - * @param userName - * @return - */ - public boolean desensitizationByUserName(String userName); - } diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java index 609db42..50b96f3 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java @@ -106,32 +106,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl public SysRole getRoleByName(String roleName) { LambdaQueryWrapper<SysRole> roleLambdaQueryWrapper = Wrappers.lambdaQuery(); roleLambdaQueryWrapper.eq(SysRole::getRoleName, roleName); - SysRole role = getOne(roleLambdaQueryWrapper); - return role; - } - - public boolean desensitizationByUserName(String userName){ - LambdaQueryWrapper<SysRole> roleLambdaQueryWrapper = Wrappers.lambdaQuery(); - roleLambdaQueryWrapper.eq(SysRole::getRoleCode,"desensitization"); - SysRole sysRole = getOne(roleLambdaQueryWrapper); - if(ObjectUtil.isEmpty(sysRole)){ - return false; - } - LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = Wrappers.lambdaQuery(); - sysUserLambdaQueryWrapper.eq(SysUser::getUsername,userName); - SysUser sysUser = iSysUserService.getOne(sysUserLambdaQueryWrapper); - - LambdaQueryWrapper<SysUserRole> sysUserRoleLambdaQueryWrapper = Wrappers.lambdaQuery(); - sysUserRoleLambdaQueryWrapper.eq(SysUserRole::getRoleId,sysRole.getId()); - List<SysUserRole> sysUserRoleList = iSysUserRoleService.list(sysUserRoleLambdaQueryWrapper); - - boolean flag = false; - for (SysUserRole sysUserRole : sysUserRoleList){ - if(sysUserRole.getUserId().equals(sysUser.getId())){ - flag = true; - break; - } - } - return flag; + return getOne(roleLambdaQueryWrapper); } } -- libgit2 0.22.2