mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-15 14:57:41 +08:00
refactor: 梳理用户和角色体系,内置角色:超级管理员、租户管理员(系统管理员),且内置用户和角色不允许变更及分配
This commit is contained in:
@@ -17,9 +17,12 @@
|
||||
package top.continew.admin.common.context;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import top.continew.admin.common.constant.SysConstants;
|
||||
import top.continew.admin.common.config.TenantExtensionProperties;
|
||||
import top.continew.admin.common.constant.GlobalConstants;
|
||||
import top.continew.admin.common.enums.RoleCodeEnum;
|
||||
import top.continew.starter.core.util.CollUtils;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -101,23 +104,16 @@ public class UserContext implements Serializable {
|
||||
this.passwordExpirationDays = passwordExpirationDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置角色
|
||||
*
|
||||
* @param roles 角色
|
||||
*/
|
||||
public void setRoles(Set<RoleContext> roles) {
|
||||
this.roles = roles;
|
||||
this.roleCodes = CollUtils.mapToSet(roles, RoleContext::getCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
*
|
||||
* @return true:是;false:否
|
||||
*/
|
||||
public boolean isAdmin() {
|
||||
if (CollUtil.isEmpty(roleCodes)) {
|
||||
return false;
|
||||
}
|
||||
return roleCodes.contains(SysConstants.SUPER_ROLE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码是否已过期
|
||||
*
|
||||
@@ -125,7 +121,7 @@ public class UserContext implements Serializable {
|
||||
*/
|
||||
public boolean isPasswordExpired() {
|
||||
// 永久有效
|
||||
if (this.passwordExpirationDays == null || this.passwordExpirationDays <= SysConstants.NO) {
|
||||
if (this.passwordExpirationDays == null || this.passwordExpirationDays <= GlobalConstants.Boolean.NO) {
|
||||
return false;
|
||||
}
|
||||
// 初始密码(第三方登录用户)暂不提示修改
|
||||
@@ -134,4 +130,29 @@ public class UserContext implements Serializable {
|
||||
}
|
||||
return this.pwdResetTime.plusDays(this.passwordExpirationDays).isBefore(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为超级管理员用户
|
||||
*
|
||||
* @return true:是;false:否
|
||||
*/
|
||||
public boolean isSuperAdminUser() {
|
||||
if (CollUtil.isEmpty(roleCodes)) {
|
||||
return false;
|
||||
}
|
||||
return roleCodes.contains(RoleCodeEnum.SUPER_ADMIN.getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为租户管理员用户
|
||||
*
|
||||
* @return true:是;false:否
|
||||
*/
|
||||
public boolean isTenantAdminUser() {
|
||||
if (CollUtil.isEmpty(roleCodes)) {
|
||||
return false;
|
||||
}
|
||||
TenantExtensionProperties tenantExtensionProperties = SpringUtil.getBean(TenantExtensionProperties.class);
|
||||
return !tenantExtensionProperties.isDefaultTenant() && roleCodes.contains(RoleCodeEnum.TENANT_ADMIN.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,12 +181,22 @@ public class UserContextHolder {
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
* 是否为超级管理员用户
|
||||
*
|
||||
* @return 是否为管理员
|
||||
* @return true:是;false:否
|
||||
*/
|
||||
public static boolean isAdmin() {
|
||||
public static boolean isSuperAdminUser() {
|
||||
StpUtil.checkLogin();
|
||||
return getContext().isAdmin();
|
||||
return getContext().isSuperAdminUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为租户管理员用户
|
||||
*
|
||||
* @return true:是;false:否
|
||||
*/
|
||||
public static boolean isTenantAdminUser() {
|
||||
StpUtil.checkLogin();
|
||||
return getContext().isTenantAdminUser();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user