spring - 使用 Spring Sleuth Zipkin 配置基本身份验证

标签 spring spring-cloud-sleuth zipkin

我正在尝试配置我的 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/

相关文章:

java - 无法 Autowiring DefaultTokenService

spring - 跨线程发送 TraceId

spring - 注入(inject) Autowiring 的依赖项失败;

java - 如何使用 FFmpeg 限制阅读速度

java - kafka 0.8.2.2有spring支持吗?

java - Brave (Zipkin) 是否支持从客户端到服务器的并行请求

spring-boot - Zipkin 与 Spring Boot 2.2 和 Hoxton Cloud

java - 使用 Jetty 服务器将 spring cloud sleuth 添加到 Spring 应用程序

java - 即使在 Bluemix 中作为 header 传递到服务请求,Sleuth header X-B3-TraceId 值也会重新生成

zipkin - 在 sleuth 中添加自定义跟踪 ID