PrivilegeRegistry privilegeRegistry = new PrivilegeRegistry(sImpl);
return new ACLTemplate(path, princicipalMgr, privilegeRegistry, sImpl.getValueFactory());
}
public void testMultipleEntryEffect() throws RepositoryException, NotExecutableException {
JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
pt.addEntry(testPrincipal, privileges, true, Collections.EMPTY_MAP);
// new entry extends privs.
privileges = privilegesFromNames(new String[] {
Privilege.JCR_READ,
Privilege.JCR_ADD_CHILD_NODES});
assertTrue(pt.addEntry(testPrincipal,
privileges,
true, Collections.EMPTY_MAP));
// net-effect: only a single allow-entry with both privileges
assertTrue(pt.size() == 1);
assertSamePrivileges(privileges, pt.getAccessControlEntries()[0].getPrivileges());
// adding just ADD_CHILD_NODES -> must not remove READ priv
Privilege[] achPrivs = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
assertFalse(pt.addEntry(testPrincipal, achPrivs, true, Collections.EMPTY_MAP));
// net-effect: only a single allow-entry with add_child_nodes + read priv
assertTrue(pt.size() == 1);
assertSamePrivileges(privileges, pt.getAccessControlEntries()[0].getPrivileges());
// revoke the 'READ' privilege
privileges = privilegesFromName(Privilege.JCR_READ);
assertTrue(pt.addEntry(testPrincipal, privileges, false, Collections.EMPTY_MAP));
// net-effect: 2 entries one allowing ADD_CHILD_NODES, the other denying READ
assertTrue(pt.size() == 2);
assertSamePrivileges(privilegesFromName(Privilege.JCR_ADD_CHILD_NODES),
pt.getAccessControlEntries()[0].getPrivileges());
assertSamePrivileges(privilegesFromName(Privilege.JCR_READ),
pt.getAccessControlEntries()[1].getPrivileges());
// remove the deny-READ entry
pt.removeAccessControlEntry(pt.getAccessControlEntries()[1]);
assertTrue(pt.size() == 1);
assertSamePrivileges(privilegesFromName(Privilege.JCR_ADD_CHILD_NODES),
pt.getAccessControlEntries()[0].getPrivileges());
// remove the allow-ADD_CHILD_NODES entry
pt.removeAccessControlEntry(pt.getAccessControlEntries()[0]);
assertTrue(pt.isEmpty());
}