Reputation: 353
I have one scenario where we need to maintain multiple sessions like we have for Google Accounts. User can add multiple accounts in different tabs and all of them will have its specific content. For example in Tab1 user1 is loggedin and in Tab2 user2 is logged in
We are using Angular in frontend and JAVA.
Thought of using localstorage in frontend which will have Array of users . And we will pass the current user in the URL For ex: In Tab1 it will the URL will be like http://localhost:8080/account/user1/ and in tab2 it will be http://localhost:8080/account/user2/
Now the problem is that HttpSession would be different in both cases, and in the code we have set some attributes in HttpSession. As per my understanding the ServletContainer will manage different sessions and they can be identified with sessionId. The problem which I see is the way to pass sessionId in request to Java so that my server code will have that session. For ex: if tab1 is opened then session related to user1 should be picked, and if tab2 is opened then session related to user2.
Upvotes: 0
Views: 801
Reputation: 8495
Use Spring Session API version 1.3.4.RELEASE - as explained in official documentation here.
Spring Session provides an API and implementations for managing a user’s session information.
Multiple Browser Sessions - Spring Session supports managing multiple users' sessions in a single browser instance (i.e. multiple authenticated accounts similar to Google).
Please note, this feature has been removed from version 2.1.2.RELEASE
11.4. Dropped Support
As a part of the changes to HttpSessionStrategy and it’s alignment to the counterpart from the reactive world, the support for managing multiple users' sessions in a single browser instance has been removed. The introduction of a new API to replace this functionality is under consideration for future releases.
Upvotes: 1