Single active session for user

Hi, I have requirement to have only one session open for user. For example,

  1. user_one logged in from machine_1.
  2. Now user_one is trying to login from machine_2

Then on approval, session from machine_1 should get destroyed.

Now, we are capturing session ID every time one get created. And we have user id. But as per our understanding, we can only destroy current session/context for current thread.

We are not able to destroy session on Machine_1 as it is another thread. And OpenMRS is also not using spring security features.

Can any one please suggest, how to close session for user which is running in different thread?


Here is one example of how you could implement that functionality:


I trier this code snippet to help me realize that, but seem NOT working. Can you help me see where the problem is? @sagarbele did you manage making that work?

Did you figure this out?

No @dkayiwa this did NOT work for me

Maybe @saurabhverma can help crack this in reff app. I saw you have similar implementation in your application