mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
refactor: 梳理用户和角色体系,内置角色:超级管理员、租户管理员(系统管理员),且内置用户和角色不允许变更及分配
This commit is contained in:
@@ -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() + "登录");
|
||||
// 解析账号登录用户为操作人
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
|
||||
/**
|
||||
|
@@ -206,7 +206,7 @@ continew-starter.tenant:
|
||||
tenant-id-header: X-Tenant-Id
|
||||
# 请求头中租户编码键名
|
||||
tenant-code-header: X-Tenant-Code
|
||||
# 默认租户 ID:超管用户所在租户(默认:0)
|
||||
# 默认租户 ID:超级管理员用户所在租户(默认:0)
|
||||
default-tenant-id: 0
|
||||
# 忽略表(忽略拼接租户条件)
|
||||
ignore-tables:
|
||||
|
@@ -164,8 +164,9 @@ VALUES
|
||||
INSERT INTO `sys_role`
|
||||
(`id`, `name`, `code`, `data_scope`, `description`, `sort`, `is_system`, `create_user`, `create_time`)
|
||||
VALUES
|
||||
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, b'1', 1, NOW()),
|
||||
(2, '普通用户', 'general', 4, '系统初始角色', 2, b'1', 1, NOW()),
|
||||
(1, '超级管理员', 'super_admin', 1, '系统初始角色', 0, b'1', 1, NOW()),
|
||||
(2, '系统管理员', 'sys_admin', 1, NULL, 1, b'0', 1, NOW()),
|
||||
(3, '普通用户', 'general', 4, NULL, 2, b'0', 1, NOW()),
|
||||
(547888897925840927, '测试人员', 'tester', 5, NULL, 3, b'0', 1, NOW()),
|
||||
(547888897925840928, '研发人员', 'developer', 4, NULL, 4, b'0', 1, NOW());
|
||||
|
||||
@@ -173,7 +174,7 @@ VALUES
|
||||
INSERT INTO `sys_user`
|
||||
(`id`, `username`, `nickname`, `password`, `gender`, `email`, `phone`, `avatar`, `description`, `status`, `is_system`, `pwd_reset_time`, `dept_id`, `create_user`, `create_time`)
|
||||
VALUES
|
||||
(1, 'admin', '系统管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, b'1', NOW(), 1, 1, NOW()),
|
||||
(1, 'admin', '超级管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, b'1', NOW(), 1, 1, NOW()),
|
||||
(547889293968801822, 'test', '测试员', '{bcrypt}$2a$10$xAsoeMJ.jc/kSxhviLAg7.j2iFrhi6yYAdniNdjLiIUWU/BRZl2Ti', 2, NULL, NULL, NULL, NULL, 1, b'0', NOW(), 547887852587843593, 1, NOW()),
|
||||
(547889293968801823, 'Charles', 'Charles', '{bcrypt}$2a$10$xAsoeMJ.jc/kSxhviLAg7.j2iFrhi6yYAdniNdjLiIUWU/BRZl2Ti', 1, NULL, NULL, NULL, '代码写到极致,就是艺术。', 1, b'0', NOW(), 547887852587843595, 1, NOW()),
|
||||
(547889293968801824, 'Yoofff', 'Yoofff', '{bcrypt}$2a$10$xAsoeMJ.jc/kSxhviLAg7.j2iFrhi6yYAdniNdjLiIUWU/BRZl2Ti', 1, NULL, NULL, NULL, '弱小和无知不是生存的障碍,傲慢才是。', 2, b'0', NOW(), 1, 1, NOW()),
|
||||
|
@@ -164,8 +164,9 @@ VALUES
|
||||
INSERT INTO "sys_role"
|
||||
("id", "name", "code", "data_scope", "description", "sort", "is_system", "create_user", "create_time")
|
||||
VALUES
|
||||
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, true, 1, NOW()),
|
||||
(2, '普通用户', 'general', 4, '系统初始角色', 2, true, 1, NOW()),
|
||||
(1, '超级管理员', 'super_admin', 1, '系统初始角色', 0, true, 1, NOW()),
|
||||
(2, '系统管理员', 'sys_admin', 1, NULL, 1, false, 1, NOW()),
|
||||
(3, '普通用户', 'general', 4, NULL, 2, false, 1, NOW()),
|
||||
(547888897925840927, '测试人员', 'tester', 5, NULL, 3, false, 1, NOW()),
|
||||
(547888897925840928, '研发人员', 'developer', 4, NULL, 4, false, 1, NOW());
|
||||
|
||||
@@ -173,7 +174,7 @@ VALUES
|
||||
INSERT INTO "sys_user"
|
||||
("id", "username", "nickname", "password", "gender", "email", "phone", "avatar", "description", "status", "is_system", "pwd_reset_time", "dept_id", "create_user", "create_time")
|
||||
VALUES
|
||||
(1, 'admin', '系统管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, true, NOW(), 1, 1, NOW()),
|
||||
(1, 'admin', '超级管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, true, NOW(), 1, 1, NOW()),
|
||||
(547889293968801822, 'test', '测试员', '{bcrypt}$2a$10$xAsoeMJ.jc/kSxhviLAg7.j2iFrhi6yYAdniNdjLiIUWU/BRZl2Ti', 2, NULL, NULL, NULL, NULL, 1, false, NOW(), 547887852587843593, 1, NOW()),
|
||||
(547889293968801823, 'Charles', 'Charles', '{bcrypt}$2a$10$xAsoeMJ.jc/kSxhviLAg7.j2iFrhi6yYAdniNdjLiIUWU/BRZl2Ti', 1, NULL, NULL, NULL, '代码写到极致,就是艺术。', 1, false, NOW(), 547887852587843595, 1, NOW()),
|
||||
(547889293968801824, 'Yoofff', 'Yoofff', '{bcrypt}$2a$10$xAsoeMJ.jc/kSxhviLAg7.j2iFrhi6yYAdniNdjLiIUWU/BRZl2Ti', 1, NULL, NULL, NULL, '弱小和无知不是生存的障碍,傲慢才是。', 1, false, NOW(), 1, 1, NOW()),
|
||||
|
Reference in New Issue
Block a user