Cannot use the same cookie for multiple GWT applications

I am developing a network of applications where I want to offer my users several applications, and only they should register / register at the same time and use all applications with the same name.

To achieve this, I created a cookie in which I store the user session identifier (which it receives at login). Each time the user opens the application, the launching module tries to find the cookie and sends a request to the server to check if this session is valid.

When I tested this on my local machine for developers, everything worked fine, but on my test server with preliminary testing the cookie that I created in one application was not found by another application.

My test server is Tomcat 7. Applications deployed via .war-upload

Cookies are initially created with this command: Cookies.setCookie("WebsiteName", result.getSessionId());

Every help is appreciated!

Change 1

I worked a bit to make everything work the way I wanted it to.

Initially, I did not implement an HttpServlet session, but my own session management system, which stored my own session identifier in a cookie. Checking the server logs, I found out that if both applications are deployed under a subpath, the session exit for application 1 is as follows:

Test HttpSession ID: 34446C7F3F345F74A0AAB5E292A47021 | Own Session ID: 3a25884692c499d5e72f07bb2b214a40f63f5a4a842852c58f30e1b46cf7bee7bc8a3394a9fe83a04ac4e1dcb4069dbca95a8f0001e012bc643934e08af35ec2 

And for application 2

Test HttpSession ID: 429388DE8F0F76F877B077433FE16B66 | Own Session ID: 4e6b19a7621893de0cd0826b298ea4d8eb5ffecf4a7503f3274f729c2df28f4a1e9ce52179730b4139804f256591149fd712be76ad3afd87bade4f58aab4234f

, Tomcat -, .war-File ROOT.war . ROOT:

Test HttpSession ID: B9F2D14A716C3A06E328F58ED0995D95 | Own Session ID: 039b1c0cd2726dcfa1d8585da589e05984cfb6c971e083423d8456673837ea954ead42728aecf93be358ed13c757e3848ee3eb061a2253350c7d6dc1a14c970c

root/webapp1/:

Test HttpSession ID: BFD836C297B1BF8204D243387401CCA7 | Own Session ID: 039b1c0cd2726dcfa1d8585da589e05984cfb6c971e083423d8456673837ea954ead42728aecf93be358ed13c757e3848ee3eb061a2253350c7d6dc1a14c970c

cookie . , cookie .

Cookie, , , : -)

+1
1

? (firebug?)?. .

, , , .

1:

 void createSession(String Username) 
 {
    getThreadLocalRequest().getSession().setAttribute("Username", Username);
 }

2: cookie

String sessionID = /*(Get sessionID from server response to your login request.)*/;
final long DURATION = 1000 * 60 * 60 * 24 * 14; 
Date expires = new Date(System.currentTimeMillis() + DURATION);
Cookies.setCookie("sessionId", sessionID, expires, null, "/", false);

3. cookie .

boolean sessionAndUserValidFlag = false;
String sessionID = Cookies.getCookie("sessionId");
if ( sessionID != null )
{
   sessionAndUserValidFlag = validateSession(sessionID);
}
if (sessionAndUserValidFlag)
{
   //Continue login
}
else
{
  //Display Login Popup
}

validateSession :

public boolean validateSession(String sessionId)
{
    if (getThreadLocalRequest().getSession().getId.equals(sessionId))
    {
       if ( getThreadLocalRequest().getSession().getAttribute("UserName") != null )
       {
             return true;
       }
    }
    return false;
}
+2

All Articles