[Yanel-commits] rev 33177 - public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client

michi at wyona.com michi at wyona.com
Mon Mar 10 16:29:00 CET 2008


Author: michi
Date: 2008-03-10 16:28:59 +0100 (Mon, 10 Mar 2008)
New Revision: 33177

Modified:
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicyGetter.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicySetter.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/Group.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/User.java
Log:
right class introduced

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicyGetter.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicyGetter.java	2008-03-10 15:24:14 UTC (rev 33176)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicyGetter.java	2008-03-10 15:28:59 UTC (rev 33177)
@@ -77,10 +77,11 @@
             Element userE = (Element) userElements.item(i);
 
             NodeList rightElements = userE.getElementsByTagName("right");
-            String[] rights = new String[rightElements.getLength()];
+            Right[] rights = new Right[rightElements.getLength()];
             for (int k = 0; k < rights.length; k++) {
                 Element rightE = (Element) rightElements.item(k);
-                rights[k] = rightE.getAttribute("id");
+                // TODO: Do not hardcode permission
+                rights[k] = new Right(rightE.getAttribute("id"), true);
                 //Window.alert("User Right: " + rights[k]);
             }
 
@@ -93,10 +94,11 @@
             Element groupE = (Element) groupElements.item(i);
 
             NodeList rightElements = groupE.getElementsByTagName("right");
-            String[] rights = new String[rightElements.getLength()];
+            Right[] rights = new Right[rightElements.getLength()];
             for (int k = 0; k < rights.length; k++) {
                 Element rightE = (Element) rightElements.item(k);
-                rights[k] = rightE.getAttribute("id");
+                // TODO: Do not hardcode permission
+                rights[k] = new Right(rightE.getAttribute("id"), true);
                 //Window.alert("Group Right: " + rights[k]);
             }
 

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicySetter.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicySetter.java	2008-03-10 15:24:14 UTC (rev 33176)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AsynchronousPolicySetter.java	2008-03-10 15:28:59 UTC (rev 33177)
@@ -47,11 +47,15 @@
         if (users != null) {
             for (int i = 0; i < users.length; i++) {
                 data.append("<user id=\"" + users[i].getId() + "\">");
-                String[] rights = users[i].getRights();
+                Right[] rights = users[i].getRights();
                 if (rights != null) {
                     for (int k = 0; k < rights.length; k++) {
-                        data.append("<right id=\"" + rights[k] + "\">" + rights[k] + "</right>");
+                        data.append("<right id=\"" + rights[k].getId() + "\" permission=\"" + rights[k].getPermission() + "\">" + rights[k].getId() + "</right>");
                     }
+                } else {
+                    // TODO: Do not hardcode rights
+                    data.append("<right id=\"r\" permission=\"false\">" + "r" + "</right>");
+                    data.append("<right id=\"w\" permission=\"false\">" + "w" + "</right>");
                 }
                 data.append("</user>");
             }
@@ -59,11 +63,15 @@
         if (groups != null) {
             for (int i = 0; i < groups.length; i++) {
                 data.append("<group id=\"" + groups[i].getId() + "\">");
-                String[] rights = groups[i].getRights();
+                Right[] rights = groups[i].getRights();
                 if (rights != null) {
                     for (int k = 0; k < rights.length; k++) {
-                        data.append("<right id=\"" + rights[k] + "\">" + rights[k] + "</right>");
+                        data.append("<right id=\"" + rights[k].getId() + "\" permission=\"" + rights[k].getPermission() + "\">" + rights[k].getId() + "</right>");
                     }
+                } else {
+                    // TODO: Do not hardcode rights
+                    data.append("<right id=\"r\" permission=\"false\">" + "r" + "</right>");
+                    data.append("<right id=\"w\" permission=\"false\">" + "w" + "</right>");
                 }
                 data.append("</group>");
             }

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/Group.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/Group.java	2008-03-10 15:24:14 UTC (rev 33176)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/Group.java	2008-03-10 15:28:59 UTC (rev 33177)
@@ -21,12 +21,12 @@
 public class Group {
 
     private String id;
-    private String[] rights;
+    private Right[] rights;
 
     /**
      *
      */
-    public Group(String id, String[] rights) {
+    public Group(String id, Right[] rights) {
         this.id = id;
         this.rights = rights;
     }
@@ -41,7 +41,7 @@
     /**
      *
      */
-    public String[] getRights() {
+    public Right[] getRights() {
         return rights;
     }
 }

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java	2008-03-10 15:24:14 UTC (rev 33176)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java	2008-03-10 15:28:59 UTC (rev 33177)
@@ -85,11 +85,11 @@
                 for (int i = 0; i < users.length; i++) {
                     String label = "u: (";
 
-                    String[] rights = users[i].getRights();
+                    Right[] rights = users[i].getRights();
 
                     boolean readExists = false;
                     for (int k = 0; k < rights.length; k++) {
-                        if (rights[k].equals(READ_RIGHT)) {
+                        if (rights[k].getId().equals(READ_RIGHT)) {
                             readExists = true;
                             break;
                         }
@@ -122,11 +122,11 @@
             if (groups != null) {
                 for (int i = 0; i < groups.length; i++) {
                     String label = "g: (";
-                    String[] rights = groups[i].getRights();
+                    Right[] rights = groups[i].getRights();
 
                     boolean readExists = false;
                     for (int k = 0; k < rights.length; k++) {
-                        if (rights[k].equals(READ_RIGHT)) {
+                        if (rights[k].getId().equals(READ_RIGHT)) {
                             readExists = true;
                             break;
                         }
@@ -187,7 +187,7 @@
             String selectedIdentity = getSelectedItemText();
             if (selectedIdentity != null) {
                 if (sender == readCB) {
-                    String[] currentRights = getRights(selectedIdentity);
+                    Right[] currentRights = getRights(selectedIdentity);
                     String[] newRights;
                     if (readCB.isChecked()) {
                         Window.alert("Add Read right from selected identity " + selectedIdentity + " from policy");
@@ -198,7 +198,7 @@
                     }
                     setSelectedListItem(newRights);
                 } else if (sender == writeCB) {
-                    String[] currentRights = getRights(selectedIdentity);
+                    Right[] currentRights = getRights(selectedIdentity);
                     String[] newRights;
                     if (writeCB.isChecked()) {
                         Window.alert("Add Write right from selected identity " + selectedIdentity + " from policy");
@@ -218,15 +218,15 @@
             String selectedIdentity = getSelectedItemText();
 
             //Window.alert("Update check boxes!");
-            String[] rights = getRights(selectedIdentity);
+            Right[] rights = getRights(selectedIdentity);
 
             boolean hasReadBeenChecked = false;
             boolean hasWriteBeenChecked = false;
             for (int j = 0; j < rights.length; j++) {
-                if (rights[j].equals(READ_RIGHT)) {
+                if (rights[j].getId().equals(READ_RIGHT)) {
                     readCB.setChecked(true);
                     hasReadBeenChecked = true;
-                } else if (rights[j].equals(WRITE_RIGHT)) {
+                } else if (rights[j].getId().equals(WRITE_RIGHT)) {
                     writeCB.setChecked(true);
                     hasWriteBeenChecked = true;
                 }
@@ -239,21 +239,28 @@
     /**
      * Get rights from identity string, e.g. "u: (r,w) alice"
      */
-    private String[] getRights(String identity) {
+    private Right[] getRights(String identity) {
         if (identity.indexOf("(") > 0) {
             String[] rightsString = identity.substring(identity.indexOf("(") + 1, identity.indexOf(")")).split(",");
-            //Window.alert("Rights: " + rights);
+
             Vector r = new Vector();
+            Vector rs = new Vector();
             for (int i = 0; i < rightsString.length; i++) {
                 if (!rightsString[i].equals("-")) r.add(rightsString[i]);
+                if (!rightsString[i].equals("-")) {
+                    rs.add(new Right(rightsString[i], true));
+                } else {
+                    rs.add(new Right("TODO", false));
+                }
             }
-            String[] rights = new String[r.size()];
+            Right[] rights = new Right[rs.size()];
             for (int i = 0; i < rights.length; i++) {
-                rights[i] = (String) r.elementAt(i);
+                rights[i] = (Right) rs.elementAt(i);
             }
             return rights;
         } else {
-            return new String[0];
+            // TODO: Return all rights with permission false
+            return new Right[0];
         }
     }
 
@@ -290,19 +297,19 @@
     /**
      *
      */
-    private String[] addRight(String[] currentRights, String right) {
+    private String[] addRight(Right[] currentRights, String right) {
         //Window.alert("addRight(): Number of current rights: " + currentRights.length);
 
         // Copy all current rights
         Vector newRights = new Vector();
         for (int i = 0; i < currentRights.length; i++) {
-            newRights.add(currentRights[i]);
+            newRights.add(currentRights[i].getId());
         }
 
         // Add new right if it doesn't exist yet
         boolean hasRightAlready = false;
         for (int i = 0; i < currentRights.length; i++) {
-            if (currentRights[i].equals(right)) {
+            if (currentRights[i].getId().equals(right)) {
                 hasRightAlready = true;
                 break;
             }
@@ -320,11 +327,11 @@
     /**
      *
      */
-    private String[] removeRight(String[] currentRights, String right) {
+    private String[] removeRight(Right[] currentRights, String right) {
         Vector newRights = new Vector();
         for (int i = 0; i < currentRights.length; i++) {
-            if (!currentRights[i].equals(right)) {
-                newRights.add(currentRights[i]);
+            if (!currentRights[i].getId().equals(right)) {
+                newRights.add(currentRights[i].getId());
             }
         }
 
@@ -407,7 +414,7 @@
         Vector users = new Vector();
         for (int i = 0; i < lb.getItemCount(); i++) {
             String itemText = lb.getItemText(i);
-            String[] rights = getRights(itemText);
+            Right[] rights = getRights(itemText);
             String id = getIdentityWithoutRights(i);
             if (id.startsWith("u:")) {
                 users.add(new User(id.substring(2).trim(), rights));
@@ -428,7 +435,7 @@
         Vector groups = new Vector();
         for (int i = 0; i < lb.getItemCount(); i++) {
             String itemText = lb.getItemText(i);
-            String[] rights = getRights(itemText);
+            Right[] rights = getRights(itemText);
             String id = getIdentityWithoutRights(i);
             if (id.startsWith("g:")) {
                 groups.add(new Group(id.substring(2).trim(), rights));

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/User.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/User.java	2008-03-10 15:24:14 UTC (rev 33176)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/User.java	2008-03-10 15:28:59 UTC (rev 33177)
@@ -21,12 +21,12 @@
 public class User {
 
     private String id;
-    private String[] rights;
+    private Right[] rights;
 
     /**
      *
      */
-    public User(String id, String[] rights) {
+    public User(String id, Right[] rights) {
         this.id = id;
         this.rights = rights;
     }
@@ -41,7 +41,7 @@
     /**
      *
      */
-    public String[] getRights() {
+    public Right[] getRights() {
         return rights;
     }
 }



More information about the Yanel-commits mailing list