【发布时间】:2021-06-10 15:57:26
【问题描述】:
我正在尝试根据经过身份验证的用户设置 WebClient 标头值,如下所示:
webClient.post().header(HttpHeaders.AUTHORIZATION, getUserIdFromSession())...
和
public String getUserIdFromSession() {
Mono<Authentication> authentication = ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication);
//do something here to get user credentials and return them
}
我应该将所需的标头值存储在其他地方吗?因为以反应方式,一切都返回一个 Mono/Flux 并且我目前无法使用经过身份验证的用户数据,因为我已将其与 Spring MVC 一起使用。在那里我可以做SecurityContextHolder.getContext().getAuthentication()
【问题讨论】:
标签: spring spring-boot spring-security spring-webflux spring-webclient