Search in sources :

Example 41 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class CugAccessControlManagerTest method testGetApplicablePolicies.

@Test
public void testGetApplicablePolicies() throws Exception {
    AccessControlPolicyIterator it = cugAccessControlManager.getApplicablePolicies(SUPPORTED_PATH);
    assertTrue(it.hasNext());
    AccessControlPolicy policy = cugAccessControlManager.getApplicablePolicies(SUPPORTED_PATH).nextAccessControlPolicy();
    assertTrue(policy instanceof CugPolicyImpl);
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Test(org.junit.Test)

Example 42 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class AdminPrincipalsBaseTest method before.

@Override
public void before() throws Exception {
    super.before();
    NodeUtil rootNode = new NodeUtil(root.getTree("/"), NamePathMapper.DEFAULT);
    rootNode.addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    administrativePrincipal = getUserManager(root).createGroup(new PrincipalImpl(ADMINISTRATORS_PRINCIPAL_NAME)).getPrincipal();
    root.commit();
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlPolicyIterator itr = acMgr.getApplicablePolicies("/testNode");
    while (itr.hasNext() && acl == null) {
        AccessControlPolicy policy = itr.nextAccessControlPolicy();
        if (policy instanceof AccessControlList) {
            acl = (AccessControlList) policy;
        }
    }
    if (acl == null) {
        throw new RepositoryException("No applicable policy found.");
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) RepositoryException(javax.jcr.RepositoryException) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Example 43 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class CompositeAccessControlManagerTest method testRemovePolicy.

@Test
public void testRemovePolicy() throws Exception {
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH);
    while (it.hasNext()) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        acMgr.setPolicy(TEST_PATH, plc);
    }
    root.commit();
    acMgr.removePolicy(TEST_PATH, TestPolicy.INSTANCE);
    root.commit();
    assertEquals(1, acMgr.getPolicies(TEST_PATH).length);
    acMgr.removePolicy(TEST_PATH, acMgr.getPolicies(TEST_PATH)[0]);
    root.commit();
    assertEquals(0, acMgr.getPolicies(TEST_PATH).length);
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 44 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class CompositeAccessControlManagerTest method testGetEffectivePolicies.

@Test
public void testGetEffectivePolicies() throws Exception {
    AccessControlPolicy[] effective = acMgr.getEffectivePolicies(TEST_PATH);
    assertEquals(0, effective.length);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH);
    while (it.hasNext()) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        acMgr.setPolicy(TEST_PATH, plc);
    }
    root.commit();
    assertEquals(2, acMgr.getEffectivePolicies(TEST_PATH).length);
    Tree child = root.getTree(TEST_PATH).addChild("child");
    child.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    assertEquals(1, acMgr.getEffectivePolicies(child.getPath()).length);
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 45 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project jackrabbit-oak by apache.

the class CompositeAccessControlManagerTest method testSetPolicyAtTestPath.

@Test
public void testSetPolicyAtTestPath() throws Exception {
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH);
    int cnt = 0;
    while (it.hasNext()) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        acMgr.setPolicy(TEST_PATH, plc);
        cnt++;
    }
    assertEquals(2, cnt);
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

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