Results 1 to 6 of 6

Thread: How to prohibit concurrent user logins?

  1. #1
    Join Date
    Jan 2005
    Posts
    3

    Default How to prohibit concurrent user logins?

    I'm trying to implement a login system that only allows a user to have a single session running at any one time. What I mean by this is:

    1. user X logs in successfully into session 1

    2. From another machine or browser the same user X logs in successfully into a separate session 2. This should cause session 1 to become invalidated/logged out.

    Is it possible to do this in Acegi? Any assistance would be appreciated.

    Cheers
    Matt

  2. #2

    Default

    One way to do it, not through Ageci, is to create a map with a key of username and a value of session id. Then when someone logs in, you check the map to see if the username is already logged in and if they are invalidate the old session. Of course, you will have to manually manage this map, which means removing the entry if they log out or their session times out, but you can use a SessionListener for the whole thing.

    --Rexxe

  3. #3
    Join Date
    Jan 2005
    Posts
    3

    Default

    Thanks Rexxe,

    I've had a look at the SessionListener and I think I need to also use the an ApplicationListener to capture logon events. I think I need both because the SessionListener captures sessionCreate events (which happen before logon and therefore are not interesting to me) and sessionDestroy events (which I need to check and remove the user from my map). The applicationListener captures the logon event which I can then check to see if the user is already logged on and if so invalidate their first session.

    My problem now is how to I invalidate a session given the session id.

    Cheers
    Matt

  4. #4

    Default

    Last edited by robyn; May 19th, 2006 at 05:29 AM.

  5. #5
    Join Date
    Jan 2005
    Posts
    3

    Default

    Thanks Rexxe, I've managed to get the functionality working but I have a couple of issues I need to iron out.

    Firstly I had to store the username/HTTPSession in the map rather than the username/sessionId as I couldn't figure out a way to get a handle on the HTTPSession given a session id. This works and I can invalidate the session but I would rather just store the session id.

    And secondly, do you know how listeners work in clustered environments. ie I have my web app running on 2 servers in load sharing mode. A user X logs into server A and gets a logged in session. User X then attempts to login via server B, this will cause an event to be published from server B. My question is will server A pick up this event, as I now need my listener on server A to catch this event and invalidate the session of User X on server A.

    Cheers
    Matt

  6. #6

    Default

    I have never used them in clustered environments, but they should work since the session is replicated. You should look at: http://java.sun.com/products/servlet...gListener.html

    Also, are you using Tomcat? If you are, the session information can be shared between the two app servers using a database, which is configurable in the Tomcat config files. See http://jakarta.apache.org/tomcat/tom...ter-howto.html

    --Rexxe

Similar Threads

  1. Problem with HibernateInterceptor
    By prane in forum Data
    Replies: 5
    Last Post: Oct 16th, 2007, 08:01 AM
  2. LDAPPasswordAuthenticationDao problem
    By benoit_m35 in forum Security
    Replies: 15
    Last Post: Jan 11th, 2006, 07:04 AM
  3. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  4. Replies: 4
    Last Post: Jul 23rd, 2005, 05:54 AM
  5. Concurrent Logins -- Is it in 0.8x?
    By eisenb in forum Security
    Replies: 31
    Last Post: Jun 24th, 2005, 11:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •