处理 SpringMVC 全局处理
This commit is contained in:
@@ -15,7 +15,6 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
|
||||
OAUTH2_ACCESS_TOKEN_NOT_FOUND(1001001001, "访问令牌不存在"),
|
||||
OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED(1001001002, "访问令牌已过期"),
|
||||
OAUTH2_ACCESS_TOKEN_INVALID(1001001003, "访问令牌已失效"),
|
||||
OAUTH2_NOT_AUTHENTICATION(1001001004, "账号未登录"),
|
||||
OAUTH2_REFRESH_TOKEN_NOT_FOUND(1001001005, "刷新令牌不存在"),
|
||||
OAUTH_REFRESH_TOKEN_EXPIRED(1001001006, "访问令牌已过期"),
|
||||
OAUTH_REFRESH_TOKEN_INVALID(1001001007, "刷新令牌已失效"),
|
||||
@@ -70,7 +69,6 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
|
||||
DEPARTMENT_EXISTS_ADMIN(1002007006, "部门中存在员工,无法删除"),
|
||||
|
||||
// ========== 权限模块 1002008000 ==========
|
||||
PERMISSION_DENY(1002008001, "没有该操作权限"),
|
||||
PERMISSION_DEMO_PERMISSION_DENY(1002008002, "演示账号,暂不允许写操作。欢迎加入我们的交流群:http://t.cn/EKEr5WE"),
|
||||
PERMISSION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002008004, "分配角色资源时,有资源不存在"),
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package cn.iocoder.mall.systemservice.rpc.systemlog.dto;
|
||||
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import cn.iocoder.mall.systemservice.enums.systemlog.SystemExceptionLogProcessStatusEnum;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 系统异常日志处理 DTO
|
||||
*/
|
||||
@@ -16,14 +20,18 @@ public class SystemExceptionLogProcessDTO extends PageParam {
|
||||
/**
|
||||
* 系统异常日志编号
|
||||
*/
|
||||
@NotNull(message = "系统异常日志编号不能为空")
|
||||
private Integer logId;
|
||||
/**
|
||||
* 处理状态
|
||||
*/
|
||||
@NotNull(message = "处理状态不能为空")
|
||||
@InEnum(value = SystemExceptionLogProcessStatusEnum.class, message = "处理状态必须是 {value}")
|
||||
private Integer processStatus;
|
||||
/**
|
||||
* 处理管理员编号
|
||||
*/
|
||||
@NotNull(message = "处理管理员编号不能为空")
|
||||
private Integer processAdminId;
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogCrea
|
||||
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogPageBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@@ -21,6 +22,7 @@ public interface SystemExceptionLogConvert {
|
||||
|
||||
SystemExceptionLogCreateBO convert(SystemExceptionLogCreateDTO bean);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<SystemExceptionLogBO> convertPage(IPage<SystemExceptionLogDO> page);
|
||||
|
||||
SystemExceptionLogBO convert(SystemExceptionLogDO bean);
|
||||
|
||||
@@ -17,8 +17,8 @@ public interface SystemExceptionLogMapper extends BaseMapper<SystemExceptionLogD
|
||||
.eqIfPresent("user_id", pageBO.getUserId())
|
||||
.eqIfPresent("user_type", pageBO.getUserType())
|
||||
.eqIfPresent("application_name", pageBO.getApplicationName())
|
||||
.eqIfPresent("processStatus", pageBO.getProcessStatus())
|
||||
.orderByDesc("start_time"));
|
||||
.eqIfPresent("process_status", pageBO.getProcessStatus())
|
||||
.orderByDesc("exception_time"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.PERMISSION_DENY;
|
||||
import static cn.iocoder.common.framework.enums.GlobalErrorCodeEnum.FORBIDDEN;
|
||||
|
||||
/**
|
||||
* 权限 Manager
|
||||
@@ -98,7 +98,7 @@ public class PermissionManager {
|
||||
// 查询管理员拥有的角色关联数据
|
||||
Set<Integer> roleIds = permissionService.listAdminRoleIds(checkDTO.getAdminId());
|
||||
if (CollectionUtil.isEmpty(roleIds)) { // 如果没有角色,默认无法访问
|
||||
throw ServiceExceptionUtil.exception(PERMISSION_DENY);
|
||||
throw ServiceExceptionUtil.exception(FORBIDDEN);
|
||||
}
|
||||
// 判断是否为超管。若是超管,默认有所有权限
|
||||
if (roleService.hasSuperAdmin(roleIds)) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.common.framework.enums.GlobalErrorCodeEnum.FORBIDDEN;
|
||||
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*;
|
||||
|
||||
/**
|
||||
@@ -150,13 +151,13 @@ public class PermissionService {
|
||||
// 权限验证
|
||||
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByResourceIds(permissionIds);
|
||||
if (CollectionUtil.isEmpty(roleResourceDOs)) { // 资源未授予任何角色,必然权限验证不通过
|
||||
throw ServiceExceptionUtil.exception(PERMISSION_DENY);
|
||||
throw ServiceExceptionUtil.exception(FORBIDDEN);
|
||||
}
|
||||
Map<Integer, List<Integer>> resourceRoleMap = CollectionUtils.convertMultiMap(roleResourceDOs,
|
||||
RoleResourceDO::getResourceId, RoleResourceDO::getRoleId);
|
||||
for (Map.Entry<Integer, List<Integer>> entry : resourceRoleMap.entrySet()) {
|
||||
if (!CollectionUtil.containsAny(roleIds, entry.getValue())) { // 所以有任一不满足,就验证失败,抛出异常
|
||||
throw ServiceExceptionUtil.exception(PERMISSION_DENY);
|
||||
throw ServiceExceptionUtil.exception(FORBIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user