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

michi at wyona.com michi at wyona.com
Thu Apr 3 22:59:06 CEST 2008


Author: michi
Date: 2008-04-03 22:59:06 +0200 (Thu, 03 Apr 2008)
New Revision: 34799

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/PolicyViewer.java
Log:
dismantling of groups implemented

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	2008-04-03 19:52:02 UTC (rev 34798)
+++ public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java	2008-04-03 20:59:06 UTC (rev 34799)
@@ -46,8 +46,6 @@
             policyUsecase = request.getParameter(PARAMETER_USECASE);
         }
         
-        Resource resToEditPolicy = getYanel().getResourceManager().getResource(getEnvironment(), getRealm(), policyPath);
-        
         String backToRealm = org.wyona.yanel.core.util.PathUtil.backToRealm(getPath());
         StringBuffer sb = new StringBuffer("");
         try {
@@ -67,17 +65,17 @@
                 String showTabsParam = request.getParameter("showTabs");
                 if (showTabsParam != null) showTabs = new java.lang.Boolean(showTabsParam).booleanValue();
 
-                sb.append(PolicyViewer.getXHTMLView(resToEditPolicy.getRealm().getPolicyManager(), resToEditPolicy.getPath(), null, orderedBy, showParents, showTabs));
+                sb.append(PolicyViewer.getXHTMLView(getRealm().getPolicyManager(), getRealm().getIdentityManager().getGroupManager(), getPath(), null, orderedBy, showParents, showTabs));
         } else if (policyUsecase.equals("update")) {
                 String getXML = request.getParameter("get");
                 String postXML = request.getParameter("post");
                 if (getXML != null && getXML.equals("identities")) {
-                    sb.append(getIdentitiesAndRightsAsXML(resToEditPolicy.getRealm().getIdentityManager(), resToEditPolicy.getRealm().getPolicyManager(), getRequestedLanguage()));
+                    sb.append(getIdentitiesAndRightsAsXML(getRealm().getIdentityManager(), getRealm().getPolicyManager(), getRequestedLanguage()));
                 } else if (getXML != null && getXML.equals("policy")) {
-                    sb.append(getPolicyAsXML(resToEditPolicy.getRealm().getPolicyManager(), resToEditPolicy.getPath()));
+                    sb.append(getPolicyAsXML(getRealm().getPolicyManager(), getPath()));
                 } else if (postXML != null && postXML.equals("policy")) {
                     try {
-                        writePolicy(request.getInputStream(), resToEditPolicy.getRealm().getPolicyManager(), resToEditPolicy.getPath());
+                        writePolicy(request.getInputStream(), getRealm().getPolicyManager(), getPath());
                         sb.append("<?xml version=\"1.0\"?><saved/>");
                     } catch(Exception e) {
                         log.error(e,e);
@@ -85,10 +83,10 @@
                     }
                 } else {
                     String identitiesURL = "../.." + getPath() + "?policy-path=" + policyPath + "&amp;yanel.policy=update&amp;get=identities";
-                    //String saveURL = "../.." + resToEditPolicy.getPath() + "?yanel.policy=update&post=policy";
+                    //String saveURL = "../.." + getPath() + "?yanel.policy=update&post=policy";
                     String saveURL = "?policy-path=" + policyPath + "&amp;yanel.policy=update&amp;post=policy";
-                    String cancelURL = org.wyona.commons.io.PathUtil.getName(resToEditPolicy.getPath());
-                    if (resToEditPolicy.getPath().endsWith("/")) cancelURL = "./";
+                    String cancelURL = org.wyona.commons.io.PathUtil.getName(getPath());
+                    if (getPath().endsWith("/")) cancelURL = "./";
 
                     sb.append("<?xml version=\"1.0\"?>");
                     sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");

Modified: public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyViewer.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyViewer.java	2008-04-03 19:52:02 UTC (rev 34798)
+++ public/yanel/trunk/src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyViewer.java	2008-04-03 20:59:06 UTC (rev 34799)
@@ -4,6 +4,7 @@
 import org.wyona.security.core.GroupPolicy;
 import org.wyona.security.core.IdentityPolicy;
 import org.wyona.security.core.UsecasePolicy;
+import org.wyona.security.core.api.GroupManager;
 import org.wyona.security.core.api.Identity;
 import org.wyona.security.core.api.Policy;
 import org.wyona.security.core.api.PolicyManager;
@@ -31,7 +32,7 @@
      * @param showParents Show the policies of the parent nodes, which allows to figure out how the policy has been aggregated
      * @param showTabs Show the tabs which allow to switch between parent policies and node policy
      */
-    static public String getXHTMLView (PolicyManager pm, String path, String contentItemId, int orderedBy, boolean showParents, boolean showTabs) {
+    static public String getXHTMLView (PolicyManager pm, GroupManager gm, String path, String contentItemId, int orderedBy, boolean showParents, boolean showTabs) {
         try {
             StringBuffer sb = new StringBuffer("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
             sb.append("<head>");
@@ -43,28 +44,29 @@
 	    if(showParents) {
                 // Show also all parent policies
                 if (showTabs) {
-                    sb.append("<p><a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=false\">Tab: Node Policy</a> | Tab: Parent Policies</p>");
+                    sb.append("<p><a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=false\">Node Policy</a> | Parent Policies</p>");
                 }
 
                 sb.append("<p>Access Policies for Path (and its parents) <i>" + path);
                 if (contentItemId != null) sb.append("#" + contentItemId);
                 sb.append("</i>:</p>");
-                sb.append("<p>(Policy Repository: "+pm.getPoliciesRepository().getName()+", "+pm.getPoliciesRepository().getConfigFile()+")</p>");
 
+                //sb.append("<p>(Policy Repository: "+pm.getPoliciesRepository().getName()+", "+pm.getPoliciesRepository().getConfigFile()+")</p>");
+
                 sb.append(getOrderByLink(orderedBy, showParents, showTabs));
                 sb.append("<p><table border=\"1\">");
                 sb.append("<tr><td>Path</td>" + getSplittedPath(pm, path, contentItemId) + "</tr>");
 
                 boolean aggregate = false;
-                sb.append("<tr valign=\"top\"><td>Policy</td>" + getPolicies(pm, path, contentItemId, aggregate, orderedBy) + "</tr>");
+                sb.append("<tr valign=\"top\"><td>Policy</td>" + getPolicies(pm, gm, path, contentItemId, aggregate, orderedBy) + "</tr>");
 
                 aggregate = true;
-                sb.append("<tr valign=\"top\"><td>Aggregated Policy</td>" + getPolicies(pm, path, contentItemId, aggregate, orderedBy) + "</tr>");
+                sb.append("<tr valign=\"top\"><td>Aggregated Policy</td>" + getPolicies(pm, gm, path, contentItemId, aggregate, orderedBy) + "</tr>");
                 sb.append("</table></p>");
             } else {
                 // Show policy of this node only
                 if (showTabs) {
-                    sb.append("<p>Tab: Node Policy | <a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=true\">Tab: Parent Policies</a></p>");
+                    sb.append("<p>Node Policy | <a href=\"?yanel.policy=read&amp;orderedBy=" + orderedBy + "&amp;showParents=true\">Parent Policies</a></p>");
                 }
 
                 sb.append("<div id=\"path-sentence\"><p>Aggregated Access Policy for Path <i>" + path);
@@ -75,7 +77,7 @@
                 boolean aggregate = true;
                 Policy p = pm.getPolicy(path, aggregate);
                 sb.append("<p><table border=\"1\"><tr>");
-		sb.append(getPolicy(p, aggregate, orderedBy, null));
+		sb.append(getPolicy(p, aggregate, orderedBy, null, gm));
                 if (contentItemId != null) {
                     sb.append("<td>contentItemId (" + contentItemId + ") not implemented yet into API!</td>");
                 }
@@ -92,7 +94,7 @@
     /**
      * Get splitted path
      */
-    static public StringBuffer getSplittedPath (PolicyManager pm, String path, String contentItemId) {
+    static private StringBuffer getSplittedPath (PolicyManager pm, String path, String contentItemId) {
         String[] names = path.split("/");
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < names.length -1; i++) {
@@ -123,7 +125,7 @@
      * @param aggregate If aggregate true, then the policy will be aggregated/merged with existing parent policies, otherwise only the node specific policy will be returned
      * @param orderedBy Ordered by identities or usecases
      */
-    static public StringBuffer getPolicies(PolicyManager pm, String path, String contentItemId, boolean aggregate, int orderedBy) throws AuthorizationException {
+    static private StringBuffer getPolicies(PolicyManager pm, GroupManager groupManager, String path, String contentItemId, boolean aggregate, int orderedBy) throws AuthorizationException {
 
         String[] names = path.split("/");
         StringBuffer sb = new StringBuffer();
@@ -153,12 +155,12 @@
             //log.debug("Back path: " + i + ", " + names[i] + ", " + back);
 
 
-            sb.append(getPolicy(p, aggregate, orderedBy, back));
+            sb.append(getPolicy(p, aggregate, orderedBy, back, groupManager));
         }
 
         // Show policy of the actual node
         Policy p = pm.getPolicy(path, aggregate);
-        sb.append(getPolicy(p, aggregate, orderedBy, null));
+        sb.append(getPolicy(p, aggregate, orderedBy, null, groupManager));
 
         // Show policy according to content id
         if (contentItemId != null) {
@@ -171,7 +173,7 @@
     /**
      * Get policy as XHTML list ordered by usecases
      */
-    static public StringBuffer getPolicyAsXHTMLListOrderedByUsecases(Policy p) {
+    static private StringBuffer getPolicyAsXHTMLListOrderedByUsecases(Policy p) {
         StringBuffer sb = new StringBuffer();
         UsecasePolicy[] up = p.getUsecasePolicies();
         if (up != null && up.length > 0) {
@@ -203,8 +205,9 @@
 
     /**
      * Get policy as XHTML list ordered by identities
+     * @param dismantleGroups Show all members of a group instead the group itself
      */
-    static public StringBuffer getPolicyAsXHTMLListOrderedByIdentities(Policy p) {
+    static private StringBuffer getPolicyAsXHTMLListOrderedByIdentities(Policy p, boolean dismantleGroups, GroupManager gm) {
         Vector worldRights = new Vector();
         java.util.HashMap users = new java.util.HashMap();
         java.util.HashMap groups = new java.util.HashMap();
@@ -271,7 +274,28 @@
         java.util.Iterator groupIterator = groups.keySet().iterator();
         while (groupIterator.hasNext()) {
             String groupName = (String) groupIterator.next();
-            sb.append("<li>Group: " + groupName + " (" + getCommaSeparatedList((Vector) groups.get(groupName)) + ")</li>");
+            String rights = getCommaSeparatedList((Vector) groups.get(groupName));
+            if (!dismantleGroups) {
+                sb.append("<li>Group: " + groupName + " (" + rights + ")</li>");
+            } else {
+                //sb.append("<li>Dismantle Group: " + groupName + " (" + rights + ")</li>");
+                try {
+                    org.wyona.security.core.api.Item[] groupMembers = gm.getGroup(groupName).getMembers();
+                    for (int i = 0; i < groupMembers.length; i++) {
+                        if (groupMembers[i] instanceof org.wyona.security.core.api.Group) {
+                            log.warn("TODO: Also dismantle sub-group '" + groupMembers[i].getID() + "' contained by group '" + groupName + "'.");
+                            sb.append("<li>Sub-Group: " + groupMembers[i].getID() + " (" + rights + ")</li>");
+                        } else if (groupMembers[i] instanceof org.wyona.security.core.api.User) {
+                            sb.append("<li>User: " + groupMembers[i].getID() + " (" + rights + ")</li>");
+                        } else {
+                            sb.append("<li>Item: " + groupMembers[i].getID() + " (" + rights + ")</li>");
+                        }
+                    }
+                } catch(Exception e) {
+                    log.error(e, e);
+                    sb.append("<li>Exception when trying to dismantle group '" + groupName + "': " + e.getMessage() + "</li>");
+                }
+            }
         }
 
 // TODO: Also add hosts
@@ -297,13 +321,13 @@
             }
         } else {
             if(log.isDebugEnabled()) log.debug("No rights asigned!");
-            return null;
+            return "No rights!";
         }
         return sb.toString();
     }
 
     /**
-     * @param showTabs TODO
+     * @param showTabs
      *
      */
     private static String getOrderByLink(int orderedBy, boolean showParents, boolean showTabs) {
@@ -322,7 +346,7 @@
      * @param aggregate If aggregate true, then the policy will be aggregated/merged with existing parent policies, otherwise only the node specific policy will be returned
      * @param back ../../../
      */
-    static private StringBuffer getPolicy(Policy policy, boolean aggregate, int orderedBy, String back) throws AuthorizationException {
+    static private StringBuffer getPolicy(Policy policy, boolean aggregate, int orderedBy, String back, GroupManager groupManager) throws AuthorizationException {
         StringBuffer sb = new StringBuffer("<td>");
         if (policy != null) {
             String showUseInheritedPolicies = "";
@@ -339,7 +363,7 @@
             if (orderedBy == ORDERED_BY_USECASES) {
                 sb.append(editPolicy + showUseInheritedPolicies + getPolicyAsXHTMLListOrderedByUsecases(policy));
             } else if (orderedBy == ORDERED_BY_IDENTITIES) {
-                sb.append(editPolicy + showUseInheritedPolicies + getPolicyAsXHTMLListOrderedByIdentities(policy));
+                sb.append(editPolicy + showUseInheritedPolicies + getPolicyAsXHTMLListOrderedByIdentities(policy, aggregate, groupManager));
             } else {
                 sb.append("No such orderedBy implemented: " + orderedBy);
             }



More information about the Yanel-commits mailing list