【发布时间】:2023-01-09 19:20:18
【问题描述】:
我的任务是 - 获取 JWT 令牌。(所有详细信息都在这里How to get jwt token value in spring webflux? (to exchange it with Minio STS token))
但是让我们丢弃多余的细节。简而言之:
我有一个源代码:
Mono<Object> mono = ReactiveSecurityContextHolder.getContext()
.map(securityContext -> securityContext.getAuthentication().getPrincipal());
mono.block(); //<-- I need to get the result of Mono execution HERE at this thread in a blocking manner
我在这里得到错误:
block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-2
因为在 reactor 和 bla bla bla 中禁止使用阻塞调用,尽管在以前版本的 reactor 中这段代码是有效的。
我开始寻找问题的解决方案并创建了 2 个主题:
- How to get jwt token value in spring webflux? (to exchange it with Minio STS token)
-
How to get raw token from ReactiveSecurityContextHolder?
我有一个 advice 以 here 描述的方式进行阻塞调用:
所以我的尝试是:
尝试 1:
Mono<Object> mono = ReactiveSecurityContextHolder.getContext() .map(securityContext -> securityContext.getAuthentication().getPrincipal()); Mono<Object> objectMono = mono.subscribeOn(Schedulers.boundedElastic()); Object result = objectMono.block();尝试 2:
Mono<Object> mono = ReactiveSecurityContextHolder.getContext() .map(securityContext -> securityContext.getAuthentication().getPrincipal()); mono.subscribeOn(Schedulers.boundedElastic()); Object result = mono.block();在这两种情况下,我都会收到相同的错误:
block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-2我该如何解决?
【问题讨论】:
标签: java spring-boot spring-security spring-webflux reactor