Search in sources :

Example 76 with AccessControlManager

use of javax.jcr.security.AccessControlManager 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 77 with AccessControlManager

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

the class AccessControlManagementTest method testAclReferingToRemovedPrincipal.

@Test
public void testAclReferingToRemovedPrincipal() throws Exception {
    JackrabbitAccessControlList acl = allow(path, repWritePrivileges);
    String acPath = acl.getPath();
    // remove the test user
    testUser.remove();
    superuser.save();
    testUser = null;
    // try to retrieve the acl again
    Session s = getHelper().getSuperuserSession();
    try {
        AccessControlManager acMgr = getAccessControlManager(s);
        acMgr.getPolicies(acPath);
    } finally {
        s.logout();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Session(javax.jcr.Session) Test(org.junit.Test)

Example 78 with AccessControlManager

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

the class ImportIgnoreTest method testImportUnknownPrincipal.

@Test
public void testImportUnknownPrincipal() throws Exception {
    try {
        runImport();
        AccessControlManager acMgr = adminSession.getAccessControlManager();
        AccessControlPolicy[] policies = acMgr.getPolicies(target.getPath());
        assertEquals(1, policies.length);
        assertEquals(0, ((AccessControlList) policies[0]).getAccessControlEntries().length);
    } finally {
        adminSession.refresh(false);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Test(org.junit.Test)

Example 79 with AccessControlManager

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

the class OpvIgnoreTest method addIgnoredChild.

private void addIgnoredChild(@Nonnull Node node) throws Exception {
    AccessControlManager acMgr = superuser.getAccessControlManager();
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, node.getPath());
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ));
    acMgr.setPolicy(acl.getPath(), acl);
    superuser.save();
    Node c = node.getNode(AccessControlConstants.REP_POLICY);
    assertEquals(OnParentVersionAction.IGNORE, c.getDefinition().getOnParentVersion());
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Node(javax.jcr.Node) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 80 with AccessControlManager

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

the class AuthorizationContextTest method createAcl.

private void createAcl(@Nullable String path, String... privilegeNames) throws RepositoryException {
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, path);
    assertNotNull(acl);
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(privilegeNames));
    acMgr.setPolicy(path, acl);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList)

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