处理 SpringMVC 全局处理
This commit is contained in:
@@ -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