Search in sources :

Example 56 with AccessControlEntry

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

the class JackrabbitAccessControlListTest method testRemoveEntry.

@Test
public void testRemoveEntry() throws NotExecutableException, RepositoryException {
    Principal princ = getValidPrincipal();
    Privilege[] grPriv = privilegesFromName("rep:write");
    acl.addEntry(princ, grPriv, true, Collections.<String, Value>emptyMap());
    AccessControlEntry[] entries = acl.getAccessControlEntries();
    int length = entries.length;
    assertTrue("Grant was both successful -> at least 1 entry.", length > 0);
    for (AccessControlEntry entry : entries) {
        acl.removeAccessControlEntry(entry);
        length = length - 1;
        assertEquals(length, acl.size());
        assertEquals(length, acl.getAccessControlEntries().length);
    }
    assertTrue(acl.isEmpty());
    assertEquals(0, acl.size());
    assertEquals(0, acl.getAccessControlEntries().length);
}
Also used : AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal) Test(org.junit.Test) AbstractAccessControlTest(org.apache.jackrabbit.test.api.security.AbstractAccessControlTest)

Example 57 with AccessControlEntry

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

the class JackrabbitAccessControlListTest method testAddEntry.

@Test
public void testAddEntry() throws NotExecutableException, RepositoryException {
    List<AccessControlEntry> entriesBefore = Arrays.asList(acl.getAccessControlEntries());
    if (acl.addEntry(testPrincipal, testPrivileges, true, Collections.<String, Value>emptyMap())) {
        AccessControlEntry[] entries = acl.getAccessControlEntries();
        AccessControlEntry ace = null;
        for (AccessControlEntry entry : entries) {
            if (testPrincipal.equals(entry.getPrincipal())) {
                ace = entry;
            }
        }
        assertNotNull("addEntry was successful -> expected entry for tesPrincipal.", ace);
        assertTrue("addEntry was successful -> at least 1 entry.", entries.length > 0);
    } else {
        AccessControlEntry[] entries = acl.getAccessControlEntries();
        assertEquals("Grant ALL not successful -> entries must not have changed.", entriesBefore, Arrays.asList(entries));
    }
}
Also used : AccessControlEntry(javax.jcr.security.AccessControlEntry) Test(org.junit.Test) AbstractAccessControlTest(org.apache.jackrabbit.test.api.security.AbstractAccessControlTest)

Example 58 with AccessControlEntry

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

the class ReadVersionContentTest method tearDown.

@Override
@After
protected void tearDown() throws Exception {
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(superuser, VersionConstants.VERSION_STORE_PATH);
    if (acl != null) {
        for (AccessControlEntry entry : acl.getAccessControlEntries()) {
            if (entry.getPrincipal().equals(testUser.getPrincipal())) {
                acl.removeAccessControlEntry(entry);
            }
        }
        acMgr.setPolicy(VersionConstants.VERSION_STORE_PATH, acl);
        superuser.save();
    }
}
Also used : AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) After(org.junit.After)

Example 59 with AccessControlEntry

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

the class ImportBesteffortTest method testImportUnknownPrincipal.

@Test
public void testImportUnknownPrincipal() throws Exception {
    runImport();
    AccessControlManager acMgr = adminSession.getAccessControlManager();
    AccessControlPolicy[] policies = acMgr.getPolicies(target.getPath());
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof JackrabbitAccessControlList);
    AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
    assertEquals(1, entries.length);
    AccessControlEntry entry = entries[0];
    assertEquals("unknownprincipal", entry.getPrincipal().getName());
    assertEquals(1, entry.getPrivileges().length);
    assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
    if (entry instanceof JackrabbitAccessControlEntry) {
        assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Test(org.junit.Test)

Example 60 with AccessControlEntry

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

the class RandomizedReadTest method clearContent.

@Override
protected void clearContent() throws Exception {
    for (JackrabbitSession session : writeSessions) {
        Node root = session.getRootNode();
        if (root.hasNode("n1")) {
            root.getNode("n1").remove();
        }
        if (root.hasNode("n2")) {
            root.getNode("n2").remove();
        }
        AccessControlList acl = AccessControlUtils.getAccessControlList(session, "/");
        if (acl != null) {
            boolean modified = false;
            for (AccessControlEntry ace : acl.getAccessControlEntries()) {
                if (getTestPrincipal(session).equals(ace.getPrincipal())) {
                    acl.removeAccessControlEntry(ace);
                    modified = true;
                }
            }
            if (modified) {
                session.getAccessControlManager().setPolicy("/", acl);
            }
        }
        session.save();
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Node(javax.jcr.Node) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

AccessControlEntry (javax.jcr.security.AccessControlEntry)126 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)50 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)50 Privilege (javax.jcr.security.Privilege)47 AccessControlManager (javax.jcr.security.AccessControlManager)39 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)39 AccessControlList (javax.jcr.security.AccessControlList)38 Test (org.junit.Test)29 Principal (java.security.Principal)28 NodeImpl (org.apache.jackrabbit.core.NodeImpl)13 ArrayList (java.util.ArrayList)12 Node (javax.jcr.Node)12 Value (javax.jcr.Value)10 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 RepositoryException (javax.jcr.RepositoryException)8 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)8 ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)8