[Yanel-commits] rev 33452 -
public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client
michi at wyona.com
michi at wyona.com
Sun Mar 16 16:10:19 CET 2008
Author: michi
Date: 2008-03-16 16:10:18 +0100 (Sun, 16 Mar 2008)
New Revision: 33452
Modified:
public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java
public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java
Log:
policy reading fixed and generalized
Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java 2008-03-16 14:23:45 UTC (rev 33451)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java 2008-03-16 15:10:18 UTC (rev 33452)
@@ -68,9 +68,11 @@
}
// Get data from server
- getPolicy(readPolicyURL);
getIdentitiesAndRights(identitiesURL); // TODO: Subtract policy identities!
+ // TODO: Do not load policy before available rights have been loaded, because these are needed for validation of the policy. See timer of identities and rights loading!
+ getPolicy(readPolicyURL);
+
// Setup GUI
VerticalPanel vp = new VerticalPanel();
RootPanel.get().add(vp);
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-16 14:23:45 UTC (rev 33451)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java 2008-03-16 15:10:18 UTC (rev 33452)
@@ -42,8 +42,6 @@
private VerticalPanel vp = new VerticalPanel();
- private String READ_RIGHT = "r";
- private String WRITE_RIGHT = "w";
private Right[] availableRights;
private CheckBox[] availableRightsCB;
@@ -77,82 +75,22 @@
if (users != null || groups != null) {
if (users != null) {
for (int i = 0; i < users.length; i++) {
- String label = "u: (";
-
+ String type = "u";
+ String id = users[i].getId();
Right[] rights = users[i].getRights();
//Window.alert("User: " + users[i].getId() + " (Number of rights: " + rights.length + ")");
-
- boolean readExists = false;
- for (int k = 0; k < rights.length; k++) {
- //Window.alert("Check for READ right: " + rights[k].getId());
- if (rights[k].getId().equals(READ_RIGHT)) {
- readExists = true;
- break;
- }
- }
- if (readExists) {
- label = label + READ_RIGHT;
- } else {
- label = label + "-";
- }
- label = label + ",";
- boolean writeExists = false;
- for (int k = 0; k < rights.length; k++) {
- //Window.alert("Check for WRITE right: " + rights[k].getId());
- if (rights[k].getId().equals(WRITE_RIGHT)) {
- writeExists = true;
- break;
- }
- }
- if (writeExists) {
- //Window.alert("WRITE exists");
- label = label + WRITE_RIGHT;
- } else {
- //Window.alert("WRITE does NOT exist");
- label = label + "-";
- }
-
- label = label +") " + users[i].getId();
-
- String value = "u: " + users[i].getId();
- lb.addItem(label, value);
+ String value = type+": " + id;
+ lb.addItem(getListLabel(type, id, rights), value);
}
}
if (groups != null) {
for (int i = 0; i < groups.length; i++) {
- String label = "g: (";
+ String type = "g";
+ String id = groups[i].getId();
Right[] rights = groups[i].getRights();
//Window.alert("Group: " + groups[i].getId() + " (Number of rights: " + rights.length + ")");
-
- boolean readExists = false;
- for (int k = 0; k < rights.length; k++) {
- if (rights[k].getId().equals(READ_RIGHT)) {
- readExists = true;
- break;
- }
- }
- if (readExists) {
- label = label + READ_RIGHT;
- } else {
- label = label + "-";
- }
- label = label + ",";
- boolean writeExists = false;
- for (int k = 0; k < rights.length; k++) {
- if (rights[k].getId().equals(WRITE_RIGHT)) {
- writeExists = true;
- break;
- }
- }
- if (writeExists) {
- label = label + WRITE_RIGHT;
- } else {
- label = label + "-";
- }
-
- label = label + ") " + groups[i].getId();
- String value = "g: " + groups[i].getId();
- lb.addItem(label, value);
+ String value = type+": " + id;
+ lb.addItem(getListLabel(type, id, rights), value);
}
} else {
Window.alert("No groups!");
@@ -343,6 +281,15 @@
* @param index Position of list item
*/
private void setListItem(String type, String id, String[] rights, int index) {
+ lb.setItemText(index, getListLabel(type, id, rights));
+ }
+
+ /**
+ * @param type u for user and g for group
+ * @param id
+ * @param rights Rights
+ */
+ private String getListLabel(String type, String id, String[] rights) {
StringBuffer sb = new StringBuffer(type + ":");
sb.append("(" + rights[0]);
@@ -351,10 +298,45 @@
}
sb.append(")");
sb.append(" " + id);
- lb.setItemText(index, sb.toString());
+ return sb.toString();
}
/**
+ * @param type u for user and g for group
+ * @param id
+ * @param rights Rights
+ */
+ private String getListLabel(String type, String id, Right[] rights) {
+ StringBuffer sb = new StringBuffer(type + ":");
+
+ if (availableRights != null) {
+ sb.append("(");
+ for (int i = 0; i < availableRights.length; i ++) {
+ boolean rightExists = false;
+ for (int k = 0; k < rights.length; k ++) {
+ if (availableRights[i].getId().equals(rights[k].getId()) && rights[k].getPermission()) {
+ rightExists = true;
+ break;
+ }
+ }
+ if (i > 0) {
+ sb.append(",");
+ }
+ if (rightExists) {
+ sb.append(availableRights[i].getId());
+ } else {
+ sb.append("-");
+ }
+ }
+ sb.append(")");
+ } else {
+ Window.alert("Available rights not loaded yet!");
+ }
+ sb.append(" " + id);
+ return sb.toString();
+ }
+
+ /**
*
*/
public User[] getUsers() {
More information about the Yanel-commits
mailing list