From 594ea3208d6cca33b50394f81fa69c38b6046ec5 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Thu, 20 Mar 2025 22:27:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(system):=20=E6=96=B0=E5=A2=9E=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E7=AC=AC=E4=B8=89=E6=96=B9=E7=99=BB=E5=BD=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=BB=98=E8=AE=A4=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 原来第三方登录用户注册后默认为超管用户,是出于方便演示环境用户查看,本次有 Gitee@hagyao520 大佬反馈不安全,干脆调整此逻辑,感谢大佬提供的普通用户角色 PR --- .../admin/common/constant/SysConstants.java | 15 ++++++++++----- .../admin/auth/handler/SocialLoginHandler.java | 4 +--- .../controller/schedule/DemoEnvironmentJob.java | 2 +- .../resources/db/changelog/mysql/main_data.sql | 5 +++-- .../db/changelog/postgresql/main_data.sql | 5 +++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/continew-common/src/main/java/top/continew/admin/common/constant/SysConstants.java b/continew-common/src/main/java/top/continew/admin/common/constant/SysConstants.java index 509be74d..1e08d9c5 100644 --- a/continew-common/src/main/java/top/continew/admin/common/constant/SysConstants.java +++ b/continew-common/src/main/java/top/continew/admin/common/constant/SysConstants.java @@ -54,11 +54,21 @@ public class SysConstants { */ public static final String SUPER_ROLE_CODE = "admin"; + /** + * 普通用户角色编码 + */ + public static final String GENERAL_ROLE_CODE = "general"; + /** * 超管角色 ID */ public static final Long SUPER_ROLE_ID = 1L; + /** + * 普通用户角色 ID + */ + public static final Long GENERAL_ROLE_ID = 2L; + /** * 全部权限标识 */ @@ -74,11 +84,6 @@ public class SysConstants { */ public static final String LOGOUT_URI = "/auth/logout"; - /** - * 描述类字段后缀 - */ - public static final String DESCRIPTION_FIELD_SUFFIX = "String"; - private SysConstants() { } } diff --git a/continew-module-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java b/continew-module-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java index c7e33b6d..537bf8fc 100644 --- a/continew-module-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java +++ b/continew-module-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java @@ -41,7 +41,6 @@ import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.enums.GenderEnum; import top.continew.admin.system.enums.MessageTemplateEnum; import top.continew.admin.system.enums.MessageTypeEnum; -import top.continew.admin.system.model.entity.RoleDO; import top.continew.admin.system.model.entity.user.UserDO; import top.continew.admin.system.model.entity.user.UserSocialDO; import top.continew.admin.system.model.req.MessageReq; @@ -110,8 +109,7 @@ public class SocialLoginHandler extends AbstractLoginHandler { user.setStatus(DisEnableStatusEnum.ENABLE); userService.save(user); Long userId = user.getId(); - RoleDO role = roleService.getByCode(SysConstants.SUPER_ROLE_CODE); - userRoleService.assignRolesToUser(Collections.singletonList(role.getId()), userId); + userRoleService.assignRolesToUser(Collections.singletonList(SysConstants.GENERAL_ROLE_ID), userId); userSocial = new UserSocialDO(); userSocial.setUserId(userId); userSocial.setSource(source); diff --git a/continew-webapi/src/main/java/top/continew/admin/controller/schedule/DemoEnvironmentJob.java b/continew-webapi/src/main/java/top/continew/admin/controller/schedule/DemoEnvironmentJob.java index 097faaf4..d4380200 100644 --- a/continew-webapi/src/main/java/top/continew/admin/controller/schedule/DemoEnvironmentJob.java +++ b/continew-webapi/src/main/java/top/continew/admin/controller/schedule/DemoEnvironmentJob.java @@ -71,7 +71,7 @@ public class DemoEnvironmentJob { private static final Long MESSAGE_FLAG = 0L; private static final List USER_FLAG = List .of(1L, 547889293968801822L, 547889293968801823L, 547889293968801824L, 547889293968801825L, 547889293968801826L, 547889293968801827L, 547889293968801828L, 547889293968801829L, 547889293968801830L, 547889293968801831L); - private static final List ROLE_FLAG = List.of(1L, 547888897925840927L, 547888897925840928L); + private static final List ROLE_FLAG = List.of(1L, 2L, 547888897925840927L, 547888897925840928L); private static final Long DEPT_FLAG = 547887852587843611L; /** diff --git a/continew-webapi/src/main/resources/db/changelog/mysql/main_data.sql b/continew-webapi/src/main/resources/db/changelog/mysql/main_data.sql index 1737f462..f0186076 100644 --- a/continew-webapi/src/main/resources/db/changelog/mysql/main_data.sql +++ b/continew-webapi/src/main/resources/db/changelog/mysql/main_data.sql @@ -156,8 +156,9 @@ 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()), -(547888897925840927, '测试人员', 'tester', 5, NULL, 2, b'0', 1, NOW()), -(547888897925840928, '研发人员', 'developer', 4, NULL, 3, b'0', 1, NOW()); +(2, '普通用户', 'general', 4, '系统初始角色', 2, b'1', 1, NOW()), +(547888897925840927, '测试人员', 'tester', 5, NULL, 3, b'0', 1, NOW()), +(547888897925840928, '研发人员', 'developer', 4, NULL, 4, b'0', 1, NOW()); -- 初始化默认用户:admin/admin123;test/test123 INSERT INTO `sys_user` diff --git a/continew-webapi/src/main/resources/db/changelog/postgresql/main_data.sql b/continew-webapi/src/main/resources/db/changelog/postgresql/main_data.sql index 30aa9b70..dbbf261c 100644 --- a/continew-webapi/src/main/resources/db/changelog/postgresql/main_data.sql +++ b/continew-webapi/src/main/resources/db/changelog/postgresql/main_data.sql @@ -156,8 +156,9 @@ 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()), -(547888897925840927, '测试人员', 'tester', 5, NULL, 2, false, 1, NOW()), -(547888897925840928, '研发人员', 'developer', 4, NULL, 3, false, 1, NOW()); +(2, '普通用户', 'general', 4, '系统初始角色', 2, true, 1, NOW()), +(547888897925840927, '测试人员', 'tester', 5, NULL, 3, false, 1, NOW()), +(547888897925840928, '研发人员', 'developer', 4, NULL, 4, false, 1, NOW()); -- 初始化默认用户:admin/admin123;test/test123 INSERT INTO "sys_user"