[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Concurrent HTTP Session is returning wrong user

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
SolutionsTI
Asked:
SolutionsTI
  • 2
1 Solution
 
krakatoaCommented:
And is it the same weird problem that you posted over on Stackoverflow?
0
 
SolutionsTIAuthor Commented:
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
 
SolutionsTIAuthor Commented:
I have found the solution on another site. The solution has been shared on Experts-Exchange.

Thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now