use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testRemoveTransientlyAddedPolicy.
public void testRemoveTransientlyAddedPolicy() throws RepositoryException, AccessDeniedException {
AccessControlPolicy[] ex = acMgr.getPolicies(path);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
while (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
acMgr.removePolicy(path, policy);
String msg = "transiently added AND removing a policy must revert " + "the changes made. " + "ACMgr.getPolicies must then return the original value.";
assertEquals(msg, Arrays.asList(ex), Arrays.asList(acMgr.getPolicies(path)));
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testNodeIsModifiedAfterSecondSetPolicy.
public void testNodeIsModifiedAfterSecondSetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanModifyAc(path);
// make sure a policy has been explicitely set.
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
superuser.save();
// remember for tearDown
addedPolicies.put(path, policy);
} else {
throw new NotExecutableException();
}
// call 'setPolicy' a second time -> Node must be modified.
it = acMgr.getApplicablePolicies(path);
try {
if (it.hasNext()) {
Item item = superuser.getItem(path);
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
assertTrue("After setting a policy the node must be marked modified.", item.isModified());
} else {
throw new NotExecutableException();
}
} finally {
// revert changes
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testGetPolicyAfterSet.
public void testGetPolicyAfterSet() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanReadAc(path);
checkCanModifyAc(path);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
AccessControlPolicy[] policies = acMgr.getPolicies(path);
for (int i = 0; i < policies.length; i++) {
if (policy.equals(policies[i])) {
// ok
return;
}
}
fail("GetPolicies must at least return the policy that has been set before.");
} else {
throw new NotExecutableException();
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testSetAllPolicies.
public void testSetAllPolicies() throws RepositoryException, NotExecutableException {
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (!it.hasNext()) {
throw new NotExecutableException();
}
while (it.hasNext()) {
acMgr.setPolicy(path, it.nextAccessControlPolicy());
}
// all policies have been set -> no additional applicable policies.
it = acMgr.getApplicablePolicies(path);
assertFalse("After having set all applicable policies AccessControlManager.getApplicablePolicies should return an empty iterator.", it.hasNext());
assertEquals("After having set all applicable policies AccessControlManager.getApplicablePolicies should return an empty iterator.", 0, it.getSize());
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlManagerImplTest method testRemovePolicyAfterASetPoliciesCall.
/**
* This should be able to return the policies that has been transiently added
* to the node at testRoot, as the getPolicies api specifies that the method should
* take the transient changes into account.
* @throws Exception
*/
public void testRemovePolicyAfterASetPoliciesCall() throws Exception {
try {
AccessControlPolicyIterator policies = acMgr.getApplicablePolicies(testRoot);
while (policies.hasNext()) {
AccessControlList acl = (AccessControlListImpl) policies.nextAccessControlPolicy();
// GRANT read privilege
acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
acMgr.setPolicy(testRoot, acl);
AccessControlPolicy[] transientPolicy = acMgr.getPolicies(testRoot);
acMgr.removePolicy(testRoot, transientPolicy[0]);
assertEquals(0, acMgr.getPolicies(testRoot).length);
}
} finally {
superuser.refresh(false);
}
}
Aggregations