Search in sources :

Example 31 with AccessControlPolicyIterator

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);
    }
}
Also used : Item(javax.jcr.Item) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 32 with AccessControlPolicyIterator

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.
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 33 with AccessControlPolicyIterator

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());
    }
}
Also used : AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 34 with AccessControlPolicyIterator

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();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 35 with AccessControlPolicyIterator

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));
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Privilege(javax.jcr.security.Privilege)

Aggregations

AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)69 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)54 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)22 Test (org.junit.Test)16 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)15 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)15 AccessControlList (javax.jcr.security.AccessControlList)14 AccessControlManager (javax.jcr.security.AccessControlManager)13 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)11 Node (javax.jcr.Node)7 Privilege (javax.jcr.security.Privilege)6 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)6 AccessControlEntry (javax.jcr.security.AccessControlEntry)5 Principal (java.security.Principal)3 HashSet (java.util.HashSet)3 Item (javax.jcr.Item)3 RepositoryException (javax.jcr.RepositoryException)3 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)3 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2