1、菜单权限问题修复;

2、增加修改菜单权限刷新本地缓存;
This commit is contained in:
gaoqr
2024-06-13 16:38:17 +08:00
parent e8e2052be6
commit 69a679ff77
10 changed files with 136 additions and 21 deletions
@@ -1,8 +1,6 @@
package com.cf.imes.framework.organ.core.security;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.cf.imes.framework.common.enums.RpcConstants;
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.servlet.ServletUtils;
@@ -56,18 +54,10 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
this.organFrameworkService = organFrameworkService;
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return super.shouldNotFilter(request) &&
!StrUtil.startWithAny(request.getRequestURI(), RpcConstants.RPC_API_PREFIX); // 因为 RPC API 也会透传组织编号
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
Long organId = WebFrameworkUtils.getOrganId(request);
//Long organId = OrganContextHolder.getOrganId();
boolean isRpcRequest = WebFrameworkUtils.isRpcRequest(request);
// 1. 登陆的用户,校验是否有权限访问该组织,避免越权问题。
LoginUser user = SecurityFrameworkUtils.getLoginUser();
if (user != null) {
@@ -76,8 +66,7 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
organId = user.getOrganId();
OrganContextHolder.setOrganId(organId);
// 如果传递了组织编号,则进行比对组织编号,避免越权问题
} else if (!Objects.equals(user.getOrganId(), OrganContextHolder.getOrganId())
&& !isRpcRequest) { // Cloud 特殊逻辑:如果是 RPC 请求,就不校验了。主要考虑,一些场景下,会调用 OrganUtils 去切换组织
} else if (!Objects.equals(user.getOrganId(), OrganContextHolder.getOrganId())) { // Cloud 特殊逻辑:如果是 RPC 请求,就不校验了。主要考虑,一些场景下,会调用 OrganUtils 去切换组织
log.error("[doFilterInternal][组织({}) User({}/{}) 越权访问组织({}) URL({}/{})]",
user.getOrganId(), user.getId(), user.getUserType(),
OrganContextHolder.getOrganId(), request.getRequestURI(), request.getMethod());