Search in sources :

Example 1 with AccessControlPolicyIterator

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

the class CompositeAccessControlManagerTest method testGetPolicies.

@Test
public void testGetPolicies() throws Exception {
    int len = 0;
    AccessControlPolicy[] policies = acMgr.getPolicies(TEST_PATH);
    assertEquals(len, policies.length);
    acMgr.setPolicy(TEST_PATH, TestPolicy.INSTANCE);
    len++;
    policies = acMgr.getPolicies(TEST_PATH);
    assertEquals(len, policies.length);
    assertSame(TestPolicy.INSTANCE, policies[0]);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(TEST_PATH);
    while (it.hasNext()) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        if (plc == TestPolicy.INSTANCE) {
            fail("TestPolicy should only be applicable at /test.");
        } else {
            acMgr.setPolicy(TEST_PATH, plc);
            len++;
            Set<AccessControlPolicy> policySet = ImmutableSet.copyOf(acMgr.getPolicies(TEST_PATH));
            assertEquals(len, policySet.size());
            assertTrue(policySet.contains(TestPolicy.INSTANCE));
            assertTrue(policySet.contains(plc));
        }
    }
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with AccessControlPolicyIterator

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

the class CompositeAccessControlManagerTest method testGetApplicablePolicies.

@Test
public void testGetApplicablePolicies() throws Exception {
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
    while (it.hasNext()) {
        if (it.nextAccessControlPolicy() == TestPolicy.INSTANCE) {
            fail("TestPolicy should only be applicable at /test.");
        }
    }
    Set<AccessControlPolicy> applicable = ImmutableSet.copyOf(acMgr.getApplicablePolicies(TEST_PATH));
    assertEquals(2, applicable.size());
    assertTrue(applicable.contains(TestPolicy.INSTANCE));
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with AccessControlPolicyIterator

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

the class CompositeAccessControlManagerTest method testSetPolicyAtRoot.

@Test
public void testSetPolicyAtRoot() throws Exception {
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
    int cnt = 0;
    while (it.hasNext()) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        assertTrue(plc instanceof JackrabbitAccessControlList);
        acMgr.setPolicy("/", plc);
        cnt++;
    }
    assertEquals(1, cnt);
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with AccessControlPolicyIterator

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

the class AccessControlImporterTest method createImportTargetWithPolicy.

private Node createImportTargetWithPolicy(@Nullable Principal principal) throws RepositoryException {
    Node target = testRootNode.addNode("test", "test:sameNameSibsFalseChildNodeDefinition");
    AccessControlManager acMgr = superuser.getAccessControlManager();
    for (AccessControlPolicyIterator it = acMgr.getApplicablePolicies(target.getPath()); it.hasNext(); ) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        if (policy instanceof AccessControlList) {
            if (principal != null) {
                Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT) };
                ((AccessControlList) policy).addAccessControlEntry(principal, privs);
            }
            acMgr.setPolicy(target.getPath(), policy);
        }
    }
    if (!isSessionImport()) {
        superuser.save();
    }
    return target;
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Node(javax.jcr.Node) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Privilege(javax.jcr.security.Privilege)

Example 5 with AccessControlPolicyIterator

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

the class CugAccessControlManagerTest method testGetApplicablePoliciesUnsupportedPath.

@Test
public void testGetApplicablePoliciesUnsupportedPath() throws Exception {
    AccessControlPolicyIterator it = cugAccessControlManager.getApplicablePolicies(UNSUPPORTED_PATH);
    assertFalse(it.hasNext());
}
Also used : AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) 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