我正在尝试将 JHipster 从使用 Zuul 迁移到 Spring Cloud Gateway。 JHipster 使用 Eureka 来查找路由,我相信我已经正确配置了 Spring Cloud Gateway 来查找路由并将访问令牌传播给它们。这是我的配置:
spring:
cloud:
gateway:
default-filters:
- TokenRelay
discovery:
locator:
enabled: true
lower-case-service-id: true
route-id-prefix: /services/
httpclient:
pool:
max-connections: 1000
我遇到的问题是访问令牌没有发送Authorization
标头到下游服务。
以下是我的 Zuul 的配置方式application.yml
:
zuul: # those values must be configured depending on the application specific needs
sensitive-headers: Cookie,Set-Cookie #see https://github.com/spring-cloud/spring-cloud-netflix/issues/3126
host:
max-total-connections: 1000
max-per-route-connections: 100
prefix: /services
semaphore:
max-semaphores: 500
我创建了一个拉取请求来显示集成 Spring Cloud Gateway 后发生的变化。
https://github.com/mraible/jhipster-reactive-microservices-oauth2/pull/4 https://github.com/mraible/jhipster-reactive-microservices-oauth2/pull/4
重现问题的步骤:
git clone -b reactive gi[email protected] /cdn-cgi/l/email-protection:mraible/jhipster-reactive-microservices-oauth2.git
启动 JHipsterRegistry、Keycloak 和网关应用程序:
cd jhipster-reactive-microservices-oauth2/gateway
docker-compose -f src/main/docker/jhipster-registry.yml up -d
docker-compose -f src/main/docker/keycloak.yml up -d
./mvnw
启动 MongoDB 和博客应用程序:
cd ../blog
docker-compose -f src/main/docker/mongodb.yml up -d
./mvnw
导航http://本地主机:8080 http://localhost:8080在您的浏览器中,使用以下命令登录admin/admin
,并尝试去Entities > Blog。您将收到 403 访问被拒绝错误。如果您在 Chrome 开发者工具中查看网络流量,您会发现访问令牌不包含在任何标头中。