|
|
|
|
@ -13,6 +13,7 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.util.AntPathMatcher;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.FilterChain;
|
|
|
|
|
@ -20,6 +21,8 @@ import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -33,22 +36,32 @@ import java.util.Objects;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class TenantSecurityWebFilter extends ApiRequestFilter {
|
|
|
|
|
|
|
|
|
|
private static final String INNER_PROFILE = "inner";
|
|
|
|
|
private static final List<String> INNER_IGNORE_URLS = Arrays.asList(
|
|
|
|
|
"/admin-api/iot/device-operation-record/runOverview",
|
|
|
|
|
"/admin-api/mes/device-line/deviceParameterAnalysis",
|
|
|
|
|
"/admin-api/mes/device-ledger/list"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
private final TenantProperties tenantProperties;
|
|
|
|
|
|
|
|
|
|
private final AntPathMatcher pathMatcher;
|
|
|
|
|
|
|
|
|
|
private final GlobalExceptionHandler globalExceptionHandler;
|
|
|
|
|
private final TenantFrameworkService tenantFrameworkService;
|
|
|
|
|
private final Environment environment;
|
|
|
|
|
|
|
|
|
|
public TenantSecurityWebFilter(TenantProperties tenantProperties,
|
|
|
|
|
WebProperties webProperties,
|
|
|
|
|
GlobalExceptionHandler globalExceptionHandler,
|
|
|
|
|
TenantFrameworkService tenantFrameworkService) {
|
|
|
|
|
TenantFrameworkService tenantFrameworkService,
|
|
|
|
|
Environment environment) {
|
|
|
|
|
super(webProperties);
|
|
|
|
|
this.tenantProperties = tenantProperties;
|
|
|
|
|
this.pathMatcher = new AntPathMatcher();
|
|
|
|
|
this.globalExceptionHandler = globalExceptionHandler;
|
|
|
|
|
this.tenantFrameworkService = tenantFrameworkService;
|
|
|
|
|
this.environment = environment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -101,6 +114,9 @@ public class TenantSecurityWebFilter extends ApiRequestFilter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isIgnoreUrl(HttpServletRequest request) {
|
|
|
|
|
if (isInnerProfile() && isInnerIgnoreUrl(request)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// 快速匹配,保证性能
|
|
|
|
|
if (CollUtil.contains(tenantProperties.getIgnoreUrls(), request.getRequestURI())) {
|
|
|
|
|
return true;
|
|
|
|
|
@ -114,4 +130,17 @@ public class TenantSecurityWebFilter extends ApiRequestFilter {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isInnerIgnoreUrl(HttpServletRequest request) {
|
|
|
|
|
for (String url : INNER_IGNORE_URLS) {
|
|
|
|
|
if (pathMatcher.match(url, request.getRequestURI())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isInnerProfile() {
|
|
|
|
|
return Arrays.asList(environment.getActiveProfiles()).contains(INNER_PROFILE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|