Search in sources :

Example 81 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class Jr2CompatibilityTest method after.

@Override
@After
public void after() throws Exception {
    try {
        AccessControlManager acMgr = getAccessControlManager(root);
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/");
        if (acl != null) {
            boolean modified = false;
            for (AccessControlEntry entry : acl.getAccessControlEntries()) {
                if (entry.getPrincipal().equals(getTestUser().getPrincipal())) {
                    acl.removeAccessControlEntry(entry);
                    modified = true;
                }
            }
            if (modified) {
                acMgr.setPolicy("/", acl);
                root.commit();
            }
        }
    } finally {
        super.after();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) After(org.junit.After)

Example 82 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class ImmutableACLTest method testEquals.

@Test
public void testEquals() throws Exception {
    RestrictionProvider rp = getRestrictionProvider();
    ACE ace1 = createEntry(testPrincipal, PrivilegeBits.BUILT_IN.get(PrivilegeConstants.JCR_VERSION_MANAGEMENT), false);
    ACE ace2 = createEntry(true, PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES);
    ACE ace2b = createEntry(true, PrivilegeConstants.REP_READ_NODES, PrivilegeConstants.REP_READ_PROPERTIES, PrivilegeConstants.JCR_ADD_CHILD_NODES);
    JackrabbitAccessControlList acl = createACL(ace1, ace2);
    assertTrue(acl instanceof ImmutableACL);
    assertEquals(acl, acl);
    JackrabbitAccessControlList repoAcl = createACL((String) null, ace1, ace2);
    assertTrue(repoAcl instanceof ImmutableACL);
    assertEquals(repoAcl, repoAcl);
    assertEquals(acl, createACL(ace1, ace2));
    assertEquals(acl, createACL(ace1, ace2b));
    assertEquals(repoAcl, createACL((String) null, ace1, ace2b));
    assertFalse(acl.equals(createACL(ace2, ace1)));
    assertFalse(acl.equals(repoAcl));
    assertFalse(acl.equals(createEmptyACL()));
    assertFalse(acl.equals(createACL("/anotherPath", ace1, ace2)));
    assertFalse(acl.equals(new TestACL("/anotherPath", rp, getNamePathMapper(), ace1, ace2)));
    assertFalse(acl.equals(new TestACL("/anotherPath", rp, getNamePathMapper(), ace1, ace2)));
    assertFalse(acl.equals(new TestACL("/anotherPath", rp, getNamePathMapper())));
    assertFalse(acl.equals(new TestACL(getTestPath(), rp, getNamePathMapper(), ace1, ace2)));
}
Also used : RestrictionProvider(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Test(org.junit.Test)

Example 83 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class ImmutableACLTest method testImmutable.

@Test
public void testImmutable() throws Exception {
    List<JackrabbitAccessControlEntry> entries = new ArrayList();
    entries.add(createEntry(true, PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES));
    entries.add(createEntry(false, PrivilegeConstants.JCR_LIFECYCLE_MANAGEMENT));
    JackrabbitAccessControlList acl = createACL(entries);
    assertFalse(acl.isEmpty());
    assertEquals(2, acl.size());
    assertEquals(getTestPath(), acl.getPath());
    assertImmutable(acl);
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) ArrayList(java.util.ArrayList) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Test(org.junit.Test)

Example 84 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class ImmutableACLTest method testEmptyIsImmutable.

@Test
public void testEmptyIsImmutable() throws Exception {
    JackrabbitAccessControlList acl = createEmptyACL();
    assertTrue(acl.isEmpty());
    assertEquals(0, acl.size());
    assertEquals(getTestPath(), acl.getPath());
    assertImmutable(acl);
}
Also used : JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Test(org.junit.Test)

Example 85 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList in project jackrabbit-oak by apache.

the class L3_PrecedenceRulesTest method testPrecedenceOfUserPrincipals.

public void testPrecedenceOfUserPrincipals() throws RepositoryException {
    Privilege[] readPrivs = AccessControlUtils.privilegesFromNames(superuser, Privilege.JCR_READ);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
    acl.addEntry(testPrincipal, readPrivs, false);
    acl.addEntry(testGroupPrincipal, readPrivs, true);
    superuser.getAccessControlManager().setPolicy(acl.getPath(), acl);
    superuser.save();
    // EXERCISE what is the expected result?
    testSession.refresh(false);
    // EXERCISE
    Boolean canRead = null;
    assertEquals(canRead.booleanValue(), testSession.nodeExists(testRoot));
    assertEquals(canRead.booleanValue(), testSession.nodeExists(childPath));
// EXERCISE: now change the permission setup such that the testSession has read access
// EXERCISE: how many ways to you find to achieve this?
}
Also used : Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Aggregations

JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)165 AccessControlManager (javax.jcr.security.AccessControlManager)75 Privilege (javax.jcr.security.Privilege)56 AccessControlEntry (javax.jcr.security.AccessControlEntry)46 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)46 Test (org.junit.Test)40 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)32 Principal (java.security.Principal)29 Node (javax.jcr.Node)23 Session (javax.jcr.Session)17 Value (javax.jcr.Value)17 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15 Tree (org.apache.jackrabbit.oak.api.Tree)15 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)13 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)12 AccessControlException (javax.jcr.security.AccessControlException)10 NodeImpl (org.apache.jackrabbit.core.NodeImpl)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 Group (org.apache.jackrabbit.api.security.user.Group)8