Author: jleroux
Date: Fri Sep 24 22:45:12 2010
New Revision: 1001099

URL: http://svn.apache.org/viewvc?rev=1001099&view=rev
Log:
A patch from Weizhan Guo "multi-tenant function do not work correctly if switch 
from one app to another by click the menu" 
(https://issues.apache.org/jira/browse/OFBIZ-3956) - OFBIZ-3956

I found a problem when I switched from one app to another. The multi-tenant did 
not work if the username and password were the same in the main database and 
tenants (or different tenants). For example, the password of admin is ofbiz in 
main database and in DEMO1 tenant, first log in to catalog as admin of tenant 
DEMO1, and then switch to the content app, the data of content app is from the 
main database instead of DEMO1.

I debugged this problem, and the code was missing to check the userlogin tenant 
in checkExternalLoginKey.

Modified:
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java?rev=1001099&r1=1001098&r2=1001099&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java 
(original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java 
Fri Sep 24 22:45:12 2010
@@ -927,6 +927,17 @@ public class LoginWorker {
 
         GenericValue userLogin = (GenericValue) 
LoginWorker.externalLoginKeys.get(externalKey);
         if (userLogin != null) {
+            //to check it's the right tenant 
+            //in case username and password are the same in different tenants
+            LocalDispatcher dispatcher = (LocalDispatcher) 
request.getAttribute("dispatcher");
+            Delegator delegator = (Delegator) 
request.getAttribute("delegator");
+            String oldDelegatorName = delegator.getDelegatorName();
+            ServletContext servletContext = session.getServletContext();
+            if 
(!oldDelegatorName.equals(userLogin.getDelegator().getDelegatorName())) {
+                delegator = 
DelegatorFactory.getDelegator(userLogin.getDelegator().getDelegatorName());
+                dispatcher = 
ContextFilter.makeWebappDispatcher(servletContext, delegator);
+                setWebContextObjects(request, response, delegator, dispatcher);
+            }
             // found userLogin, do the external login...
 
             // if the user is already logged in and the login is different, 
logout the other user


Reply via email to