我正在尝试将JHipster从使用Zuul迁移到。JHipster使用Eureka查找路由,我相信我已经正确地配置了来查找路由并将访问令牌传播给它们。这是我的配置:
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头。
下面是在我的application.yml中使用Zuul配置东西的方式
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我创建了一个pull请求,以显示在集成之后发生了哪些变化。
https://github.com/mraible/jhipster-reactive-microservices-oauth2/pull/4
复制这一问题的步骤:
git clone -b reactive git@github.com:mraible/jhipster-reactive-microservices-oauth2.git启动JHipster注册表、密钥披风和网关应用程序:
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://localhost:8080,使用admin/admin登录,然后尝试转到Entities > Blog。您将得到一个403访问拒绝错误。如果您在工具中查看网络流量,您将看到访问令牌没有包含在任何头文件中。
发布于 2020-02-18 23:39:02
我能够用这个答案解决这个问题。
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}'"我还必须将.pathMatchers("/services/**").authenticated()添加到我的安全配置中,这是Zuul所不需要的。你可以看到我的在此提交。
https://stackoverflow.com/questions/60251863
复制相似问题