我正在尝试在 Tomcat 下启用 SSO,以便访问 http://mydomain.com 和 http://www.mydomain.com 的会话 cookie 可用于向 http://subdomain.mydomain.com。所有这三个域都转到同一个 Web 应用程序,因此理想情况下,我不想弄乱 SSO,而只需在标准 JSESSIONID
cookie 上设置域。
然而,这似乎不可能,所以我尝试启用 Tomcat 的 SSO Valve。问题是 Valve 需要一个 Realm 的定义,而 Realm 应该指定用户和角色的数据库。但是,我没有使用基于容器的身份验证,也没有使用基于角色的授权,因此我不需要或不想配置领域。我想要的只是会话 cookie 能够在每个不同的子域之间共享。
有什么简单的方法可以做到这一点吗?
编辑
我当前的解决方法是让服务器将每个传入请求重定向到“规范”服务器名称。这很有效,但显然它并没有真正解决问题。
I'm trying to enable SSO under Tomcat such that users who go to http://mydomain.com and http://www.mydomain.com will have their session cookie available for requests made to http://subdomain.mydomain.com. All three of these domains go to the same webapp, so ideally I'd like to not mess with SSO at all and just set the domain on the standard JSESSIONID
cookie.
However, that doesn't seem possible, so I'm trying to enable Tomcat's SSO Valve. The problem is that the Valve requires a definition of a Realm, and a Realm is supposed to specify a database of users and roles. However, I am not using container-based authentication nor role-based authorization, so I do not need or want to configure a Realm. All I want is for the session cookie(s) to be able to be shared across each of these different subdomains.
Is there any straightforward way to do this?
Edit
My current workaround for this is to have the server redirect every incoming request to the "canonical" server name. This works well enough, but obviously it is not actually solving the problem.
发布评论
评论(1)
我们遇到了同样的问题,并创建了一个 Tomcat
Valve
来覆盖或设置会话Cookie
的域部分。这是一件非常简单的事情,而且已经有效很多年了。代码如下:算法的工作原理如下:
- 仅当会话是新的时 - 查找会话 cookie
- 获取请求的主机名
- 用“.”分割主机名
- 如果它至少有 3 个部分(例如 www.google.de),请删除第一部分(到 .google.de)
- 重置 cookie
在您的上下文配置中,您可以像这样应用 Valve
警告:在代码中,如果之前没有创建会话,则
Valve
会创建一个会话,并且根本不关心您是否需要会话。 ..希望有帮助...祝你好运!
We were having the same problem and created a Tomcat
Valve
that would overwrite or set the Domain part of the sessionCookie
. Quite a simple thing and it already works for many years. The code goes like this:The algorithm works like this:
- Only if the session is new - find the session cookie
- Get the requested host name
- Split the host name with '.'
- If it has at least 3 parts (like www.google.de), remove first part (to .google.de)
- Reset the cookie
In your Context configuration you can apply the valve like this
Caveat: In the code the
Valve
creates a session if no session was created before and does not care if you need a session at all...Hope that helps... Good luck!