Solved

Concurrent HTTP Session is returning wrong user

Posted on 2013-05-14
3
409 Views
Last Modified: 2013-05-26
I am experiencing a quite weird problem. When two users are logging at the exact same time, one of them is detected as the other.


        locale = new Locale(getLocale(request).getLanguage(), getLocale(request).getCountry());
        
	
        strRemoteUser = WebTools.getUserIdWithoutDomainName(request.getRemoteUser()).toUpperCase();
    	
    	logger.info("[MYAPP] User " + strRemoteUser + " is logging in");

    	logger.info("[MYAPP] Creating session for : " + strRemoteUser);
    	
        HttpSession session = request.getSession(false);

        if (session != null) {
		
            session.invalidate();
            session = request.getSession();
        }       

        logger.info("[MYAPP] User in session is : " + strRemoteUser);    	      

Open in new window

         
What I get is the following. Let's assume that two users (USR001 and USR002) are logging to the application at the same exact time. They are located in a different location.

Logs:

		2013-05-14 08:19:38,550 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User USR001 is logging in
	2013-05-14 08:19:38,551 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Creating session for : USR001
	2013-05-14 08:19:38,760 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User USR002 is logging in
	2013-05-14 08:19:38,761 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Creating session for : USR002
	2013-05-14 08:19:38,834 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User in session is : USR002
	2013-05-14 08:19:39,104 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User in session is : USR002
	2013-05-14 08:19:39,425 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Auto Added User USR002
	2013-05-14 08:19:39,550 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Setting user in session: USR002 (673)

Open in new window


As you can see, USR002 "wins" the concurrent session creation as USR001 is now recognized as USR002. If USR001 logs out and then log back in, it works properly.

Any thoughts/advice?

Thank you very much for help.

Specs:

* jBoss 4.2.3GA
* PostgreSQL 9.0.3
* Struts 1.3.5
* EJB3
0
Comment
Question by:SolutionsTI
  • 2
3 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 39165795
And is it the same weird problem that you posted over on Stackoverflow?
0
 

Accepted Solution

by:
SolutionsTI earned 0 total points
ID: 39184035
Yes. Same problem.

The problem was in fact that the strRemoteUser was defined as a Class Variable for my LoginAction Struts action class.

This action is used by any user attempting to log in to the system. One gentleman on stackoverflow told my that Class Variables are common concurrent problem so I gave it a try.

Instead of a class variable I kept the strRemoteUser as a variable, and then pass it to all methods where I needed it.

It worked! The day after I had more than 80 people login in at the same time. The problem is now solved permanently.

Thank you
0
 

Author Closing Comment

by:SolutionsTI
ID: 39197417
I have found the solution on another site. The solution has been shared on Experts-Exchange.

Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 74
simple java question 3 44
HSSFWorkbook cannot be resolved error 10 49
Windows 10 and JDK 7 7u85 4 31
Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now