Search code examples
springtomcatspring-session

Configure Cookie Domain in spring session


So I already success implement SSO using spring session and redis on development localhost domain. But when I deploy to server using two sub domain.

login.example.com

apps.example.com

They always create new session Id on each sub domain. I already try to configure using Context in tomcat configuration.

<Context sessionCookieDomain=".example.com" sessionCookiePath="/">

But no luck.


Solution

  • Spring session moves the session management on application level, so no surprise that trying to configure the container (in your case tomcat) has no effect. Currently there is a TODO in spring-session code to allow setting the domain, but is not implemented.

    Maybe it is best to open an issue to allow setting the domain or comment/vote on https://github.com/spring-projects/spring-session/issues/112.

    Meanwhile a workaround would be to go with your own implementation of MultiHttpSessionStrategy based on CookieHttpSessionStrategy.