【发布时间】:2021-12-28 06:43:42
【问题描述】:
我需要帮助!
这是我的网络客户端
private WebClient client = WebClient.create("http://address:port");
public Mono<RespDto> translate(AuthPrincipal principal, ReqDto dto, String token) {
return client.get()
.uri(uriBuilder -> uriBuilder
.path("/api")
.queryParam("id", dto.getId())
.queryParam("content", dto.getContent())
.queryParam("profile", dto.getProfile())
.build())
.headers(h -> h.setBearerAuth(token.split(" ")[1]))
.retrieve()
.bodyToMono(RespDto.class);
}
这是我要检索的 api 的控制器
@GetMapping("")
public Mono<?> trans(@AuthenticationPrincipal @ApiIgnore AuthPrincipal principal,
@Valid ReqDto reqDto) {
return service.function(principal, reqDto);
}
所以我的问题是服务函数检查主体 id 的权限,但我知道如何通过 webclient 传递 AuthPrincipal 对象...
请帮助菜鸟!
【问题讨论】:
-
你没有。您传递您的凭据/令牌或向服务器验证您所需的任何内容。
标签: java spring-boot webclient