/** * Asserts that the given privilege sets are equal, regardless of ordering. */ private void assertEquals(Privilege[] expected, Privilege[] actual) { assertEquals(getPrivilegeNames(expected), getPrivilegeNames(actual)); }
private static void verifyACEs(AccessControlPolicy[] policies, String policyPath, int numberOfAce) throws RepositoryException { JackrabbitAccessControlList acl = null; for (AccessControlPolicy p : policies) { if (p instanceof JackrabbitAccessControlList) { if (policyPath.equals(((JackrabbitAccessControlList) p).getPath())) { acl = (JackrabbitAccessControlList) p; } } } if (acl == null) { fail("No Jackrabbit ACL found at " + policyPath); } else { assertEquals(numberOfAce, acl.getAccessControlEntries().length); } }
modifyPrivileges(path, testGroup.getPrincipal(), privilegesFromName(Privilege.JCR_READ), true); AccessControlPolicy[] plcs = acMgr.getEffectivePolicies(path); AccessControlPolicy[] plcs2 = acMgr.getEffectivePolicies(childNPath); assertTrue(Arrays.equals(plcs, plcs2)); verifyACEs(plcs2, path, 1); modifyPrivileges(path, testGroup.getPrincipal(), privilegesFromName(Privilege.JCR_WRITE), false); plcs = acMgr.getEffectivePolicies(path); plcs2 = acMgr.getEffectivePolicies(childNPath); assertTrue(Arrays.equals(plcs, plcs2)); verifyACEs(plcs2, path, 2); modifyPrivileges(childNPath, testGroup.getPrincipal(), privilegesFromName(Privilege.JCR_ADD_CHILD_NODES), true); plcs = acMgr.getEffectivePolicies(path); plcs2 = acMgr.getEffectivePolicies(childNPath); assertFalse(Arrays.equals(plcs, plcs2)); verifyACEs(plcs2, path, 2); verifyACEs(plcs2, childNPath, 1); modifyPrivileges(childNPath, testGroup.getPrincipal(), privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES), true); plcs = acMgr.getEffectivePolicies(path); plcs2 = acMgr.getEffectivePolicies(childNPath); assertFalse(Arrays.equals(plcs, plcs2)); verifyACEs(plcs2, path, 2); verifyACEs(plcs2, childNPath, 1);
public void testPermissions() throws Exception { Session superuser2 = getHelper().getSuperuserSession(); try { JackrabbitAccessControlManager acM = (JackrabbitAccessControlManager) acMgr; Privilege[] privs = privilegesFromName(Privilege.JCR_LOCK_MANAGEMENT); modifyPrivileges(path, testGroup.getPrincipal(), privs, true); assertTrue(acM.hasPrivileges(path, principals, privs)); assertTrue(acM2.hasPrivileges(path, principals, privs)); assertTrue(acM.hasPrivileges(childNPath, principals, privs)); assertTrue(acM2.hasPrivileges(childNPath, principals, privs)); modifyPrivileges(path, testGroup.getPrincipal(), privilegesFromName(Privilege.JCR_WRITE), true); privs = privilegesFromNames(new String[] { Privilege.JCR_LOCK_MANAGEMENT, Privilege.JCR_WRITE}); assertTrue(acM.hasPrivileges(path, principals, privs)); assertTrue(acM2.hasPrivileges(path, principals, privs)); assertTrue(acM.hasPrivileges(childNPath, principals, privs)); assertTrue(acM2.hasPrivileges(childNPath, principals, privs)); modifyPrivileges(childNPath, testGroup.getPrincipal(), privilegesFromName(Privilege.JCR_ADD_CHILD_NODES), false); privs = privilegesFromNames(new String[] { Privilege.JCR_LOCK_MANAGEMENT,
@Override protected void setUp() throws Exception { super.setUp(); // create some nodes below the test root in order to apply ac-stuff Node node = testRootNode.addNode(nodeName1, testNodeType); Node cn1 = node.addNode(nodeName2, testNodeType); superuser.save(); path = node.getPath(); childNPath = cn1.getPath(); // create the testGroup UserManager umgr = getUserManager(superuser); Principal groupPrincipal = new TestPrincipal("testGroup" + UUID.randomUUID()); testGroup = umgr.createGroup(groupPrincipal); testUser = umgr.createUser("testUser" + UUID.randomUUID(), "pw"); if (!umgr.isAutoSave() && superuser.hasPendingChanges()) { superuser.save(); } }
private ACLTemplate modifyPrivileges(String path, Principal principal, Privilege[] privileges, boolean isAllow) throws NotExecutableException, RepositoryException { ACLTemplate tmpl = getPolicy(acMgr, path, principal); tmpl.addEntry(principal, privileges, isAllow); acMgr.setPolicy(tmpl.getPath(), tmpl); superuser.save(); return tmpl; }
private void runTestUnderLoad(TestInvokation ti) throws Exception { JcrTestThread t[] = new JcrTestThread[4]; for (int i = 0; i < t.length; i++) { t[i] = new JcrTestThread(); } try { for (int i = 0; i < t.length; i++) { t[i].start(); } ti.runTest(); } finally { for (int i = 0; i < t.length; i++) { t[i].stopMe(); t[i].join(); Throwable th = t[i].getLastExc(); if (th != null) { fail("failure in load thread: " + th); } } } }
@Override protected void tearDown() throws Exception { try { if (testGroup != null) { testGroup.remove(); if (!getUserManager(superuser).isAutoSave() && superuser.hasPendingChanges()) { superuser.save(); } } if (testUser != null) { testUser.remove(); if (!getUserManager(superuser).isAutoSave() && superuser.hasPendingChanges()) { superuser.save(); } } } finally { super.tearDown(); } }