我正在尝试配置我的 Spring Boot 应用程序以登录 zipkin 服务器。问题是该服务器受代理保护(具有基本身份验证),我找不到任何描述如何使用 spring-sleuth 配置授权的文档。
我尝试过使用这种配置:
spring.zipkin.baseUrl: http://user:password@zipkin-server:9411
但没有成功,日志指示:
ZipkinRestTemplateWrapper : Created POST request for "http://user:password@zipkin-server:9411/api/v2/spans"
ZipkinRestTemplateWrapper : Setting request Accept header to [text/plain, application/json, application/*+json, */*]
ZipkinRestTemplateWrapper : Writing [[B@46d92b65] as "application/json" using [org.springframework.http.converter.ByteArrayHttpMessageConverter@53804b23]
ZipkinRestTemplateWrapper : POST request for "http://user:password@zipkin-server:9411/api/v2/spans" resulted in 401 (Unauthorized); invoking error handler
我尝试过使用curl,它有效。
有人已经成功使用 spring-sleuth 配置身份验证吗?
最佳答案
对于基本身份验证,需要将用户名和密码作为 HTTP header Authorization
的一部分发送。 header 值按字符串 username:password
的 Base64 编码计算。因此,如果用户名是 abcd
且密码是 1234
,则 header 将看起来像这样(使用的聊天集:UTF-8)。
Authorization: Basic YWJjZDoxMjM0
Sleuth 云项目提供了 ZipkinRestTemplateCustomizer
来配置用于与 Zipkin 服务器通信的 RestTemplate
。
请参阅文档以了解相同内容: https://cloud.spring.io/spring-cloud-sleuth/reference/html/#sending-spans-to-zipkin
注意:Base64 编码是可逆的,因此基本身份验证凭据不安全。 HTTPS 通信应与基本身份验证一起使用。
关于spring - 使用 Spring Sleuth Zipkin 配置基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55001316/