[Yanel-commits] rev 48944 - public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager

michi at wyona.com michi at wyona.com
Wed Apr 21 13:48:23 CEST 2010


Author: michi
Date: 2010-04-21 13:48:23 +0200 (Wed, 21 Apr 2010)
New Revision: 48944

Modified:
   public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java
Log:
get aggregated policy implementation started

Modified: public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java	2010-04-21 11:47:44 UTC (rev 48943)
+++ public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java	2010-04-21 11:48:23 UTC (rev 48944)
@@ -119,8 +119,13 @@
                 }
 
                 if (viewId != null && viewId.equals("get-xml")) {
-                    log.warn("DEBUG: Get XML version of policy ...");
-                    sb.append(getPoliciesAsXML(getPath(), null, orderedBy, showParents));
+                    if (getEnvironment().getRequest().getParameter("aggregate") != null && getEnvironment().getRequest().getParameter("aggregate").equals("true")) {
+                        log.warn("DEBUG: Get XML version of aggregated policy ...");
+                        sb.append(getAggregatedPolicyAsXML(getPath(), null, orderedBy, showParents));
+                    } else {
+                        log.warn("DEBUG: Get XML version of policy ...");
+                        sb.append(getPoliciesAsXML(getPath(), null, orderedBy, showParents));
+                    }
                 } else {
                     log.warn("DEBUG: Get XHTML version of policy ...");
                     sb.append(PolicyViewer.getXHTMLView(getRealm().getPolicyManager(), getRealm().getIdentityManager().getGroupManager(), getPath(), null, orderedBy, showParents, showTabs, showAbbreviatedLabels));
@@ -512,4 +517,53 @@
         sb.append("</policy-viewer>");
         return sb;
     }
+
+    /**
+     * Get aggregated policy as XML
+     *
+     * @param path Content path which is associated with an access policy
+     * @param contentItemId Content Item ID which allows a unique association with an access policy and an item within the content
+     * @param orderedBy Allows ordering by usecases or identities
+     * @param showParents Show the policies of the parent nodes, which allows to figure out how the policy has been aggregated
+     */
+    private StringBuilder getAggregatedPolicyAsXML(String path, String contentItemId, int orderedBy, boolean showParents) throws Exception {
+        log.warn("DEBUG: Get policies for path: " + path);
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("<?xml version=\"1.0\"?><policy-viewer xmlns=\"http://www.wyona.org/security/1.0\">");
+
+        sb.append("<usecases><usecase id=\"r\">Read</usecase><usecase id=\"w\">Write</usecase></usecases>");
+
+        sb.append("<policies>");
+
+            boolean aggregate = true;
+            Policy p = getRealm().getPolicyManager().getPolicy(path, aggregate);
+
+            if (p != null) {
+                sb.append("<node name=\"" + path + "\">");
+                sb.append("<policy use-inherited-policies=\"" + p.useInheritedPolicies() + "\">");
+                UsecasePolicy[] up = p.getUsecasePolicies();
+                for (int k = 0; k < up.length; k++) {
+                    sb.append("<usecase id=\"" + up[k].getName() + "\">");
+                    // TODO: Use ItemPolicy and cast check in order to get the right order
+                    IdentityPolicy[] ip = up[k].getIdentityPolicies();
+                    for (int j = 0; j < ip.length; j++) {
+                        sb.append("<user id=\"" + ip[j].getId() + "\" permission=\"" + ip[j].getPermission() + "\" naz-blocked=\"true\" naz-permission-unlike-group=\"true\"/>"); // TODO: naz ...
+                    }
+                    GroupPolicy[] gp = up[k].getGroupPolicies();
+                    for (int j = 0; j < gp.length; j++) {
+                        sb.append("<group id=\"" + gp[j].getId() + "\" permission=\"" + gp[j].getPermission() + "\" naz-permission-unlike-members=\"true\"/>"); // TODO: naz ...
+                    }
+                    sb.append("</usecase>");
+                }
+                sb.append("</policy>");
+                sb.append("</node>");
+            } else {
+                sb.append("<node name=\"" + path + "\"/>");
+            }
+
+        sb.append("</policies>");
+        sb.append("</policy-viewer>");
+        return sb;
+    }
 }



More information about the Yanel-commits mailing list