{"record":{"id":"bcafcb9d37d42ea5","repo":"jeecgboot/JeecgBoot","slug":"admin","errorCode":null,"errorMessage":"admin角色，不允许删除！","messagePattern":"admin角色，不允许删除！","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"critical","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java","lineNumber":116,"sourceCode":"        sysUserMapper.deleteBathRolePermissionRelation(roleIds);\n        //3.删除角色\n        this.removeByIds(Arrays.asList(roleIds));\n        return true;\n    }\n\n    @Override\n    public Long getRoleCountByTenantId(String id, Integer tenantId) {\n        return sysRoleMapper.getRoleCountByTenantId(id,tenantId);\n    }\n\n    @Override\n    public void checkAdminRoleRejectDel(String ids) {\n        LambdaQueryWrapper<SysRole> query = new  LambdaQueryWrapper<>();\n        query.in(SysRole::getId,Arrays.asList(ids.split(SymbolConstant.COMMA)));\n        query.eq(SysRole::getRoleCode,\"admin\");\n        Long adminRoleCount = sysRoleMapper.selectCount(query);\n        if(adminRoleCount>0){\n            throw new JeecgBootException(\"admin角色，不允许删除！\");\n        }\n    }\n}\n","sourceCodeStart":98,"sourceCodeEnd":120,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysRoleServiceImpl.java#L98-L120","documentation":"Thrown by SysRoleServiceImpl.checkAdminRoleRejectDel when a query for roles with roleCode='admin' among the IDs to delete returns count > 0. This JeecgBootException prevents deletion of the system's built-in admin role, which is critical for system access. The method splits the comma-separated ids string and queries for any admin-role matches.","triggerScenarios":"Calling checkAdminRoleRejectDel with a comma-separated list of role IDs that includes the admin role's ID. The query filters by roleCode='admin' using an IN clause on the split IDs.","commonSituations":"User selects 'all roles' in a batch-delete UI that includes the admin role; a script or migration attempts to clean up all roles; the admin role ID is accidentally included in a bulk delete request.","solutions":["Exclude the admin role from the delete selection in the frontend UI (disable its checkbox).","Filter out roleCode='admin' before calling checkAdminRoleRejectDel.","If legitimate admin role management is needed, use a dedicated role-management endpoint, not the batch delete.","Log which ID(s) triggered the rejection for audit purposes."],"exampleFix":"// before\npublic void checkAdminRoleRejectDel(String ids) {\n    query.in(SysRole::getId, Arrays.asList(ids.split(\",\")));\n    query.eq(SysRole::getRoleCode, \"admin\");\n    Long count = sysRoleMapper.selectCount(query);\n    if (count > 0) {\n        throw new JeecgBootException(\"admin角色，不允许删除！\");\n    }\n}\n\n// after — frontend excludes admin role from batch delete\nconst deletableRoles = selectedRoles.filter(r => r.roleCode !== 'admin');\nif (deletableRoles.length < selectedRoles.length) {\n    ElMessage.warning('admin角色不允许删除，已自动排除');\n}\nawait api.deleteRoles(deletableRoles.map(r => r.id).join(','));","handlingStrategy":"validation","validationCode":"// Filter out admin role before batch delete\nList<String> safeIds = roleList.stream()\n    .filter(r -> !\"admin\".equals(r.getRoleCode()))\n    .map(SysRole::getId)\n    .collect(Collectors.toList());\nif (safeIds.isEmpty()) {\n    return Result.error(\"没有可删除的角色(admin角色不允许删除)\");\n}\nservice.checkAdminRoleRejectDel(String.join(\",\", safeIds));","typeGuard":"public boolean containsNoAdminRole(List<SysRole> roles) {\n    return roles.stream().noneMatch(r -> \"admin\".equals(r.getRoleCode()));\n}","tryCatchPattern":"try {\n    service.checkAdminRoleRejectDel(ids);\n} catch (JeecgBootException e) {\n    if (e.getMessage().contains(\"admin角色\")) {\n        return Result.error(\"admin角色不允许删除，请取消选择后重试\");\n    }\n    throw e;\n}","preventionTips":["Disable the delete checkbox for the admin role in the UI.","Filter out roleCode='admin' before calling the batch delete.","Never include the admin role ID in automated cleanup scripts."],"tags":["jeecg-boot","role","admin-protection","security","business-exception"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}