From 9ed5b521d613edb51b160cca931ee680019e2896 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期二, 07 三月 2023 22:26:13 +0800 Subject: [PATCH] fix 修复 用户密码暴露问题 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java | 43 +++++++++++++++++++------------------------ 1 files changed, 19 insertions(+), 24 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index e83a124..2140a77 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -1,16 +1,16 @@ package com.ruoyi.system.service.impl; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.constant.UserConstants; +import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.StreamUtils; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.mybatis.core.page.PageQuery; import com.ruoyi.system.domain.SysRole; import com.ruoyi.common.mybatis.core.page.TableDataInfo; @@ -110,7 +110,7 @@ Set<String> permsSet = new HashSet<>(); for (SysRoleVo perm : perms) { if (ObjectUtil.isNotNull(perm)) { - permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); + permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim())); } } return permsSet; @@ -155,14 +155,11 @@ * @return 缁撴灉 */ @Override - public String checkRoleNameUnique(SysRoleBo role) { + public boolean checkRoleNameUnique(SysRoleBo role) { boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() .eq(SysRole::getRoleName, role.getRoleName()) .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); - if (exist) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; + return !exist; } /** @@ -172,14 +169,11 @@ * @return 缁撴灉 */ @Override - public String checkRoleKeyUnique(SysRoleBo role) { + public boolean checkRoleKeyUnique(SysRoleBo role) { boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() .eq(SysRole::getRoleKey, role.getRoleKey()) .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); - if (exist) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; + return !exist; } /** @@ -189,7 +183,7 @@ */ @Override public void checkRoleAllowed(SysRoleBo role) { - if (ObjectUtil.isNotNull(role.getRoleId()) && role.isAdmin()) { + if (ObjectUtil.isNotNull(role.getRoleId()) && role.isSuperAdmin()) { throw new ServiceException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳瑙掕壊"); } } @@ -201,7 +195,7 @@ */ @Override public void checkRoleDataScope(Long roleId) { - if (!LoginHelper.isAdmin()) { + if (!LoginHelper.isSuperAdmin()) { SysRoleBo role = new SysRoleBo(); role.setRoleId(roleId); List<SysRoleVo> roles = this.selectRoleList(role); @@ -231,10 +225,11 @@ @Override @Transactional(rollbackFor = Exception.class) public int insertRole(SysRoleBo bo) { - SysRole role = BeanUtil.toBean(bo, SysRole.class); + SysRole role = MapstructUtils.convert(bo, SysRole.class); // 鏂板瑙掕壊淇℃伅 baseMapper.insert(role); - return insertRoleMenu(role); + bo.setRoleId(role.getRoleId()); + return insertRoleMenu(bo); } /** @@ -246,12 +241,12 @@ @Override @Transactional(rollbackFor = Exception.class) public int updateRole(SysRoleBo bo) { - SysRole role = BeanUtil.toBean(bo, SysRole.class); + SysRole role = MapstructUtils.convert(bo, SysRole.class); // 淇敼瑙掕壊淇℃伅 baseMapper.updateById(role); // 鍒犻櫎瑙掕壊涓庤彍鍗曞叧鑱� roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, role.getRoleId())); - return insertRoleMenu(role); + return insertRoleMenu(bo); } /** @@ -262,7 +257,7 @@ */ @Override public int updateRoleStatus(SysRoleBo bo) { - SysRole role = BeanUtil.toBean(bo, SysRole.class); + SysRole role = MapstructUtils.convert(bo, SysRole.class); return baseMapper.updateById(role); } @@ -275,13 +270,13 @@ @Override @Transactional(rollbackFor = Exception.class) public int authDataScope(SysRoleBo bo) { - SysRole role = BeanUtil.toBean(bo, SysRole.class); + SysRole role = MapstructUtils.convert(bo, SysRole.class); // 淇敼瑙掕壊淇℃伅 baseMapper.updateById(role); // 鍒犻櫎瑙掕壊涓庨儴闂ㄥ叧鑱� roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, role.getRoleId())); // 鏂板瑙掕壊鍜岄儴闂ㄤ俊鎭紙鏁版嵁鏉冮檺锛� - return insertRoleDept(role); + return insertRoleDept(bo); } /** @@ -289,7 +284,7 @@ * * @param role 瑙掕壊瀵硅薄 */ - public int insertRoleMenu(SysRole role) { + public int insertRoleMenu(SysRoleBo role) { int rows = 1; // 鏂板鐢ㄦ埛涓庤鑹茬鐞� List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); @@ -310,7 +305,7 @@ * * @param role 瑙掕壊瀵硅薄 */ - public int insertRoleDept(SysRole role) { + public int insertRoleDept(SysRoleBo role) { int rows = 1; // 鏂板瑙掕壊涓庨儴闂紙鏁版嵁鏉冮檺锛夌鐞� List<SysRoleDept> list = new ArrayList<SysRoleDept>(); -- Gitblit v1.9.3