Zuul -> Eureka Server,基本身份验证问题

2024-05-05

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

如果我使用基本授权,它会抛出“消息”:“访问此资源需要完全身份验证”

以下是我的观察:

在 ZuulFilter 的 run() 方法中,我得到了值 request.getHeader("授权") --> 基本 c29tOnNvbzz==

但是一旦它到达微服务,我得到的值为“null”, request.getHeader("授权") --> null

使用 Spring Boot 版本:1.4.0.RELEASE

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

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

请帮忙,不确定授权标头在哪里消失。

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

默认情况下,授权是敏感标头,这意味着 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 https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#cookies-and-sensitive-headers

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Zuul -> Eureka Server,基本身份验证问题 的相关文章

随机推荐