use of javax.jcr.security.AccessControlPolicy 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();
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AccessControlPolicyTest method testNodeIsModifiedAfterRemovePolicy.
public void testNodeIsModifiedAfterRemovePolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
checkCanReadAc(path);
checkCanModifyAc(path);
Item item = superuser.getItem(path);
if (acMgr.getPolicies(path).length == 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);
} else {
throw new NotExecutableException();
}
}
// test transient behaviour of the removal
try {
AccessControlPolicy[] plcs = acMgr.getPolicies(path);
if (plcs.length > 0) {
acMgr.removePolicy(path, plcs[0]);
assertTrue("After removing a policy the node must be marked modified.", item.isModified());
}
} finally {
item.refresh(false);
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AccessControlPolicyTest method testApplicablePoliciesAreDistintFromSetPolicies.
public void testApplicablePoliciesAreDistintFromSetPolicies() throws RepositoryException, NotExecutableException {
checkCanReadAc(path);
// call must succeed without exception
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
Set<AccessControlPolicy> acps = new HashSet<AccessControlPolicy>();
while (it.hasNext()) {
acps.add(it.nextAccessControlPolicy());
}
AccessControlPolicy[] policies = acMgr.getPolicies(path);
for (int i = 0; i < policies.length; i++) {
assertFalse("The applicable policies obtained should not be present among the policies obtained through AccessControlManager.getPolicies.", acps.contains(policies[i]));
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class RSessionAccessControlPolicyTest method testSetInvalidPolicy.
public void testSetInvalidPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
try {
testAcMgr.setPolicy(path, new AccessControlPolicy() {
public String getName() throws RepositoryException {
return getClass().getName();
}
public String getDescription() throws RepositoryException {
return "";
}
});
fail("Invalid policy may not be set by a READ-only session.");
} catch (AccessControlException e) {
// success.
}
}
use of javax.jcr.security.AccessControlPolicy 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]);
}
}
Aggregations