Spring boot Spring云网关和令牌中继过滤器
我正在尝试将JHipster从使用Zuul迁移到SpringCloudGateway。JHipster使用Eureka查找路由,我相信我已经正确配置了SpringCloudGateway来查找路由并将访问令牌传播给它们。这是我的配置:Spring boot Spring云网关和令牌中继过滤器,spring-boot,spring-security,jhipster,spring-security-oauth2,spring-cloud-gateway,Spring Boot,Spring Security,Jhipster,Spring Security Oauth2,Spring Cloud Gateway,我正在尝试将JHipster从使用Zuul迁移到SpringCloudGateway。JHipster使用Eureka查找路由,我相信我已经正确配置了SpringCloudGateway来查找路由并将访问令牌传播给它们。这是我的配置: spring: cloud: gateway: default-filters: - TokenRelay discovery: locator: enabled: true
spring:
cloud:
gateway:
default-filters:
- TokenRelay
discovery:
locator:
enabled: true
lower-case-service-id: true
route-id-prefix: /services/
httpclient:
pool:
max-connections: 1000
我遇到的问题是访问令牌没有向下游服务发送授权
头
下面是在我的应用程序中使用Zuul配置的情况。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
我创建了一个pull请求,以显示集成SpringCloudGateway后发生的变化
重现问题的步骤:
git clone -b reactive git@github.com:mraible/jhipster-reactive-microservices-oauth2.git
启动JHipster注册表、KeyClope和网关应用程序:
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
在浏览器中导航到,使用
admin/admin
登录,然后尝试转到实体博客。您将收到403拒绝访问错误。如果你在Chrome开发者工具中查看网络流量,你会发现访问令牌没有包含在任何标题中。我可以使用
spring:
云:
网关:
发现:
定位器:
已启用:true
谓词:
-名称:路径
args:
模式:“'/services/'+serviceId.toLowerCase()+'/**”
过滤器:
-名称:重写路径
args:
regexp:“'/services/'+serviceId.toLowerCase()+'/(?*)”
替换:“'/${剩余的}”
我还必须向我的安全配置中添加
.pathMatchers(“/services/**”).authenticated()
,这对于Zuul来说是不需要的。你可以看到我的眼睛 我能用计算机解决这个问题。我还必须向我的安全配置中添加.pathMatchers(“/services/**”).authenticated()
,这对于Zuul来说是不需要的。你可以看到我的眼睛。
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}'"