brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [2/5] git commit: filter the applicationresource children according to the entitlements
Date Mon, 30 Jun 2014 22:24:40 GMT
filter the applicationresource children according to the entitlements


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/82136c7a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/82136c7a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/82136c7a

Branch: refs/heads/master
Commit: 82136c7a951617be81fc57263dbe1cd35945ec0e
Parents: 8958fc1
Author: Andrea Turli <andrea.turli@gmail.com>
Authored: Mon Jun 30 18:58:32 2014 +0200
Committer: Andrea Turli <andrea.turli@gmail.com>
Committed: Mon Jun 30 18:58:32 2014 +0200

----------------------------------------------------------------------
 .../management/entitlement/Entitlements.java    | 10 ++++----
 .../rest/resources/ApplicationResource.java     | 26 +++++++++++++-------
 2 files changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/82136c7a/core/src/main/java/brooklyn/management/entitlement/Entitlements.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/entitlement/Entitlements.java b/core/src/main/java/brooklyn/management/entitlement/Entitlements.java
index 6e3fe71..667bb3b 100644
--- a/core/src/main/java/brooklyn/management/entitlement/Entitlements.java
+++ b/core/src/main/java/brooklyn/management/entitlement/Entitlements.java
@@ -18,6 +18,11 @@ package brooklyn.management.entitlement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Objects;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
 import brooklyn.config.BrooklynProperties;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
@@ -27,11 +32,6 @@ import brooklyn.util.ResourceUtils;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.text.Strings;
 
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.reflect.TypeToken;
-
 public class Entitlements {
 
     private static final Logger log = LoggerFactory.getLogger(Entitlements.class);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/82136c7a/usage/rest-server/src/main/java/brooklyn/rest/resources/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/ApplicationResource.java
b/usage/rest-server/src/main/java/brooklyn/rest/resources/ApplicationResource.java
index 95eefb8..68e8bcd 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/ApplicationResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/ApplicationResource.java
@@ -140,26 +140,32 @@ public class ApplicationResource extends AbstractBrooklynRestResource
implements
     private ArrayNode childEntitiesRecursiveAsArray(Entity entity) {
         ArrayNode node = mapper().createArrayNode();
         for (Entity e : entity.getChildren()) {
-            node.add(recursiveTreeFromEntity(e));
+            if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY,
entity)) {
+                node.add(recursiveTreeFromEntity(e));
+            }
         }
         return node;
     }
 
     private ArrayNode entitiesIdAndNameAsArray(Collection<? extends Entity> entities)
{
         ArrayNode node = mapper().createArrayNode();
-        for (Entity e : entities) {
-            ObjectNode holder = mapper().createObjectNode();
-            holder.put("id", e.getId());
-            holder.put("name", e.getDisplayName());
-            node.add(holder);
+        for (Entity entity : entities) {
+            if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY,
entity)) {
+                ObjectNode holder = mapper().createObjectNode();
+                holder.put("id", entity.getId());
+                holder.put("name", entity.getDisplayName());
+                node.add(holder);
+            }
         }
         return node;
     }
 
     private ArrayNode entitiesIdAsArray(Collection<? extends Entity> entities) {
         ArrayNode node = mapper().createArrayNode();
-        for (Entity e : entities) {
-            node.add(e.getId());
+        for (Entity entity : entities) {
+            if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY,
entity)) {
+                node.add(entity.getId());
+            }
         }
         return node;
     }
@@ -173,7 +179,9 @@ public class ApplicationResource extends AbstractBrooklynRestResource
implements
             for (String entityId: entityIds.split(",")) {
                 Entity entity = mgmt().getEntityManager().getEntity(entityId.trim());
                 while (entity != null && entity.getParent() != null) {
-                    jsonEntitiesById.put(entity.getId(), fromEntity(entity));
+                    if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY,
entity)) {
+                        jsonEntitiesById.put(entity.getId(), fromEntity(entity));
+                    }
                     entity = entity.getParent();
                 }
             }


Mime
View raw message