Search in sources :

Example 56 with AccessControlList

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

the class CugEvaluationTest method testHasAllPrivileges2.

@Test
public void testHasAllPrivileges2() throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/content/a");
    acl.addAccessControlEntry(testGroupPrincipal, privilegesFromNames(PrivilegeConstants.JCR_ALL));
    acMgr.setPolicy("/content/a", acl);
    root.commit();
    // testGroup
    PermissionProvider pp = createPermissionProvider(testGroupPrincipal);
    assertFalse(pp.hasPrivileges(root.getTree("/content"), PrivilegeConstants.JCR_ALL));
    assertTrue(pp.hasPrivileges(root.getTree("/content/a"), PrivilegeConstants.JCR_ALL));
    assertTrue(pp.hasPrivileges(root.getTree("/content/a/b"), PrivilegeConstants.JCR_ALL));
    assertFalse(pp.hasPrivileges(root.getTree("/content/a/b/c"), PrivilegeConstants.JCR_ALL));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) PermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider) Test(org.junit.Test)

Example 57 with AccessControlList

use of javax.jcr.security.AccessControlList 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 58 with AccessControlList

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

the class AccessControlManagerImplTest method testGetEffectiveModifiedPolicy.

@Test
public void testGetEffectiveModifiedPolicy() throws Exception {
    ACL acl = setupPolicy(testPath);
    AccessControlEntry[] aces = acl.getAccessControlEntries();
    root.commit();
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(PrivilegeConstants.JCR_VERSION_MANAGEMENT));
    acMgr.setPolicy(testPath, acl);
    AccessControlPolicy[] policies = acMgr.getEffectivePolicies(testPath);
    assertNotNull(policies);
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof AccessControlList);
    AccessControlEntry[] effectiveAces = ((AccessControlList) policies[0]).getAccessControlEntries();
    assertArrayEquals(aces, effectiveAces);
    assertFalse(Arrays.equals(effectiveAces, acl.getAccessControlEntries()));
}
Also used : JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AccessControlList(javax.jcr.security.AccessControlList) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlEntry(javax.jcr.security.AccessControlEntry) TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 59 with AccessControlList

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

the class VersionTreePermissionTest method before.

@Override
public void before() throws Exception {
    super.before();
    NodeUtil testNode = new NodeUtil(root.getTree("/")).addChild("test", NT_OAK_UNSTRUCTURED);
    testNode.addChild("a", NT_OAK_UNSTRUCTURED).addChild("b", NT_OAK_UNSTRUCTURED).addChild("c", NT_OAK_UNSTRUCTURED);
    TreeUtil.addMixin(testNode.getTree(), MIX_VERSIONABLE, root.getTree(NODE_TYPES_PATH), null);
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/test");
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, PrivilegeConstants.JCR_READ));
    acMgr.setPolicy("/test", acl);
    root.commit();
    // create a structure in the version storage
    testNode.setBoolean(JCR_ISCHECKEDOUT, false);
    root.commit();
    testNode.setBoolean(JCR_ISCHECKEDOUT, true);
    root.commit();
    testTree = testNode.getTree();
    vMgr = ReadOnlyVersionManager.getInstance(root, NamePathMapper.DEFAULT);
    pp = getConfig(AuthorizationConfiguration.class).getPermissionProvider(root, root.getContentSession().getWorkspaceName(), ImmutableSet.<Principal>of(EveryonePrincipal.getInstance()));
    assertTrue(pp instanceof PermissionProviderImpl);
    vpField = VersionTreePermission.class.getDeclaredField("versionablePermission");
    vpField.setAccessible(true);
    Class cls = Class.forName(CompiledPermissionImpl.class.getName() + "$TreePermissionImpl");
    tpImplTree = cls.getDeclaredField("tree");
    tpImplTree.setAccessible(true);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Example 60 with AccessControlList

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

the class L6_AccessControlContentTest method testRepoPolicy.

public void testRepoPolicy() throws RepositoryException {
    AccessControlList repoAcl = AccessControlUtils.getAccessControlList(acMgr, null);
    assertNotNull(repoAcl);
    repoAcl.addAccessControlEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, PrivilegeConstants.JCR_NAMESPACE_MANAGEMENT));
    acMgr.setPolicy(null, repoAcl);
    // EXERCISE retrieve the policy node and verify the expected name, primary type and child items
    String policyPath = null;
    Node aclNode = superuser.getNode(policyPath);
    String expectedName = null;
    assertEquals(expectedName, aclNode.getName());
    String expectedPrimaryTypeName = null;
    assertEquals(expectedPrimaryTypeName, aclNode.getPrimaryNodeType().getName());
    NodeIterator aclChildren = aclNode.getNodes();
// EXERCISE verify the correct number + expected nature of the children.
// EXERCISE: can you also identify which mixins are being involved and where they got applied?
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node)

Aggregations

AccessControlList (javax.jcr.security.AccessControlList)97 AccessControlEntry (javax.jcr.security.AccessControlEntry)49 AccessControlManager (javax.jcr.security.AccessControlManager)49 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)39 Privilege (javax.jcr.security.Privilege)25 Node (javax.jcr.Node)17 RepositoryException (javax.jcr.RepositoryException)17 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)17 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)15 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)15 Test (org.junit.Test)13 Principal (java.security.Principal)12 AccessDeniedException (javax.jcr.AccessDeniedException)12 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 AccessControlException (javax.jcr.security.AccessControlException)6 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 NodeImpl (org.apache.jackrabbit.core.NodeImpl)6 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)5 AccessControlException (java.security.AccessControlException)5