From 7bef9a961d968e4187d1bf843404b29992c21a67 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Mon, 23 Jul 2012 10:50:21 -0700 Subject: [PATCH] Resource tags: CS-15661 - don't accept NULL or empty key value when create resource tag --- api/src/com/cloud/api/commands/CreateTagsCmd.java | 1 + .../com/cloud/tags/TaggedResourceManagerImpl.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreateTagsCmd.java b/api/src/com/cloud/api/commands/CreateTagsCmd.java index f87ae6e96d8..a981363cc89 100644 --- a/api/src/com/cloud/api/commands/CreateTagsCmd.java +++ b/api/src/com/cloud/api/commands/CreateTagsCmd.java @@ -33,6 +33,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ResourceTag; import com.cloud.server.ResourceTag.TaggedResourceType; diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java index f79eba4a17f..84a26924a71 100644 --- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java +++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java @@ -233,7 +233,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager Transaction txn = Transaction.currentTxn(); txn.start(); - for (String tag : tags.keySet()) { + for (String key : tags.keySet()) { for (String resourceId : resourceIds) { Long id = getResourceId(resourceId, resourceType); String resourceUuid = getUuid(resourceId, resourceType); @@ -254,10 +254,16 @@ public class TaggedResourceManagerImpl implements TaggedResourceService, Manager _accountMgr.checkAccess(caller, _domainMgr.getDomain(domainId)); } else { throw new PermissionDeniedException("Account " + caller + " doesn't have permissions to create tags" + - " for resource " + tag); + " for resource " + key); + } + + String value = tags.get(key); + + if (value == null || value.isEmpty()) { + throw new InvalidParameterValueException("Value for the key " + key + " is either null or empty"); } - ResourceTagVO resourceTag = new ResourceTagVO(tag, tags.get(tag), accountDomainPair.first(), + ResourceTagVO resourceTag = new ResourceTagVO(key, value, accountDomainPair.first(), accountDomainPair.second(), id, resourceType, customer, resourceUuid); resourceTag = _resourceTagDao.persist(resourceTag);