Eli Mesika has uploaded a new change for review.

Change subject: core: fix e8993e1ca33b823852e15b4adeb3df293afb5676
......................................................................

core: fix e8993e1ca33b823852e15b4adeb3df293afb5676

The problems in the $Subject patch were

1) It assumes that all the fields returned from the query are returned
from the search engine as well which is not true since some entity
collections are filled when the query is used and omitted while the
search engine is used which leads to an empty intersection

2) Some columns may not return as a result of security filtering.

This patch fixes the intersection logic such that instead of making a
full intersection on the whole entity fields, only entity IDs are used.

In order to do that we need to
1. Get the filter query result (filterList)  and search query result
(searchList)

2. Create new ID only lists

3. Intersect between the ID lists and get the result

4. Remove from the filterList (that has all security constrains applied) all 
entries that did not match the IDs appears in 3

Change-Id: I23ef5740ea59069b10afc329e5ef75bce3c33b31
Signed-off-by: emesika <[email protected]>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java
1 file changed, 29 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/57/38757/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java
index 80da17d..ae46767 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java
@@ -3,6 +3,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
@@ -21,6 +23,7 @@
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
+import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.interfaces.SearchType;
 import org.ovirt.engine.core.common.queries.SearchParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
@@ -127,13 +130,38 @@
         // check if we got search expression in the URI
         if (QueryHelper.hasConstraint(getUriInfo(), 
QueryHelper.CONSTRAINT_PARAMETER)) {
             List<Q> searchList = getBackendCollection(searchType);
-            return (List<Q>) CollectionUtils.intersection(filteredList, 
searchList);
+            return intersect(filteredList, searchList);
         }
         else {
             return filteredList;
         }
     }
 
+    /**
+     * Intersects the list resulted from the query with the list resulted from 
the search engine
+     * in order to get the search applied while preserving all security 
constrains on the resulted
+     * rows and columns
+     * @param list1
+     * @param list2
+     * @return
+     */
+    private List<Q> intersect(List<Q> list1, List<Q> list2) {
+        Collection<Guid> listId1 = new ArrayList<>();
+        Collection<Guid> listId2 = new ArrayList<>();
+        for (Q be : list1) {
+            listId1.add((Guid)((BusinessEntity)be).getId());
+        }
+        for (Q be : list2) {
+            listId2.add((Guid)((BusinessEntity)be).getId());
+        }
+        Collection<Guid> result = CollectionUtils.intersection(listId1, 
listId2);
+        for (Q be : list1) {
+            if (! result.contains(((BusinessEntity)be).getId()))
+            list1.remove(be);
+        }
+        return list1;
+    }
+
     protected final <T> Response performCreate(VdcActionType task,
             VdcActionParametersBase taskParams,
             IResolver<T, Q> entityResolver,


-- 
To view, visit https://gerrit.ovirt.org/38757
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23ef5740ea59069b10afc329e5ef75bce3c33b31
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to