fix 修复 远程调用手动使用虚拟线程导致上下文丢失问题
This commit is contained in:
-25
@@ -2,26 +2,20 @@ package org.dromara.common.security.config;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.filter.SaServletFilter;
|
||||
import cn.dev33.satoken.filter.SaTokenContextFilterForJakartaServlet;
|
||||
import cn.dev33.satoken.httpauth.basic.SaHttpBasicUtil;
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.same.SaSameUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.dromara.common.core.constant.HttpStatus;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* 权限安全配置
|
||||
*
|
||||
@@ -30,25 +24,6 @@ import java.util.EnumSet;
|
||||
@AutoConfiguration
|
||||
public class SecurityConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 重新注册 Sa-Token 上下文过滤器,使其覆盖 Servlet 异步分发。
|
||||
*
|
||||
* @param filter Sa-Token 官方上下文过滤器
|
||||
* @return 过滤器注册配置
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean<SaTokenContextFilterForJakartaServlet> saTokenContextFilterRegistration(
|
||||
SaTokenContextFilterForJakartaServlet filter) {
|
||||
FilterRegistrationBean<SaTokenContextFilterForJakartaServlet> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(filter);
|
||||
registration.setName("saTokenContextFilterForServlet");
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.ERROR));
|
||||
registration.setAsyncSupported(true);
|
||||
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册sa-token的拦截器
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AuthFilter implements WebMvcConfigurer {
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新注册 Sa-Token 上下文过滤器,使其覆盖 Servlet 异步分发。
|
||||
* 重新注册 Sa-Token 上下文过滤器,使其覆盖网关 SSE/WebSocket 异步分发。
|
||||
*
|
||||
* @param filter Sa-Token 官方上下文过滤器
|
||||
* @return 过滤器注册配置
|
||||
|
||||
+3
-14
@@ -12,7 +12,6 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.utils.DateUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.ThreadUtils;
|
||||
import org.dromara.system.api.*;
|
||||
import org.dromara.system.api.domain.bo.RemoteTaskAssigneeBo;
|
||||
import org.dromara.system.api.domain.vo.RemoteDeptVo;
|
||||
@@ -31,7 +30,6 @@ import org.dromara.workflow.service.IFlwTaskAssigneeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -214,25 +212,16 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
|
||||
}
|
||||
|
||||
private List<RemoteUserVo> getUsersByTypes(Map<TaskAssigneeEnum, List<String>> typeIdMap) {
|
||||
List<Supplier<List<RemoteUserVo>>> suppliers = typeIdMap.entrySet().stream()
|
||||
.map(entry -> (Supplier<List<RemoteUserVo>>) () -> this.getUsersByType(entry.getKey(), entry.getValue()))
|
||||
.toList();
|
||||
return ThreadUtils.virtualSubmitAll(suppliers).stream()
|
||||
return typeIdMap.entrySet().stream()
|
||||
.map(entry -> this.getUsersByType(entry.getKey(), entry.getValue()))
|
||||
.filter(CollUtil::isNotEmpty)
|
||||
.flatMap(Collection::stream)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Map<TaskAssigneeEnum, Map<String, String>> getNamesByTypes(Map<TaskAssigneeEnum, List<String>> typeIdMap) {
|
||||
List<TaskAssigneeEnum> types = new ArrayList<>(typeIdMap.keySet());
|
||||
List<Supplier<Map<String, String>>> suppliers = types.stream()
|
||||
.map(type -> (Supplier<Map<String, String>>) () -> this.getNamesByType(type, typeIdMap.get(type)))
|
||||
.toList();
|
||||
List<Map<String, String>> names = ThreadUtils.virtualSubmitAll(suppliers);
|
||||
Map<TaskAssigneeEnum, Map<String, String>> nameMap = new EnumMap<>(TaskAssigneeEnum.class);
|
||||
for (int i = 0; i < types.size(); i++) {
|
||||
nameMap.put(types.get(i), names.get(i));
|
||||
}
|
||||
typeIdMap.forEach((type, ids) -> nameMap.put(type, this.getNamesByType(type, ids)));
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user