From 1e69726d770890d3a982c8aa4cfc18f42d5aaa7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sat, 17 Jun 2023 22:38:22 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AF=A1=E6=94=B9=E7=AE=A1=E7=90=86=E5=91=98=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E7=AC=A6=E8=B6=8A=E6=9D=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/constant/UserConstants.java | 5 +++++ .../service/impl/SysRoleServiceImpl.java | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java index 4a095faad..569c5dafa 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java @@ -129,4 +129,9 @@ public interface UserConstants { */ Long ADMIN_ID = 1L; + /** + * 管理员角色key + */ + String ADMIN_ROLE_KEY = "admin"; + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index b28df9e98..15713d407 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -186,6 +186,20 @@ public class SysRoleServiceImpl implements ISysRoleService { if (ObjectUtil.isNotNull(role.getRoleId()) && role.isAdmin()) { throw new ServiceException("不允许操作超级管理员角色"); } + // 新增不允许使用 管理员标识符 + if (ObjectUtil.isNull(role.getRoleId()) + && StringUtils.equals(role.getRoleKey(), UserConstants.ADMIN_ROLE_KEY)) { + throw new ServiceException("不允许使用系统内置管理员角色标识符!"); + } + // 修改不允许修改 管理员标识符 + if (ObjectUtil.isNotNull(role.getRoleId())) { + SysRole sysRole = baseMapper.selectById(role.getRoleId()); + // 如果标识符不相等 判断为修改了管理员标识符 + if (!StringUtils.equals(sysRole.getRoleKey(), role.getRoleKey()) + && StringUtils.equals(sysRole.getRoleKey(), UserConstants.ADMIN_ROLE_KEY)) { + throw new ServiceException("不允许修改系统内置管理员角色标识符!"); + } + } } /** @@ -342,9 +356,9 @@ public class SysRoleServiceImpl implements ISysRoleService { @Transactional(rollbackFor = Exception.class) public int deleteRoleByIds(Long[] roleIds) { for (Long roleId : roleIds) { - checkRoleAllowed(new SysRole(roleId)); - checkRoleDataScope(roleId); SysRole role = selectRoleById(roleId); + checkRoleAllowed(role); + checkRoleDataScope(roleId); if (countUserRoleByRoleId(roleId) > 0) { throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); }