use of javax.jcr.security.AccessControlEntry 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.AccessControlEntry in project jackrabbit by apache.
the class AccessControlListTest method testRemoveAccessControlEntryAndSetPolicy.
public void testRemoveAccessControlEntryAndSetPolicy() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
// add a new ACE that can be removed later on.
AccessControlList acl = getList(acMgr, path);
if (!acl.addAccessControlEntry(testPrincipal, privs)) {
throw new NotExecutableException();
} else {
acMgr.setPolicy(path, acl);
}
// try to re-access the modifiable ACL in order to remove the ACE
// added before.
acl = getList(acMgr, path);
AccessControlEntry ace = null;
AccessControlEntry[] aces = acl.getAccessControlEntries();
if (aces.length == 0) {
throw new NotExecutableException();
} else {
ace = aces[0];
acl.removeAccessControlEntry(ace);
}
// before setting the policy again -> no changes visible.
assertEquals("Removal of an ACE must only be visible upon 'setPolicy'", Arrays.asList(aces), Arrays.asList(getList(acMgr, path).getAccessControlEntries()));
// set policy again.
acMgr.setPolicy(path, acl);
assertEquals("After 'setPolicy' the ACE-removal must be visible to the editing session.", Arrays.asList(acl.getAccessControlEntries()), Arrays.asList(getList(acMgr, path).getAccessControlEntries()));
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit by apache.
the class AccessControlListTest method testRemoveAccessControlEntryIsTransient.
public void testRemoveAccessControlEntryIsTransient() throws NotExecutableException, RepositoryException {
checkCanModifyAc(path);
AccessControlList acl = getList(acMgr, path);
// make sure an ACE is present and modifications are persisted.
if (acl.addAccessControlEntry(testPrincipal, privs)) {
acMgr.setPolicy(path, acl);
superuser.save();
} else {
throw new NotExecutableException();
}
// retrieve ACL again -> transient removal of the ace
acl = getList(acMgr, path);
AccessControlEntry ace = acl.getAccessControlEntries()[0];
acl.removeAccessControlEntry(ace);
acMgr.setPolicy(path, acl);
// revert changes -> removed entry must be present again.
superuser.refresh(false);
List<AccessControlEntry> entries = Arrays.asList(getList(acMgr, path).getAccessControlEntries());
assertTrue("After reverting any changes the removed ACE should be present again.", entries.contains(ace));
}
use of javax.jcr.security.AccessControlEntry 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.AccessControlEntry 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();
}
}
Aggregations