Zuul -> Eureka 服务器,基本身份验证问题

Zuul -> Eureka Server, Basic Authentication issue

如果流程不包含基本授权,我可以访问该服务。

如果我使用基本授权,它会抛出 "message":"Full authentication is required to access this resource"

以下是我的观察:

在 ZuulFilter 中,运行() 方法,我得到值 request.getHeader("Authorization") --> 基础 c29tOnNvbzz==

但是一旦它到达微服务,我就得到了 'null' 的价值, request.getHeader("Authorization") --> 空

使用 Spring 引导版本:1.4.0.RELEASE

This is my flow:
------------------

Zuul -> Service Discovery (Eureka Server) -> Service

请帮忙,不知道授权 header 在哪里消失了。

Eureka Server yml file:
-------------------------
server.port:4001
eureka.instance.hostname=localhost
eureka.client.fetch-registry:false
eureka.client.register-with-eureka:false
eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.client.healthcheck.enabled=true

Zuul yml file:
-----------------
server:
  port: 8765
info:
  component: Edge Server
eureka:
  instance:
    leaseRenewalIntervalInSeconds: 3
    metadataMap:
      instanceId: ${spring.application.name}:${random.value}
  client:
    # Default values comes from org.springframework.cloud.netflix.eurek.EurekaClientConfigBean
    registryFetchIntervalSeconds: 5
    instanceInfoReplicationIntervalSeconds: 5
    initialInstanceInfoReplicationIntervalSeconds: 5

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

zuul.sensitive-headers: Cookie,Set-Cookie,Authorization

logging:
  level:
    ROOT: WARN
    se.callista: INFO

    # Get info regarding connection to the cofig server and retries if required
    org.springframework.cloud.config.client.ConfigServicePropertySourceLocator: INFO
    org.springframework.retry.support.RetryTemplate: DEBUG

    # Set INFO to see the allocated port
    org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer: INFO
---
eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://localhost:4001/eureka,http://localhost:4002/eureka

这解决了我的问题,但这是我们唯一的解决方案吗?

ctx.addZuulRequestHeader("Authorization",request.getHeader("‌ 授权"))

你的 属性 对应 zuul.sensitiveHeaders 是错误的。驼峰式不带连字符。

https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#cookies-and-sensitive-headers

授权默认是一个敏感的header,这意味着Zuul不会转发它们。如果你把它留在敏感的头文件之外,Zuul 会转发这个头文件。

zuul.sensitiveHeaders: Cookie,Set-Cookie

它也应该是驼峰式而不是连字符。

额外信息:https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#cookies-and-sensitive-headers