|
|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
package cn.iocoder.yudao.framework.tenant.core.security;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
|
|
|
|
@ -15,13 +13,13 @@ import cn.iocoder.yudao.framework.web.config.WebProperties;
|
|
|
|
|
import cn.iocoder.yudao.framework.web.core.filter.ApiRequestFilter;
|
|
|
|
|
import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler;
|
|
|
|
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.util.AntPathMatcher;
|
|
|
|
|
|
|
|
|
|
import jakarta.servlet.FilterChain;
|
|
|
|
|
import jakarta.servlet.ServletException;
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.util.AntPathMatcher;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
@ -56,12 +54,6 @@ public class TenantSecurityWebFilter extends ApiRequestFilter {
|
|
|
|
|
this.tenantFrameworkService = tenantFrameworkService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
@ -75,8 +67,7 @@ public class TenantSecurityWebFilter extends ApiRequestFilter {
|
|
|
|
|
tenantId = user.getTenantId();
|
|
|
|
|
TenantContextHolder.setTenantId(tenantId);
|
|
|
|
|
// 如果传递了租户编号,则进行比对租户编号,避免越权问题
|
|
|
|
|
} else if (!Objects.equals(user.getTenantId(), TenantContextHolder.getTenantId())
|
|
|
|
|
&& !isRpcRequest) { // Cloud 特殊逻辑:如果是 RPC 请求,就不校验了。主要考虑,一些场景下,会调用 TenantUtils 去切换租户
|
|
|
|
|
} else if (!Objects.equals(user.getTenantId(), TenantContextHolder.getTenantId())) {
|
|
|
|
|
log.error("[doFilterInternal][租户({}) User({}/{}) 越权访问租户({}) URL({}/{})]",
|
|
|
|
|
user.getTenantId(), user.getId(), user.getUserType(),
|
|
|
|
|
TenantContextHolder.getTenantId(), request.getRequestURI(), request.getMethod());
|
|
|
|
|
|