Search in sources :

Example 21 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testSetPrincipalPolicy.

//-----------------------------------------------< setPrincipalPolicy() >---
@Test
public void testSetPrincipalPolicy() throws Exception {
    JackrabbitAccessControlPolicy[] applicable = acMgr.getApplicablePolicies(testPrincipal);
    assertNotNull(applicable);
    assertEquals(1, applicable.length);
    assertTrue(applicable[0] instanceof ACL);
    ACL acl = (ACL) applicable[0];
    Value pathValue = getValueFactory().createValue(testPath, PropertyType.PATH);
    assertTrue(acl.addEntry(testPrincipal, testPrivileges, true, Collections.singletonMap(REP_NODE_PATH, pathValue)));
    acMgr.setPolicy(acl.getPath(), acl);
    root.commit();
    Root root2 = adminSession.getLatestRoot();
    AccessControlPolicy[] policies = getAccessControlManager(root2).getPolicies(testPath);
    assertEquals(1, policies.length);
    assertEquals(1, ((ACL) policies[0]).getAccessControlEntries().length);
    policies = getAccessControlManager(root2).getPolicies(testPrincipal);
    assertEquals(1, policies.length);
    assertArrayEquals(acl.getAccessControlEntries(), ((ACL) policies[0]).getAccessControlEntries());
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Root(org.apache.jackrabbit.oak.api.Root) Value(javax.jcr.Value) TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 22 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testRemovePolicyAcContent.

@Test
public void testRemovePolicyAcContent() throws Exception {
    for (String acPath : getAcContentPaths()) {
        try {
            AccessControlPolicy acl = createPolicy(acPath);
            acMgr.removePolicy(acPath, acl);
            fail("Removing access control policy to access control content should fail");
        } catch (AccessControlException e) {
        // success
        }
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlException(javax.jcr.security.AccessControlException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 23 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testGetEffectivePoliciesByPrincipal.

@Test
public void testGetEffectivePoliciesByPrincipal() throws Exception {
    // no ACLs containing entries for the specified principals
    // -> no effective policies expected
    Set<Set<Principal>> principalSets = new HashSet<Set<Principal>>();
    principalSets.add(Collections.singleton(testPrincipal));
    principalSets.add(Collections.<Principal>singleton(EveryonePrincipal.getInstance()));
    principalSets.add(ImmutableSet.of(testPrincipal, EveryonePrincipal.getInstance()));
    for (Set<Principal> principals : principalSets) {
        AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
        assertNotNull(policies);
        assertEquals(0, policies.length);
    }
    setupPolicy(testPath);
    // changes not yet persisted -> no effecitve policies found for testprincipal
    for (Set<Principal> principals : principalSets) {
        AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
        assertNotNull(policies);
        assertEquals(0, policies.length);
    }
    root.commit();
    // after persisting changes -> the policy must be found
    for (Set<Principal> principals : principalSets) {
        AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
        assertNotNull(policies);
        if (principals.contains(testPrincipal)) {
            assertEquals(1, policies.length);
        } else {
            assertEquals(0, policies.length);
        }
    }
    NodeUtil child = new NodeUtil(root.getTree(testPath)).addChild("child", JcrConstants.NT_UNSTRUCTURED);
    String childPath = child.getTree().getPath();
    setupPolicy(childPath);
    // changes not yet persisted -> no effecitve policies found for testprincipal
    for (Set<Principal> principals : principalSets) {
        AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
        assertNotNull(policies);
        if (principals.contains(testPrincipal)) {
            assertEquals(1, policies.length);
        } else {
            assertEquals(0, policies.length);
        }
    }
    root.commit();
    // after persisting changes -> the policy must be found
    for (Set<Principal> principals : principalSets) {
        AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
        assertNotNull(policies);
        if (principals.contains(testPrincipal)) {
            assertEquals(2, policies.length);
        } else {
            assertEquals(0, policies.length);
        }
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 24 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testSetPolicyInvalidPath.

@Test
public void testSetPolicyInvalidPath() throws Exception {
    for (String invalid : getInvalidPaths()) {
        try {
            AccessControlPolicy acl = createPolicy(invalid);
            acMgr.setPolicy(invalid, acl);
            fail("Setting access control policy with invalid path should fail");
        } catch (RepositoryException e) {
        // success
        }
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) RepositoryException(javax.jcr.RepositoryException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 25 with AccessControlPolicy

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

the class AccessControlManagerImplTest method testTestSessionGetPolicies.

@Test
public void testTestSessionGetPolicies() throws Exception {
    setupPolicy(testPath);
    root.commit();
    Root testRoot = getTestRoot();
    testRoot.refresh();
    JackrabbitAccessControlManager testAcMgr = getTestAccessControlManager();
    PrincipalManager testPrincipalMgr = getPrincipalManager(testRoot);
    List<Principal> principals = ImmutableList.of(testPrincipal, EveryonePrincipal.getInstance());
    for (Principal principal : principals) {
        if (testPrincipalMgr.hasPrincipal(principal.getName())) {
            // testRoot can't read access control content -> doesn't see
            // the existing policies and creates a new applicable policy.
            AccessControlPolicy[] policies = testAcMgr.getPolicies(principal);
            assertNotNull(policies);
            assertEquals(0, policies.length);
        } else {
            // testRoot can't read principal -> no policies for that principal
            assertEquals(0, testAcMgr.getPolicies(principal).length);
        }
    }
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Root(org.apache.jackrabbit.oak.api.Root) 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