use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testAddAccessControlEntryAgain.
public void testAddAccessControlEntryAgain() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
AccessControlList list = getList(acMgr, path);
list.addAccessControlEntry(testPrincipal, privs);
AccessControlEntry[] entries = list.getAccessControlEntries();
if (entries.length > 0) {
assertFalse("Adding an existing entry again must not modify the AC-List", list.addAccessControlEntry(entries[0].getPrincipal(), entries[0].getPrivileges()));
} else {
throw new NotExecutableException();
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testExtendPrivileges.
public void testExtendPrivileges() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
// search 2 non-aggregated privileges
List<Privilege> twoPrivs = new ArrayList<Privilege>(2);
for (int i = 0; i < privs.length && twoPrivs.size() < 2; i++) {
if (!privs[i].isAggregate()) {
twoPrivs.add(privs[i]);
}
}
if (twoPrivs.size() < 2) {
throw new NotExecutableException("At least 2 supported, non-aggregate privileges required at " + path);
}
AccessControlList acl = getList(acMgr, path);
Privilege privilege = twoPrivs.get(0);
// add first privilege:
acl.addAccessControlEntry(testPrincipal, new Privilege[] { privilege });
// add a second privilege (but not specifying the privilege added before)
// -> the first privilege must not be removed.
Privilege privilege2 = twoPrivs.get(1);
acl.addAccessControlEntry(testPrincipal, new Privilege[] { privilege2 });
List<Privilege> currentPrivileges = currentPrivileges(acl, testPrincipal);
assertTrue("'AccessControlList.addAccessControlEntry' must not remove privileges added before", currentPrivileges.containsAll(twoPrivs));
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testAddAccessControlEntryInvalidPrincipal.
public void testAddAccessControlEntryInvalidPrincipal() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
try {
Principal invalidPrincipal = getHelper().getUnknownPrincipal(superuser);
AccessControlList acl = getList(acMgr, path);
acl.addAccessControlEntry(invalidPrincipal, privs);
fail("Adding an entry with an unknown principal must throw AccessControlException.");
} catch (AccessControlException e) {
// success.
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testRemoveIllegalAccessControlEntry.
public void testRemoveIllegalAccessControlEntry() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
try {
AccessControlEntry entry = new AccessControlEntry() {
public Principal getPrincipal() {
return testPrincipal;
}
public Privilege[] getPrivileges() {
return privs;
}
};
AccessControlList acl = getList(acMgr, path);
acl.removeAccessControlEntry(entry);
fail("AccessControlManager.removeAccessControlEntry with an unknown entry must throw AccessControlException.");
} catch (AccessControlException e) {
// ok
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlListTest method testAddAccessControlEntryEmptyPrivilegeArray.
public void testAddAccessControlEntryEmptyPrivilegeArray() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
try {
Privilege[] invalidPrivs = new Privilege[0];
AccessControlList acl = getList(acMgr, path);
acl.addAccessControlEntry(testPrincipal, invalidPrivs);
fail("Adding an entry with an invalid privilege array must throw AccessControlException.");
} catch (AccessControlException e) {
// success.
} finally {
superuser.refresh(false);
}
}
Aggregations