jeecgboot/JeecgBoot · error · JeecgBootException
admin用户,不允许删除!
Error message
admin用户,不允许删除!
What it means
Thrown by SysUserServiceImpl.checkUserAdminRejectDel. It queries sys_user for rows matching the given userIds AND username='admin'; if any exist, deletion is blocked to protect the built-in administrator.
Source
Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java:2067
// 代码逻辑说明: 【QQYUN-8425】用户导入成功后 消息提醒 跳转至同意页面---
data.put(CommonConstant.NOTICE_MSG_BUS_TYPE,SysAnnmentTypeEnum.TENANT_INVITE.getType());
messageDTO.setData(data);
messageDTO.setContent(title);
messageDTO.setToUser(invitedUsername);
messageDTO.setFromUser("system");
systemSendMsgHandle.sendMessage(messageDTO);
}
//======================================= end 用户与部门 用户列表导入 =========================================
@Override
public void checkUserAdminRejectDel(String userIds) {
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
query.in(SysUser::getId,Arrays.asList(userIds.split(SymbolConstant.COMMA)));
query.eq(SysUser::getUsername,"admin");
Long adminRoleCount = this.baseMapper.selectCount(query);
//大于0说明存在管理员用户,不允许删除
if(adminRoleCount>0){
throw new JeecgBootException("admin用户,不允许删除!");
}
}
@Override
public void changePhone(JSONObject json, String username) {
String smscode = json.getString("smscode");
String phone = json.getString("phone");
String type = json.getString("type");
if(oConvertUtils.isEmpty(phone)){
throw new JeecgBootException("请填写原手机号!");
}
if(oConvertUtils.isEmpty(smscode)){
throw new JeecgBootException("请填写验证码!");
}
//step1 验证原手机号是否和当前用户匹配
SysUser sysUser = userMapper.getUserByNameAndPhone(phone,username);
if (null == sysUser){
throw new JeecgBootException("原手机号不匹配,无法修改密码!");View on GitHub (pinned to 96fb33f5ec)
Solutions
- Exclude admin's userId from the delete request before submitting.
- In the UI, make admin non-selectable or filter it from bulk-select.
- If a non-system account was mistakenly named 'admin', rename it before deleting.
- Audit the userIds list payload to confirm which id triggers it.
Example fix
// before
userIds = selectedIds.stream().collect(joining(",")); // includes admin id
checkUserAdminRejectDel(userIds);
// after: strip admin id
List<String> safe = selectedIds.stream().filter(id -> !adminId.equals(id)).collect(toList());
checkUserAdminRejectDel(String.join(",", safe)); Defensive patterns
Strategy: validation
Validate before calling
SysUser admin = userMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, "admin"));
List<String> safe = Arrays.asList(userIds.split(",")).stream()
.filter(id -> !id.equals(admin.getId())).collect(Collectors.toList());
if (safe.isEmpty()) return Result.error("无可删除用户"); Type guard
boolean excludesAdmin(String userIds, String adminId) {
return !Arrays.asList(userIds.split(",")).contains(adminId);
} Try / catch
try { userService.checkUserAdminRejectDel(userIds); }
catch (JeecgBootException e) {
if (e.getMessage().contains("admin")) return Result.error("不能删除超级管理员");
throw e;
} Prevention
- Make admin non-selectable in the UI.
- Strip admin id from bulk-delete payloads server-side.
- Never reuse the username 'admin' for other accounts.
When it happens
Trigger: A delete-users request whose userIds list includes the id of the user whose username is 'admin'.
Common situations: Bulk delete selected all users including admin; admin's id leaked into a comma-separated list; a second account was renamed to 'admin' (unlikely, usually prohibited); UI did not exclude admin from the selectable set.
Related errors
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/e9159473c00f5720.
Report an issue: GitHub.