use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testAddAccessControlEntry.
public void testAddAccessControlEntry() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
Privilege[] privileges = new Privilege[] { privs[0] };
AccessControlList acl = getList(acMgr, path);
AccessControlEntry entry = null;
if (acl.addAccessControlEntry(testPrincipal, privileges)) {
AccessControlEntry[] aces = acl.getAccessControlEntries();
for (int i = 0; i < aces.length; i++) {
if (aces[i].getPrincipal().equals(testPrincipal) && Arrays.asList(privileges).equals(Arrays.asList(aces[i].getPrivileges()))) {
entry = aces[i];
}
}
if (entry == null)
throw new NotExecutableException();
} else {
throw new NotExecutableException();
}
assertEquals("Principal name of the ACE must be equal to the name of the passed Principal", testPrincipal.getName(), entry.getPrincipal().getName());
assertEquals("Privileges of the ACE must be equal to the passed ones", Arrays.asList(privileges), Arrays.asList(entry.getPrivileges()));
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testAddAccessControlEntryIsTransient.
public void testAddAccessControlEntryIsTransient() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
AccessControlList acl = getList(acMgr, path);
List<AccessControlEntry> originalAces = Arrays.asList(acl.getAccessControlEntries());
if (!acl.addAccessControlEntry(testPrincipal, privs)) {
throw new NotExecutableException();
}
// set the policy (see #testAddAccessControlEntryAndSetPolicy)
acMgr.setPolicy(path, acl);
// revert the changes made
superuser.refresh(false);
assertEquals("After calling Session.refresh() any changes to a nodes policies must be reverted.", originalAces, Arrays.asList(getList(acMgr, path).getAccessControlEntries()));
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testAddAbstractPrivilege.
public void testAddAbstractPrivilege() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
Privilege abstractPriv = null;
Privilege[] allPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
for (int i = 0; i < allPrivs.length; i++) {
if (allPrivs[i].isAbstract()) {
abstractPriv = allPrivs[i];
break;
}
}
if (abstractPriv == null) {
throw new NotExecutableException("No abstract privilege found.");
}
AccessControlList acl = getList(acMgr, path);
try {
acl.addAccessControlEntry(testPrincipal, new Privilege[] { abstractPriv });
fail("Adding an ACE with an abstract privilege must fail.");
} catch (AccessControlException e) {
// success
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testRemoveAddedAccessControlEntry.
public void testRemoveAddedAccessControlEntry() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
AccessControlList acl = getList(acMgr, path);
acl.addAccessControlEntry(testPrincipal, privs);
AccessControlEntry[] aces = acl.getAccessControlEntries();
for (int i = 0; i < aces.length; i++) {
acl.removeAccessControlEntry(aces[i]);
}
assertEquals("After removing all ACEs the ACL must be empty", 0, acl.getAccessControlEntries().length);
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testRemoveAccessControlEntry.
public void testRemoveAccessControlEntry() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
AccessControlList acl = getList(acMgr, path);
AccessControlEntry[] entries = acl.getAccessControlEntries();
if (entries.length > 0) {
AccessControlEntry ace = entries[0];
acl.removeAccessControlEntry(ace);
// retrieve entries again:
List<AccessControlEntry> remainingEntries = Arrays.asList(acl.getAccessControlEntries());
assertFalse("AccessControlList.getAccessControlEntries still returns a removed ACE.", remainingEntries.contains(ace));
}
}
Aggregations