Restricting multiple sessions in IE7


This blog helps you by providing some thoughts on how to manage HTTP session and restrict multiple users logging into your web application using IE 7 browser tab features. Let me brief little bit about the background of the problem and few possible solutions.

Lets assume your web application is currently able to restrict same user logging in multiple times from a particular machine using IE 6 like browser. This means that if user1 has logged in IE6 browser 1, then user1 will not be able to login in IE6 browser2. In this scenario, browser1 HTTP session is different from browser2 session and we will be easily able to restrict the user1.

Our goal is to restrict the user1 logging in multiple times in browser like IE 7 which provides tab features (multiple tabs in same browser). IE7 Browser shares the same session across tabs and this would be our key to restrict user as follows.

Step1: Get all active sessions from your singleton class

MySingleton  mysin= MySingleton.getSessions();   which returns hashmap of all your current sessions. userid is the key and the session as the value.

Step2: loop through all your sessions and compare the current session with the list.

Enumeration e1 = sing.keys();

while (e1.hasMoreElements())

{

String enumUser = (String) e1.nextElement();

HttpSession enumSess = (HttpSession)sing.get(enumUser );

if(enumSess == session)

{

//Matching session found which means that another user is alreading using this browser to your web application

//Keep count of sessions

count++;

session.setAttribute(”mycount”,count);

}

//somewhere down the line, your logic to block the user if count>1

,

  1. #1 by math games on February 10, 2011 - 9:34 am

    thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: