Mat*_*ble 5 spring-security spring-boot spring-security-oauth2 jhipster spring-cloud-gateway
I\xe2\x80\x99m 尝试将 JHipster 从使用 Zuul 迁移到 Spring Cloud Gateway。JHipster 使用 Eureka 来查找路由,我相信我\xe2\x80\x99已经正确配置了 Spring Cloud Gateway 来查找路由并将访问令牌传播给它们。这里\xe2\x80\x99是我的配置:
\n\nspring:\n cloud:\n gateway:\n default-filters:\n - TokenRelay\n discovery:\n locator:\n enabled: true\n lower-case-service-id: true\n route-id-prefix: /services/\n httpclient:\n pool:\n max-connections: 1000\nRun Code Online (Sandbox Code Playgroud)\n\n我\xe2\x80\x99m 遇到的问题是访问令牌没有Authorization向下游服务发送标头。
以下是我的 Zuul 的配置方式application.yml:
zuul: # those values must be configured depending on the application specific needs\n sensitive-headers: Cookie,Set-Cookie #see https://github.com/spring-cloud/spring-cloud-netflix/issues/3126\n host:\n max-total-connections: 1000\n max-per-route-connections: 100\n prefix: /services\n semaphore:\n max-semaphores: 500\nRun Code Online (Sandbox Code Playgroud)\n\n我创建了一个拉取请求来显示集成 Spring Cloud Gateway 后发生的更改。
\n\nhttps://github.com/mraible/jhipster-reactive-microservices-oauth2/pull/4
\n\n重现问题的步骤:
\n\ngit clone -b reactive git@github.com:mraible/jhipster-reactive-microservices-oauth2.git\nRun Code Online (Sandbox Code Playgroud)\n\n启动 JHipsterRegistry、Keycloak 和网关应用程序:
\n\ncd jhipster-reactive-microservices-oauth2/gateway\ndocker-compose -f src/main/docker/jhipster-registry.yml up -d\ndocker-compose -f src/main/docker/keycloak.yml up -d\n./mvnw\nRun Code Online (Sandbox Code Playgroud)\n\n启动 MongoDB 和博客应用程序:
\n\ncd ../blog\ndocker-compose -f src/main/docker/mongodb.yml up -d\n./mvnw\nRun Code Online (Sandbox Code Playgroud)\n\n在浏览器中导航到http://localhost:8080,使用 登录admin/admin,然后尝试转到Entities > Blog。您将收到 403 访问被拒绝错误。如果您在 Chrome 开发者工具中查看网络流量,您会发现访问令牌不包含在任何标头中。
我能够使用这个答案解决这个问题。
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
predicates:
- name: Path
args:
pattern: "'/services/'+serviceId.toLowerCase()+'/**'"
filters:
- name: RewritePath
args:
regexp: "'/services/' + serviceId.toLowerCase() + '/(?<remaining>.*)'"
replacement: "'/${remaining}'"
Run Code Online (Sandbox Code Playgroud)
我还必须添加.pathMatchers("/services/**").authenticated()我的安全配置,而 Zuul 不需要这些配置。你可以在这里看到我的承诺。
| 归档时间: |
|
| 查看次数: |
5225 次 |
| 最近记录: |