Newbie
Newbie

Reputation: 7249

How does Spring Session support multiple sessions within a single browser?

The Spring Session documentations describes as one of its usage benefits as written below.

Allowing for a single browser to have multiple simultaneous sessions in a transparent fashion. For example, many developers wish to allow a user to authenticate with multiple accounts and switch between them similar to how you can in gmail.

Technically, how does one leverage that benefit, how is it implemented?

Upvotes: 5

Views: 5610

Answers (1)

Rob Winch
Rob Winch

Reputation: 21720

As of Spring Session RC1, Spring Session will keep track of all the Sessions in a single cookie. Using a pattern like this:

0 defaultsession alias sessionid alias2 sessionid2

Then you can select which session you are actively using by ensuring that you have the query parameter of "_s" with the value of the alias. For example, requesting the URL /index?_s=alias2 would use sessionid2. If _s is undefined, then the session alias of 0 is used. This means /index would result in using default session. You can find this documented on CookieHttpSessionStrategy

For a working example, see the users sample.

Upvotes: 6

Related Questions