小编Gan*_*hix的帖子

在并行流中获取安全上下文时主体为空

当我尝试从并行流中的安全上下文获取主体时,如果主体不在主线程中,它总是返回 null。

当用户通过身份验证时,以下代码段失败:

listOfSomething.parallelStream()
                .foreach(el -> { 
if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() == null){
            throw new RuntimeException();
}});
Run Code Online (Sandbox Code Playgroud)

文档说:

定义与当前执行线程关联的最小安全信息的接口。

但是,有什么办法可以做到吗?它在主线程中启动并使用 ForkJoinPool

谢谢你!

java spring stream spring-security spring-boot

6
推荐指数
1
解决办法
5601
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-security ×1

stream ×1