Search in sources :

Example 26 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testGetApplicablePolicies.

//--------------------------------------< getApplicablePolicies(String) >---
@Test
public void testGetApplicablePolicies() throws Exception {
    AccessControlPolicyIterator itr = acMgr.getApplicablePolicies(testPath);
    assertNotNull(itr);
    assertTrue(itr.hasNext());
    AccessControlPolicy policy = itr.nextAccessControlPolicy();
    assertNotNull(policy);
    assertTrue(policy instanceof ACL);
    ACL acl = (ACL) policy;
    assertTrue(acl.isEmpty());
    assertEquals(testPath, acl.getPath());
    assertFalse(itr.hasNext());
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 27 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testGetPolicies.

//------------------------------------------------< getPolicies(String) >---
@Test
public void testGetPolicies() throws Exception {
    AccessControlPolicy policy = getApplicablePolicy(testPath);
    acMgr.setPolicy(testPath, policy);
    AccessControlPolicy[] policies = acMgr.getPolicies(testPath);
    assertNotNull(policies);
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof ACL);
    ACL acl = (ACL) policies[0];
    assertTrue(acl.isEmpty());
    assertEquals(testPath, acl.getOakPath());
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 28 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testRemovePolicyPropertyPath.

@Test
public void testRemovePolicyPropertyPath() throws Exception {
    try {
        String path = "/jcr:primaryType";
        AccessControlPolicy acl = createPolicy(path);
        acMgr.removePolicy(path, acl);
        fail("Removing access control policy at property path should fail");
    } catch (PathNotFoundException e) {
    // success
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) PathNotFoundException(javax.jcr.PathNotFoundException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 29 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testEffectiveSorting.

@Test
public void testEffectiveSorting() throws Exception {
    Set<Principal> principalSet = ImmutableSet.of(testPrincipal, EveryonePrincipal.getInstance());
    ACL nullPathPolicy = null;
    try {
        // 1. policy at 'testPath'
        ACL policy = getApplicablePolicy(testPath);
        policy.addEntry(testPrincipal, testPrivileges, true, getGlobRestriction("*"));
        policy.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.JCR_VERSION_MANAGEMENT), false);
        policy.addEntry(EveryonePrincipal.getInstance(), privilegesFromNames(PrivilegeConstants.JCR_LIFECYCLE_MANAGEMENT), false);
        acMgr.setPolicy(testPath, policy);
        // 2. policy at child node
        NodeUtil child = new NodeUtil(root.getTree(testPath)).addChild("child", JcrConstants.NT_UNSTRUCTURED);
        String childPath = child.getTree().getPath();
        setupPolicy(childPath);
        // 3. policy for null-path
        nullPathPolicy = getApplicablePolicy(null);
        assertNotNull(nullPathPolicy);
        nullPathPolicy.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT), true);
        acMgr.setPolicy(null, nullPathPolicy);
        root.commit();
        AccessControlPolicy[] effectivePolicies = acMgr.getEffectivePolicies(principalSet);
        assertEquals(3, effectivePolicies.length);
        assertNull(((JackrabbitAccessControlPolicy) effectivePolicies[0]).getPath());
        assertEquals(testPath, ((JackrabbitAccessControlPolicy) effectivePolicies[1]).getPath());
        assertEquals(childPath, ((JackrabbitAccessControlPolicy) effectivePolicies[2]).getPath());
    } finally {
        if (nullPathPolicy != null) {
            acMgr.removePolicy(null, nullPathPolicy);
            root.commit();
        }
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 30 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testGetPoliciesByPrincipal.

@Test
public void testGetPoliciesByPrincipal() throws Exception {
    List<Principal> principals = ImmutableList.of(testPrincipal, EveryonePrincipal.getInstance());
    for (Principal principal : principals) {
        AccessControlPolicy[] policies = acMgr.getPolicies(principal);
        assertNotNull(policies);
        assertEquals(0, policies.length);
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

AccessControlPolicy (javax.jcr.security.AccessControlPolicy)182 Test (org.junit.Test)67 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)66 AccessControlManager (javax.jcr.security.AccessControlManager)62 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)52 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)52 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)49 AccessControlEntry (javax.jcr.security.AccessControlEntry)40 AccessControlList (javax.jcr.security.AccessControlList)32 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)32 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)28 Privilege (javax.jcr.security.Privilege)28 Principal (java.security.Principal)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)23 NodeImpl (org.apache.jackrabbit.core.NodeImpl)18 TestACL (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL)18 Node (javax.jcr.Node)17 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)17 Root (org.apache.jackrabbit.oak.api.Root)14 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)14