Fix a few glitches in privilege management and display in the data explorer
authorBruno Sinou <bsinou@argeo.org>
Thu, 19 Nov 2015 09:48:15 +0000 (09:48 +0000)
committerBruno Sinou <bsinou@argeo.org>
Thu, 19 Nov 2015 09:48:15 +0000 (09:48 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8576 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AddPrivilegeWizard.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodePrivilegesPage.java

index 3432abb89bea8eb6717e4197435317cfef2e6eb1..0c65b7080adeb50fbc0ab0e7079c5d5a3df5f26d 100644 (file)
@@ -49,7 +49,7 @@ import org.eclipse.swt.widgets.Text;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
 
-/** Add Jcr privileges to the chosen user group on a given node */
+/** Add JCR privileges to the chosen user group on a given node */
 public class AddPrivilegeWizard extends Wizard {
 
        // Context
index 3dbae1da9592da8e84a47a400de84f5b6f1a0dd7..760a21319a11b5314654dc87062ea7cac953afec 100644 (file)
@@ -22,11 +22,6 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.security.AccessControlEntry;
-import javax.jcr.security.AccessControlList;
-import javax.jcr.security.AccessControlManager;
-import javax.jcr.security.AccessControlPolicy;
-import javax.jcr.security.AccessControlPolicyIterator;
 
 import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
@@ -46,7 +41,11 @@ import org.eclipse.ui.forms.editor.FormEditor;
 import org.eclipse.ui.forms.editor.FormPage;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 
-/** Display and edit a given node rights */
+/**
+ * Display and edit a given node privilege. For the time being it is completely
+ * JackRabbit specific (and hardcoded for this) and will display an empty page
+ * if using any other implementation
+ */
 public class NodePrivilegesPage extends FormPage {
 
        private Node context;
@@ -66,7 +65,8 @@ public class NodePrivilegesPage extends FormPage {
                layout.marginHeight = 5;
                layout.marginWidth = 5;
                form.getBody().setLayout(layout);
-               createRightsPart(form.getBody());
+               if (isJackRabbit())
+                       createRightsPart(form.getBody());
        }
 
        /** Creates the authorization part */
@@ -199,7 +199,7 @@ public class NodePrivilegesPage extends FormPage {
                                                                .getNodes();
                                                while (nit.hasNext()) {
                                                        Node currPrivNode = nit.nextNode();
-                                                       if (currPrivNode.getName().equals("allow"))
+                                                       if (currPrivNode.getName().startsWith("allow"))
                                                                privs.add(currPrivNode);
                                                }
                                        }
@@ -211,23 +211,24 @@ public class NodePrivilegesPage extends FormPage {
                                        }
                                }
 
-                               AccessControlManager acm = context.getSession()
-                                               .getAccessControlManager();
-                               AccessControlPolicyIterator acpi = acm
-                                               .getApplicablePolicies(context.getPath());
-
-                               List<AccessControlPolicy> acps = new ArrayList<AccessControlPolicy>();
-                               try {
-                                       while (true) {
-                                               Object obj = acpi.next();
-                                               acps.add((AccessControlPolicy) obj);
-                                       }
-                               } catch (Exception e) {
-                                       // No more elements
-                               }
-
-                               AccessControlList acl = ((AccessControlList) acps.get(0));
-                               AccessControlEntry[] entries = acl.getAccessControlEntries();
+                               // AccessControlManager acm = context.getSession()
+                               // .getAccessControlManager();
+                               // AccessControlPolicyIterator acpi = acm
+                               // .getApplicablePolicies(context.getPath());
+                               //
+                               // List<AccessControlPolicy> acps = new
+                               // ArrayList<AccessControlPolicy>();
+                               // try {
+                               // while (true) {
+                               // Object obj = acpi.next();
+                               // acps.add((AccessControlPolicy) obj);
+                               // }
+                               // } catch (Exception e) {
+                               // // No more elements
+                               // }
+                               //
+                               // AccessControlList acl = ((AccessControlList) acps.get(0));
+                               // AccessControlEntry[] entries = acl.getAccessControlEntries();
 
                                return privs.toArray();
                        } catch (Exception e) {
@@ -236,4 +237,16 @@ public class NodePrivilegesPage extends FormPage {
                        }
                }
        }
-}
+
+       // simply check if we are using jackrabbit without adding code dependencies
+       private boolean isJackRabbit() {
+               try {
+                       String cname = context.getSession().getClass().getName();
+                       return cname.startsWith("org.apache.jackrabbit");
+               } catch (RepositoryException e) {
+                       throw new ArgeoException("Cannot check JCR implementation used on "
+                                       + context, e);
+               }
+       }
+
+}
\ No newline at end of file