use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testGetApplicablePolicies.
public void testGetApplicablePolicies() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanReadAc(path);
// call must succeed without exception
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
assertNotNull("The iterator of applicable policies must not be null", it);
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testRemovePolicyIsTransient.
public void testRemovePolicyIsTransient() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanReadAc(path);
checkCanModifyAc(path);
AccessControlPolicy[] currentPolicies = acMgr.getPolicies(path);
int size = currentPolicies.length;
AccessControlPolicy toRemove;
if (size == 0) {
// no policy to remove ->> apply one
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);
toRemove = policy;
currentPolicies = acMgr.getPolicies(path);
size = currentPolicies.length;
} else {
throw new NotExecutableException();
}
} else {
toRemove = currentPolicies[0];
}
// test transient behaviour of the removal
acMgr.removePolicy(path, toRemove);
assertEquals("After transient remove AccessControlManager.getPolicies must return less policies.", size - 1, acMgr.getPolicies(path).length);
// revert changes
superuser.refresh(false);
assertEquals("Reverting a Policy removal must restore the original state.", Arrays.asList(currentPolicies), Arrays.asList(acMgr.getPolicies(path)));
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testSetPolicy.
public void testSetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanModifyAc(path);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
} else {
throw new NotExecutableException();
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testResetPolicy.
public void testResetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanReadAc(path);
checkCanModifyAc(path);
// make sure that at least a single policy has been set.
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
}
// access the policies already present at path and test if updating
// (resetting) the policies works as well.
AccessControlPolicy[] policies = acMgr.getPolicies(path);
for (int i = 0; i < policies.length; i++) {
acMgr.setPolicy(path, policies[i]);
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyTest method testRemovePolicy.
public void testRemovePolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanModifyAc(path);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (it.hasNext()) {
AccessControlPolicy policy = it.nextAccessControlPolicy();
acMgr.setPolicy(path, policy);
acMgr.removePolicy(path, policy);
AccessControlPolicy[] plcs = acMgr.getPolicies(path);
for (int i = 0; i < plcs.length; i++) {
if (plcs[i].equals(policy)) {
fail("RemovePolicy must remove the policy that has been set before.");
}
}
} else {
throw new NotExecutableException();
}
}
Aggregations