Hello,
I had to implement this myself in 6.0.6 . I suppose the same could be achieved in 6.1, though I haven't tried it yet.
I created a hook to provide this functionality.
The hook targeted the
login.events.post property in
portal.propertiesI created an implementation of com.liferay.portal.kernel.events.Action (i.e. I extended it). I assigned this new class to the aforementioned property. The idea is that I have a post login event that will do the job after a user logins. If the user that has just logged in is found to be already logged in, then I should implement the desired behavior.
Now assuming that the desired behavior is to log out the user that is already logged in, or in more precise words, invalidate the session with which the same user has already been logged in, I must find a way to fetch its session.
Since I didn't know of anything already implemented (like a Liferay util that might provided that), and for a good reason if u ask me, I had to do all this session management myself. i.e, be responsible to 'store' the session when a user logs in. Then I could do whatever I wanted with it if it was needed, and in this case (simultaneous logins) it is.
In order to manage the sessions I made use of the HttpSessionBindingListener interface. It provides methods for manipulating the session at creation and destruction. I used mappings to keep such info as servlet context attributes.
The only pitfall here is that this implementation is based on Servlet Context storage thus it is effective as long as sessions are not persisted between server restarts. This is something you can control though. Depending on your app server, you can define whether you want sessions to be persisted between server restarts. For example in tomcat, at
tomcat-xxx/conf/context.xml there's a configuration in comments which says
1<!-- Uncomment this to disable session persistence across Tomcat restarts -->
2 <!--
3 <Manager pathname="" />
4 -->
I hope I helped
Please sign in to flag this as inappropriate.