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.
We were having the same problem and created a Tomcat
Valvethat 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 http://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
Valvecreates a session if no session was created before and does not care if you need a session at all…Hope that helps… Good luck!