Gan*_*hix 6 java spring stream spring-security spring-boot
当我尝试从并行流中的安全上下文获取主体时,如果主体不在主线程中,它总是返回 null。
当用户通过身份验证时,以下代码段失败:
listOfSomething.parallelStream()
.foreach(el -> {
if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() == null){
throw new RuntimeException();
}});
Run Code Online (Sandbox Code Playgroud)
文档说:
定义与当前执行线程关联的最小安全信息的接口。
但是,有什么办法可以做到吗?它在主线程中启动并使用 ForkJoinPool
谢谢你!
看来您需要使用不同的SecurityContextHolder策略。有关如何更改它的更多详细信息,请参阅https://docs.spring.io/spring-security/site/docs/5.0.0.RELEASE/reference/htmlsingle/#securitycontextholder-securitycontext-and-authentication-objects
| 归档时间: |
|
| 查看次数: |
5601 次 |
| 最近记录: |