zuul和资源服务器之间的spring会话共享

问题描述 投票:0回答:3

我试图搜索,但没有找到适合我们情况的答案。

基本上,我们有zuul服务器作为API网关,履行以下职责

+ Autheticate user, and create and maintain session with users
+ Sessions will be stored in redis (we are using spring session with redis)

我希望所有资源服务器都能访问由zuul服务器创建的会话信息。但我无法从资源服务器获取会话信息。它总是返回null,我检查了redis服务器,看到会话已经由zuul服务器创建了

请注意,我们使用Netflix服务发现来转发来自Zuul各自服务的请求。

非常感谢任何建议

spring-boot netflix-zuul spring-session
3个回答
0
投票

即使您在Redis中存储会话,会话ID也存储在cookie中,并且必须传递到资源服务器。但zuul的默认配置是过滤掉所有与cookie相关的标头。

以下是zuul的默认配置,适用于未传递给下游服务器的敏感标头。 qazxsw poi

要将zuul中与cookie相关的标头传递到资源服务器,您需要重新定义它而不使用像下面这样的cookie相关标头。 zuul.sensitiveHeaders=Cookie,Set-Cookie,Authorization

以上示例使用全局配置。您可以为每条路线定义它。请参阅链接文档中的“Cookies和敏感标题”部分: zuul.sensitiveHeaders=Authorization

如果还需要在资源服务器中授权标头,则可以使用空白列表定义上述配置。


0
投票

实际上我错过了以下代码。

http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html

在添加上面的代码以将cookie中的session_id从zuul过滤器传递到相应的微服务之后,它能够从zuul过滤器中拾取session_id。


0
投票

确保您使用的过滤器超过5个

context.addZuulRequestHeader("Cookie", "SESSION=" +  httpSession.getId());

0
投票

我有同样的问题。但在我配置application.yml以将“sensitiveHeaders”设置为空后。我的问题解决了! :)

public int filterOrder() {
    return 10;
}```
for more detail find the below example
https://stackoverflow.com/a/54833734/11103297

zuul: routes: users: path: /myusers/** sensitiveHeaders: url: https://downstream

© www.soinside.com 2019 - 2024. All rights reserved.