Author: jacopoc
Date: Thu Apr 24 05:33:11 2014
New Revision: 1589592

URL: http://svn.apache.org/r1589592
Log:
Applied fix from trunk for revision: 1589589 
===

Fixes for a bug reported by Pierre Smits in OFBIZ-4130 (and OFBIZ-5319): a 
tenant user can access, via the delegator, the meta data information of other 
tenants; for example a tenant user with grants to use the Webtools application 
could view/edit the database details of all tenants.



Modified:
    ofbiz/branches/release13.07/   (props changed)
    
ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    
ofbiz/branches/release13.07/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
    
ofbiz/branches/release13.07/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy

Propchange: ofbiz/branches/release13.07/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1589589

Modified: 
ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1589592&r1=1589591&r2=1589592&view=diff
==============================================================================
--- 
ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
 (original)
+++ 
ofbiz/branches/release13.07/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
 Thu Apr 24 05:33:11 2014
@@ -260,6 +260,12 @@ public class GenericDelegator implements
 
     private void initializeOneGenericHelper(String groupName) {
         GenericHelperInfo helperInfo = this.getGroupHelperInfo(groupName);
+        if (helperInfo == null) {
+            if (Debug.infoOn()) {
+                Debug.logInfo("Delegator \"" + delegatorFullName + "\" NOT 
initializing helper for entity group \"" + groupName + "\" because the group is 
not associated to this delegator.", module);
+            }
+            return;
+        }
         String helperBaseName = helperInfo.getHelperBaseName();
 
         if (Debug.infoOn()) {
@@ -462,9 +468,7 @@ public class GenericDelegator implements
         GenericHelperInfo helperInfo = new GenericHelperInfo(entityGroupName, 
helperBaseName);
 
         // to avoid infinite recursion, and to behave right for shared 
org.ofbiz.tenant entities, do nothing with the tenantId if the 
entityGroupName=org.ofbiz.tenant
-        if (UtilValidate.isNotEmpty(this.delegatorTenantId) && 
!"org.ofbiz.tenant".equals(entityGroupName)) {
-            helperInfo.setTenantId(this.delegatorTenantId);
-
+        if (UtilValidate.isNotEmpty(this.delegatorTenantId)) {
             // get the JDBC parameters from the DB for the entityGroupName and 
tenantId
             try {
                 // NOTE: instead of caching the GenericHelpInfo object do a 
cached query here and create a new object each time, will avoid issues when the 
database data changes during run time
@@ -472,15 +476,12 @@ public class GenericDelegator implements
                 Delegator baseDelegator = 
DelegatorFactory.getDelegator(this.delegatorBaseName);
                 GenericValue tenantDataSource = 
baseDelegator.findOne("TenantDataSource", true, "tenantId", 
this.delegatorTenantId, "entityGroupName", entityGroupName);
                 if (tenantDataSource != null) {
+                    helperInfo.setTenantId(this.delegatorTenantId);
                     
helperInfo.setOverrideJdbcUri(tenantDataSource.getString("jdbcUri"));
                     
helperInfo.setOverrideUsername(tenantDataSource.getString("jdbcUsername"));
                     
helperInfo.setOverridePassword(tenantDataSource.getString("jdbcPassword"));
                 } else {
-                    /* don't log this, happens too many times:
-                    if (Debug.warningOn()) {
-                        Debug.logWarning("Could not find TenantDataSource 
information for tenantId=[" + this.delegatorTenantId + "] and 
entityGroupName=[" + entityGroupName + "] in delegator [" + 
this.delegatorFullName + "]; will be defaulting to settings for the base 
delegator name [" + this.delegatorBaseName + "]", module);
-                    }
-                    */
+                    return null;
                 }
             } catch (GenericEntityException e) {
                 // don't complain about this too much, just log the error if 
there is one
@@ -521,7 +522,7 @@ public class GenericDelegator implements
         if (helperInfo != null) {
             return GenericHelperFactory.getHelper(helperInfo);
         } else {
-            throw new GenericEntityException("There is no datasource (Helper) 
configured for the entity-group [" + this.getEntityGroupName(entityName) + "]; 
was trying to find datesource (helper) for entity [" + entityName + "]");
+            throw new GenericEntityException("There is no datasource (Helper) 
configured for the entity-group [" + this.getEntityGroupName(entityName) + "]; 
was trying to find datasource (helper) for entity [" + entityName + "]");
         }
     }
 

Modified: 
ofbiz/branches/release13.07/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=1589592&r1=1589591&r2=1589592&view=diff
==============================================================================
--- 
ofbiz/branches/release13.07/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
 (original)
+++ 
ofbiz/branches/release13.07/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
 Thu Apr 24 05:33:11 2014
@@ -272,6 +272,12 @@ public class EntityDataLoadContainer imp
         String delegatorNameToUse = overrideDelegator != null ? 
overrideDelegator : delegatorName;
         String groupNameToUse = overrideGroup != null ? overrideGroup : 
entityGroupName;
         Delegator delegator = 
DelegatorFactory.getDelegator(delegatorNameToUse);
+        Delegator baseDelegator = null;
+        if (delegator.getDelegatorTenantId() != null) {
+            baseDelegator = 
DelegatorFactory.getDelegator(delegator.getDelegatorBaseName());
+        } else {
+            baseDelegator = delegator;
+        }
         if (delegator == null) {
             throw new ContainerException("Invalid delegator name!");
         }
@@ -294,11 +300,11 @@ public class EntityDataLoadContainer imp
         Collection<ComponentConfig> allComponents = 
ComponentConfig.getAllComponents();
         for (ComponentConfig config : allComponents) {
             //Debug.logInfo("- Stored component : " + 
config.getComponentName(), module);
-            GenericValue componentEntry = delegator.makeValue("Component");
+            GenericValue componentEntry = baseDelegator.makeValue("Component");
             componentEntry.set("componentName", config.getComponentName());
             componentEntry.set("rootLocation", config.getRootLocation());
             try {
-                GenericValue componentCheck = delegator.findOne("Component", 
UtilMisc.toMap("componentName", config.getComponentName()), false);
+                GenericValue componentCheck = 
baseDelegator.findOne("Component", UtilMisc.toMap("componentName", 
config.getComponentName()), false);
                 if (UtilValidate.isEmpty(componentCheck)) {
                     componentEntry.create();
                 } else {
@@ -315,7 +321,7 @@ public class EntityDataLoadContainer imp
                 List<EntityExpr> exprs = FastList.newInstance();
                 exprs.add(EntityCondition.makeCondition("rootLocation", 
EntityOperator.NOT_LIKE, "%hot-deploy%"));
                 EntityCondition cond = EntityCondition.makeCondition(exprs);
-                List<GenericValue> components = 
delegator.findList("Component", cond , null, 
UtilMisc.toList("lastUpdatedStamp"), null, false);
+                List<GenericValue> components = 
baseDelegator.findList("Component", cond , null, 
UtilMisc.toList("lastUpdatedStamp"), null, false);
                 Debug.logInfo("===== Begin load specify components", module);
                 if (UtilValidate.isEmpty(this.component)) {
                     for (GenericValue component : components) {
@@ -323,14 +329,14 @@ public class EntityDataLoadContainer imp
                         //Debug.logInfo("- loaded default component : " + 
component.getString("componentName"), module);
                     }
                     Debug.logInfo("- Loaded components by default : " + 
components.size() + " components", module);
-                    List<GenericValue> tenantComponents = 
delegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", 
delegator.getDelegatorTenantId()), UtilMisc.toList("sequenceNum"), false);
+                    List<GenericValue> tenantComponents = 
baseDelegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", 
delegator.getDelegatorTenantId()), UtilMisc.toList("sequenceNum"), false);
                     for (GenericValue tenantComponent : tenantComponents) {
                         
loadComponents.add(tenantComponent.getString("componentName"));
                         //Debug.logInfo("- loaded component by tenantId : " + 
tenantComponent.getString("tenantId") +", component : " + 
tenantComponent.getString("componentName"), module);
                     }
                     Debug.logInfo("- Loaded components by tenantId : " + 
delegator.getDelegatorTenantId() + ", " + tenantComponents.size() + " 
components", module);
                 } else {
-                    List<GenericValue> tenantComponents = 
delegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", 
delegator.getDelegatorTenantId(), "componentName", this.component),
+                    List<GenericValue> tenantComponents = 
baseDelegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", 
delegator.getDelegatorTenantId(), "componentName", this.component),
                             UtilMisc.toList("sequenceNum"), false);
                     for (GenericValue tenantComponent : tenantComponents) {
                         
loadComponents.add(tenantComponent.getString("componentName"));

Modified: 
ofbiz/branches/release13.07/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy?rev=1589592&r1=1589591&r2=1589592&view=diff
==============================================================================
--- 
ofbiz/branches/release13.07/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy
 (original)
+++ 
ofbiz/branches/release13.07/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy
 Thu Apr 24 05:33:11 2014
@@ -19,14 +19,24 @@
 import javolution.util.FastList;
 
 import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.Delegator
+import org.ofbiz.entity.DelegatorFactory
+import org.ofbiz.entity.GenericValue
+import org.ofbiz.entity.condition.EntityComparisonOperator
+import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.model.ModelGroupReader;
 import org.ofbiz.entity.model.ModelReader;
 import org.ofbiz.entity.model.ModelEntity;
-import org.ofbiz.entity.model.ModelViewEntity;
+import org.ofbiz.entity.model.ModelViewEntity
+import org.ofbiz.entity.util.EntityUtil;
 
-mgr = delegator.getModelGroupReader();
-entityGroups = mgr.getGroupNames(delegator.getDelegatorBaseName()).iterator();
+if (delegator.getDelegatorTenantId() == null) {
+    mgr = delegator.getModelGroupReader();
+    entityGroups = 
mgr.getGroupNames(delegator.getDelegatorName()).toArray().sort();
+} else {
+    Delegator baseDelegator = 
DelegatorFactory.getDelegator(delegator.getDelegatorBaseName());
+    entityGroups = 
EntityUtil.getFieldListFromEntityList(baseDelegator.findList("TenantDataSource",
 EntityCondition.makeCondition("tenantId", EntityComparisonOperator.EQUALS, 
delegator.getDelegatorTenantId()), ['entityGroupName'] as Set, 
['entityGroupName'], null, false), 'entityGroupName', false);
+}
 
 filterByGroupName = parameters.filterByGroupName;
 context.filterByGroupName = filterByGroupName;
@@ -42,14 +52,17 @@ int kIdx = 0;
 entitiesList = [];
 entities.each { entityName ->
     entity = reader.getModelEntity(entityName);
+    entityGroupName = delegator.getEntityGroupName(entity.getEntityName());
 
-    if (filterByGroupName && 
!filterByGroupName.equals(delegator.getEntityGroupName(entity.getEntityName())))
 {
+    if (!entityGroups.contains(entityGroupName)) {
+        return;
+    }
+    if (filterByGroupName && !filterByGroupName.equals(entityGroupName)) {
         return;
     }
     if (filterByEntityName && 
!((String)entity.getEntityName()).toUpperCase().contains(filterByEntityName.toUpperCase()))
 {
         return;
     }
-
     viewEntity = "N";
     if (entity instanceof ModelViewEntity) {
         viewEntity = "Y";


Reply via email to