use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.
the class AccessControlManagementTest method testSetNewPolicy.
/**
* Test if a new applicable policy can be applied within a
* sub-tree where AC-modification is allowed.
*
* @see <a href="https://issues.apache.org/jira/browse/JCR-2869">JCR-2869</a>
*/
@Test
public void testSetNewPolicy() throws Exception {
/* grant 'testUser' rep:write, rep:readAccessControl and
rep:modifyAccessControl privileges at 'path' */
Privilege[] privileges = privilegesFromNames(new String[] { REP_WRITE, Privilege.JCR_READ_ACCESS_CONTROL, Privilege.JCR_MODIFY_ACCESS_CONTROL });
allow(path, privileges);
/*
testuser must be allowed to set a new policy at a child node.
*/
AccessControlPolicyIterator it = testAcMgr.getApplicablePolicies(childNPath);
while (it.hasNext()) {
AccessControlPolicy plc = it.nextAccessControlPolicy();
testAcMgr.setPolicy(childNPath, plc);
testSession.save();
testAcMgr.removePolicy(childNPath, plc);
testSession.save();
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testGetApplicableRepoPolicies.
@Test
public void testGetApplicableRepoPolicies() throws Exception {
AccessControlPolicyIterator itr = acMgr.getApplicablePolicies((String) null);
assertNotNull(itr);
assertTrue(itr.hasNext());
AccessControlPolicy policy = itr.nextAccessControlPolicy();
assertNotNull(policy);
assertTrue(policy instanceof ACL);
ACL acl = (ACL) policy;
assertTrue(acl.isEmpty());
assertNull(acl.getPath());
assertFalse(itr.hasNext());
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class EntryCollectorTest method getPolicy.
private ACLTemplate getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException {
// try applicable (new) ACLs first
AccessControlPolicyIterator itr = acM.getApplicablePolicies(path);
while (itr.hasNext()) {
AccessControlPolicy policy = itr.nextAccessControlPolicy();
if (policy instanceof ACLTemplate) {
return (ACLTemplate) policy;
}
}
// try if there is an acl that has been set before:
AccessControlPolicy[] pcls = acM.getPolicies(path);
for (AccessControlPolicy policy : pcls) {
if (policy instanceof ACLTemplate) {
return (ACLTemplate) policy;
}
}
// no applicable or existing ACLTemplate to edit -> not executable.
throw new NotExecutableException();
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class EvaluationUtil method getPolicy.
static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException {
// try applicable (new) ACLs first
AccessControlPolicyIterator itr = acM.getApplicablePolicies(path);
while (itr.hasNext()) {
AccessControlPolicy policy = itr.nextAccessControlPolicy();
if (policy instanceof ACLTemplate) {
return (ACLTemplate) policy;
}
}
// try if there is an acl that has been set before:
AccessControlPolicy[] pcls = acM.getPolicies(path);
for (AccessControlPolicy policy : pcls) {
if (policy instanceof ACLTemplate) {
return (ACLTemplate) policy;
}
}
// no applicable or existing ACLTemplate to edit -> not executable.
throw new NotExecutableException();
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class WriteTest method testApplicablePolicies.
public void testApplicablePolicies() throws RepositoryException {
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(childNPath);
assertTrue(it.hasNext());
// the same should be true, if the rep:AccessControllable mixin has
// been manually added
Node n = (Node) superuser.getItem(childNPath);
n.addMixin(((SessionImpl) superuser).getJCRName(AccessControlConstants.NT_REP_ACCESS_CONTROLLABLE));
it = acMgr.getApplicablePolicies(childNPath);
assertTrue(it.hasNext());
}
Aggregations