rafaelweingartner commented on a change in pull request #2350: Cloudstack 10170 
- fixes resource tags security bugs and adds account tags support
URL: https://github.com/apache/cloudstack/pull/2350#discussion_r154691457
 
 

 ##########
 File path: server/src/com/cloud/tags/TaggedResourceManagerImpl.java
 ##########
 @@ -276,83 +300,76 @@ public void 
doInTransactionWithoutResult(TransactionStatus status) {
         return resourceTags;
     }
 
-    @Override
-    public String getUuid(String resourceId, ResourceObjectType resourceType) {
-        if (!StringUtils.isNumeric(resourceId)) {
-            return resourceId;
-        }
-
-        Class<?> clazz = s_typeMap.get(resourceType);
-
-        Object entity = _entityMgr.findById(clazz, resourceId);
-        if (entity != null && entity instanceof Identity) {
-            return ((Identity)entity).getUuid();
-       }
-
-           return resourceId;
-       }
-
-    @Override
-    @DB
-    @ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = 
"deleting resource tags")
-    public boolean deleteTags(List<String> resourceIds, ResourceObjectType 
resourceType, Map<String, String> tags) {
-        Account caller = CallContext.current().getCallingAccount();
-
+    private List<? extends ResourceTag> searchResourceTags(List<String> 
resourceIds, ResourceObjectType resourceType) {
         SearchBuilder<ResourceTagVO> sb = 
_resourceTagDao.createSearchBuilder();
-        sb.and().op("resourceId", sb.entity().getResourceId(), 
SearchCriteria.Op.IN);
-        sb.or("resourceUuid", sb.entity().getResourceUuid(), 
SearchCriteria.Op.IN);
-        sb.cp();
+        sb.and("resourceUuid", sb.entity().getResourceUuid(), 
SearchCriteria.Op.IN);
         sb.and("resourceType", sb.entity().getResourceType(), 
SearchCriteria.Op.EQ);
 
         SearchCriteria<ResourceTagVO> sc = sb.create();
-        sc.setParameters("resourceId", resourceIds.toArray());
         sc.setParameters("resourceUuid", resourceIds.toArray());
         sc.setParameters("resourceType", resourceType);
+        return _resourceTagDao.search(sc, null);
+    }
 
-        List<? extends ResourceTag> resourceTags = _resourceTagDao.search(sc, 
null);
-        ;
-        final List<ResourceTag> tagsToRemove = new ArrayList<ResourceTag>();
+    @Override
+    @DB
+    @ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = 
"deleting resource tags")
+    public boolean deleteTags(List<String> resourceIds, ResourceObjectType 
resourceType, Map<String, String> tags) {
+        Account caller = CallContext.current().getCallingAccount();
+        if(s_logger.isDebugEnabled()) {
+            s_logger.debug("ResourceIds to Find " + String.join(", ", 
resourceIds));
+        }
+        List<? extends ResourceTag> resourceTags = 
searchResourceTags(resourceIds, resourceType);
+        final List<ResourceTag> tagsToDelete = new ArrayList<>();
 
         // Finalize which tags should be removed
         for (ResourceTag resourceTag : resourceTags) {
             //1) validate the permissions
+            if(s_logger.isDebugEnabled()) {
+                s_logger.debug("Resource Tag Id: " + 
resourceTag.getResourceId());
+                s_logger.debug("Resource Tag AccountId: " + 
resourceTag.getAccountId());
+            }
             Account owner = _accountMgr.getAccount(resourceTag.getAccountId());
+            if(s_logger.isDebugEnabled()) {
+                s_logger.debug("Resource Owner: " + owner);
+            }
             _accountMgr.checkAccess(caller, null, false, owner);
             //2) Only remove tag if it matches key value pairs
             if (tags != null && !tags.isEmpty()) {
                 for (String key : tags.keySet()) {
-                    boolean canBeRemoved = false;
+                    boolean deleteTag = false;
                     if (resourceTag.getKey().equalsIgnoreCase(key)) {
                         String value = tags.get(key);
                         if (value != null) {
 
 Review comment:
   No problem, it is ok the way it is ;)
   
   When I mentioned I also was in doubt, because of the data that we are 
dealing with (it is not obvious what we are dealing with). 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to