use of javax.jcr.security.AccessControlPolicyIterator 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.AccessControlPolicyIterator in project jackrabbit by apache.
the class RSessionAccessControlPolicyTest method testSetPolicy.
public void testSetPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
// retrieve valid policy using superuser session:
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
if (!it.hasNext()) {
throw new NotExecutableException();
}
try {
testAcMgr.setPolicy(path, it.nextAccessControlPolicy());
fail("read only session may not modify AC content.");
} catch (AccessControlException e) {
// success.
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyIteratorTest method testGetPosition.
public void testGetPosition() throws NotExecutableException, RepositoryException {
checkCanReadAc(path);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
long position = 0;
while (it.hasNext()) {
assertEquals("Position must be adjusted during iteration.", position, it.getPosition());
it.nextAccessControlPolicy();
assertEquals("Position must be adjusted after calling next.", ++position, it.getPosition());
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class AccessControlPolicyIteratorTest method testSkip.
public void testSkip() throws NotExecutableException, RepositoryException {
checkCanReadAc(path);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
long size = it.getSize();
if (size > -1) {
it.skip(size);
assertFalse("After skipping all elements 'hasNext()' must return false", it.hasNext());
try {
it.nextAccessControlPolicy();
fail("After skipping all 'nextAccessControlPolicy()' must fail.");
} catch (NoSuchElementException e) {
// success
}
} else {
throw new NotExecutableException();
}
}
use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit by apache.
the class ConcurrentReadAccessControlledTreeTest method beforeSuite.
@Override
protected void beforeSuite() throws Exception {
super.beforeSuite();
ItemVisitor visitor = new TraversingItemVisitor.Default() {
int counter = 0;
@Override
protected void entering(Node node, int level) throws RepositoryException {
if (++counter == 10) {
addPolicy(node);
counter = 0;
}
super.entering(node, level);
}
private void addPolicy(Node node) throws RepositoryException {
AccessControlManager acMgr = node.getSession().getAccessControlManager();
String path = node.getPath();
AccessControlPolicyIterator acIterator = acMgr.getApplicablePolicies(path);
if (acIterator.hasNext()) {
AccessControlPolicy policy = acIterator.nextAccessControlPolicy();
if (policy instanceof AccessControlList) {
AccessControlList acl = (AccessControlList) policy;
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
acMgr.setPolicy(path, acl);
node.getSession().save();
}
}
}
}
};
visitor.visit(testRoot);
for (int i = 0; i < bgReaders; i++) {
addBackgroundJob(new RandomRead(loginReader(), false));
}
}
Aggregations