refactor: 梳理用户和角色体系,内置角色:超级管理员、租户管理员(系统管理员),且内置用户和角色不允许变更及分配

This commit is contained in:
2025-07-26 21:22:33 +08:00
parent 7f0059984d
commit 93bf749ce3
33 changed files with 398 additions and 200 deletions

View File

@@ -29,12 +29,12 @@ import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.Async;
import top.continew.admin.auth.constant.AuthConstants;
import top.continew.admin.auth.enums.AuthTypeEnum;
import top.continew.admin.auth.model.req.AccountLoginReq;
import top.continew.admin.auth.model.req.EmailLoginReq;
import top.continew.admin.auth.model.req.LoginReq;
import top.continew.admin.auth.model.req.PhoneLoginReq;
import top.continew.admin.common.constant.SysConstants;
import top.continew.admin.system.enums.LogStatusEnum;
import top.continew.admin.system.mapper.LogMapper;
import top.continew.admin.system.model.entity.LogDO;
@@ -92,7 +92,8 @@ public class LogDaoLocalImpl implements LogDao {
// 保存记录
if (TenantContextHolder.isTenantEnabled()) {
// 异步无法获取租户 ID
String tenantId = logRequest.getHeaders().get(SpringUtil.getBean(TenantProperties.class).getTenantIdHeader());
String tenantId = logRequest.getHeaders()
.get(SpringUtil.getBean(TenantProperties.class).getTenantIdHeader());
if (StrUtil.isNotBlank(tenantId)) {
TenantUtils.execute(Long.parseLong(tenantId), () -> logMapper.insert(logDO));
return;
@@ -154,13 +155,13 @@ public class LogDaoLocalImpl implements LogDao {
String requestUri = URLUtil.getPath(logDO.getRequestUrl());
// 解析退出接口信息
String responseBody = logResponse.getBody();
if (requestUri.startsWith(SysConstants.LOGOUT_URI) && StrUtil.isNotBlank(responseBody)) {
if (requestUri.startsWith(AuthConstants.LOGOUT_URI) && StrUtil.isNotBlank(responseBody)) {
R result = JSONUtil.toBean(responseBody, R.class);
logDO.setCreateUser(Convert.toLong(result.getData(), null));
return;
}
// 解析登录接口信息
if (requestUri.startsWith(SysConstants.LOGIN_URI) && LogStatusEnum.SUCCESS.equals(logDO.getStatus())) {
if (requestUri.startsWith(AuthConstants.LOGIN_URI) && LogStatusEnum.SUCCESS.equals(logDO.getStatus())) {
String requestBody = logRequest.getBody();
logDO.setDescription(JSONUtil.toBean(requestBody, LoginReq.class).getAuthType().getDescription() + "登录");
// 解析账号登录用户为操作人

View File

@@ -27,6 +27,7 @@ import cn.dev33.satoken.sign.template.SaSignUtil;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.boot.context.event.ApplicationReadyEvent;
@@ -54,6 +55,7 @@ import java.util.*;
* @author chengzi
* @since 2022/12/19 22:13
*/
@Slf4j
@Configuration
@RequiredArgsConstructor
public class SaTokenConfiguration {
@@ -133,5 +135,6 @@ public class SaTokenConfiguration {
// 转回数组
properties.getSecurity().setExcludes(allExcludes.toArray(new String[0]));
}
log.debug("缓存 CRUD API 权限前缀完成:{}", CrudApiPermissionPrefixCache.getAll().values());
}
}

View File

@@ -46,7 +46,7 @@ import org.springframework.web.bind.annotation.*;
import top.continew.admin.auth.model.resp.CaptchaResp;
import top.continew.admin.common.config.CaptchaProperties;
import top.continew.admin.common.constant.CacheConstants;
import top.continew.admin.common.constant.SysConstants;
import top.continew.admin.common.constant.GlobalConstants;
import top.continew.admin.system.enums.OptionCategoryEnum;
import top.continew.admin.system.model.entity.SmsConfigDO;
import top.continew.admin.system.service.OptionService;
@@ -119,7 +119,7 @@ public class CaptchaController {
@GetMapping("/image")
public CaptchaResp getImageCaptcha() {
int loginCaptchaEnabled = optionService.getValueByCode2Int("LOGIN_CAPTCHA_ENABLED");
if (SysConstants.NO.equals(loginCaptchaEnabled)) {
if (GlobalConstants.Boolean.NO.equals(loginCaptchaEnabled)) {
return CaptchaResp.builder().isEnabled(false).build();
}
String uuid = IdUtil.fastUUID();

View File

@@ -77,10 +77,8 @@ public class DemoEnvironmentJob {
private static final Long DELETE_FLAG = 10000L;
private static final Long MESSAGE_FLAG = 0L;
private static final List<Long> USER_FLAG = List
.of(1L, 547889293968801822L, 547889293968801823L, 547889293968801824L, 547889293968801825L,
547889293968801826L, 547889293968801827L, 547889293968801828L, 547889293968801829L,
547889293968801830L, 547889293968801831L, 547889293968801832L, 547889293968801833L, 547889293968801834L);
private static final List<Long> ROLE_FLAG = List.of(1L, 2L, 547888897925840927L, 547888897925840928L);
.of(1L, 547889293968801822L, 547889293968801823L, 547889293968801824L, 547889293968801825L, 547889293968801826L, 547889293968801827L, 547889293968801828L, 547889293968801829L, 547889293968801830L, 547889293968801831L, 547889293968801832L, 547889293968801833L, 547889293968801834L);
private static final List<Long> ROLE_FLAG = List.of(1L, 2L, 3L, 547888897925840927L, 547888897925840928L);
private static final Long DEPT_FLAG = 547887852587843611L;
/**