Search in sources :

Example 66 with AccessControlManager

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

the class ConcurrentReadAccessControlledTreeTest2 method addPolicy.

private void addPolicy(Node node) throws RepositoryException {
    AccessControlManager acMgr = node.getSession().getAccessControlManager();
    String path = node.getPath();
    int level = 0;
    if (node.isNodeType(AccessControlConstants.NT_REP_POLICY)) {
        level = 1;
    } else if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
        level = 2;
    } else if (node.isNodeType(AccessControlConstants.NT_REP_RESTRICTIONS)) {
        level = 3;
    }
    if (level > 0) {
        path = Text.getRelativeParent(path, level);
    }
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(node.getSession(), path);
    if (acl != null) {
        Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
        for (Principal principal : principals) {
            acl.addAccessControlEntry(principal, privileges);
        }
        acMgr.setPolicy(path, acl);
        adminSession.save();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Principal(java.security.Principal)

Example 67 with AccessControlManager

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

the class ConcurrentReadSinglePolicyTreeTest method visitingNode.

@Override
protected void visitingNode(Node node, int i) throws RepositoryException {
    super.visitingNode(node, i);
    String path = node.getPath();
    AccessControlManager acMgr = node.getSession().getAccessControlManager();
    if (testRoot.getPath().equals(path)) {
        JackrabbitAccessControlList policy = AccessControlUtils.getAccessControlList(acMgr, path);
        if (policy != null) {
            policy.addEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ), true);
        }
        acMgr.setPolicy(path, policy);
    } else if (!path.contains("rep:policy")) {
        for (AccessControlPolicy policy : acMgr.getPolicies(path)) {
            if (policy instanceof JackrabbitAccessControlList) {
                acMgr.removePolicy(path, policy);
            }
        }
    }
    node.getSession().save();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 68 with AccessControlManager

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

the class AbstractRemoveMembersByIdTest method removeExistingMemberWithoutAccess.

Set<String> removeExistingMemberWithoutAccess() throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testGroup.getPath());
    if (acl != null) {
        if (acl.addEntry(getTestUser().getPrincipal(), privilegesFromNames(PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_USER_MANAGEMENT), true)) {
            acMgr.setPolicy(testGroup.getPath(), acl);
            root.commit();
        }
    }
    String userId = getTestUser().getID();
    ContentSession testSession = null;
    try {
        testSession = login(new SimpleCredentials(userId, userId.toCharArray()));
        Root testRoot = testSession.getLatestRoot();
        assertFalse(testRoot.getTree(memberGroup.getPath()).exists());
        Group gr = getUserManager(testRoot).getAuthorizable(testGroup.getID(), Group.class);
        Set<String> failed = gr.removeMembers(memberGroup.getID());
        testRoot.commit();
        return failed;
    } finally {
        if (testSession != null) {
            testSession.close();
        }
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 69 with AccessControlManager

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

the class L4_PrivilegesAndPermissionsTest method testRemoveNodes.

public void testRemoveNodes() throws Exception {
    // EXERCISE: setup the correct set of privileges such that the test passes
    superuser.save();
    Map<String, Boolean> pathHasPermissionMap = ImmutableMap.of(testRootNode.getPath(), false, childPath, false, grandChildPath, true);
    Session userSession = createTestSession();
    for (String path : pathHasPermissionMap.keySet()) {
        boolean expectedHasPermission = pathHasPermissionMap.get(path);
        assertEquals(expectedHasPermission, userSession.hasPermission(path, Session.ACTION_REMOVE));
    }
    AccessControlManager acMgr = userSession.getAccessControlManager();
    assertFalse(acMgr.hasPrivileges(childPath, new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_REMOVE_NODE) }));
    userSession.getNode(grandChildPath).remove();
    userSession.save();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 70 with AccessControlManager

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

the class L7_PrivilegeDiscoveryTest method testGetPrivileges.

public void testGetPrivileges() throws Exception {
    AccessControlManager acMgr = userSession.getAccessControlManager();
    // EXERCISE
    Set<Privilege> expected = null;
    Privilege[] testRootPrivs = acMgr.getPrivileges(testRoot);
    assertEquals(expected, ImmutableSet.copyOf(testRootPrivs));
    // EXERCISE
    expected = null;
    Privilege[] privs = acMgr.getPrivileges(testPath);
    assertEquals(expected, ImmutableSet.copyOf(privs));
    // EXERCISE
    expected = null;
    Privilege[] childPrivs = acMgr.getPrivileges(childPath);
    assertEquals(expected, ImmutableSet.copyOf(childPrivs));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) Privilege(javax.jcr.security.Privilege)

Aggregations

AccessControlManager (javax.jcr.security.AccessControlManager)192 Privilege (javax.jcr.security.Privilege)82 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)77 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)62 Session (javax.jcr.Session)47 Test (org.junit.Test)45 AccessControlEntry (javax.jcr.security.AccessControlEntry)39 Node (javax.jcr.Node)33 AccessControlList (javax.jcr.security.AccessControlList)32 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)32 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)23 Principal (java.security.Principal)22 Value (javax.jcr.Value)17 HashMap (java.util.HashMap)14 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)14 Group (org.apache.jackrabbit.api.security.user.Group)14 ValueFactory (javax.jcr.ValueFactory)13 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)13 NodeImpl (org.apache.jackrabbit.core.NodeImpl)13 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)12