Search in sources :

Example 61 with JackrabbitAccessControlList

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

the class L3_PrecedenceRulesTest method testAceOrder.

public void testAceOrder() throws RepositoryException {
    assertFalse(testSession.nodeExists(testRoot));
    Privilege[] readPrivs = AccessControlUtils.privilegesFromNames(superuser, Privilege.JCR_READ);
    // EXERCISE: fix the permission setup such that the test success without dropping either ACE
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
    acl.addEntry(testGroupPrincipal, readPrivs, true);
    acl.addEntry(EveryonePrincipal.getInstance(), readPrivs, false);
    superuser.getAccessControlManager().setPolicy(acl.getPath(), acl);
    superuser.save();
    testSession.refresh(false);
    assertTrue(testSession.nodeExists(testRoot));
    assertTrue(testSession.propertyExists(propertyPath));
}
Also used : Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 62 with JackrabbitAccessControlList

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

the class ObservationQueueTest method prepareTestData.

@Override
protected void prepareTestData(Session s) throws RepositoryException {
    UserManager uMgr = ((JackrabbitSession) s).getUserManager();
    User user = uMgr.createUser(USER, PASSWORD);
    s.save();
    AccessControlManager acMgr = s.getAccessControlManager();
    JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, "/");
    tmpl.addEntry(user.getPrincipal(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) }, true, Collections.<String, Value>emptyMap());
    acMgr.setPolicy(tmpl.getPath(), tmpl);
    s.save();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 63 with JackrabbitAccessControlList

use of org.apache.jackrabbit.api.security.JackrabbitAccessControlList 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 64 with JackrabbitAccessControlList

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

the class RandomizedReadTest method setupContent.

@Override
protected void setupContent() throws Exception {
    for (JackrabbitSession session : writeSessions) {
        Node root = session.getRootNode();
        Node n1 = root.addNode("n1");
        Node n3 = n1.addNode("n3");
        n1.addNode("n4");
        n1.addNode("n5");
        n3.addNode("n6");
        n3.addNode("n7");
        n3.addNode("n8");
        n3.addNode("n9");
        root.addNode("n2");
        Principal principal = getTestPrincipal(session);
        AccessControlManager acm = session.getAccessControlManager();
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acm, "/");
        acl.addEntry(principal, AccessControlUtils.privilegesFromNames(acm, PrivilegeConstants.JCR_READ), true);
        acm.setPolicy("/", acl);
        session.save();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Principal(java.security.Principal)

Example 65 with JackrabbitAccessControlList

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

the class AbstractEvaluationTest method modify.

protected JackrabbitAccessControlList modify(String path, Principal principal, Privilege[] privileges, boolean isAllow, Map<String, Value> restrictions, Map<String, Value[]> mvRestrictions) throws Exception {
    // remember for restore during tearDown
    rememberForRestore(path);
    JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, path);
    tmpl.addEntry(principal, privileges, isAllow, restrictions, mvRestrictions);
    acMgr.setPolicy(tmpl.getPath(), tmpl);
    superuser.save();
    testSession.refresh(false);
    return tmpl;
}
Also used : 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