Search in sources :

Example 51 with AccessControlManager

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

the class TreePermissionImplTest method testCanReadProperties.

@Test
public void testCanReadProperties() throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/test");
    acl.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.JCR_READ), true);
    acl.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.REP_READ_PROPERTIES), false);
    acMgr.setPolicy("/test", acl);
    root.commit();
    TreePermission tp = getTreePermission("/test");
    assertFalse(tp.canReadProperties());
    assertTrue(tp.canRead());
    assertFalse(tp.canReadProperties());
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) TreePermission(org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 52 with AccessControlManager

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

the class PermissionStoreTest method before.

@Override
public void before() throws Exception {
    super.before();
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/");
    if (acl != null) {
        acl.addEntry(getTestUser().getPrincipal(), privilegesFromNames(PrivilegeConstants.JCR_ALL), true);
    }
    acMgr.setPolicy("/", acl);
    root.commit();
    testSession = createTestSession();
    testRoot = testSession.getLatestRoot();
    acConfig = getSecurityProvider().getConfiguration(AuthorizationConfiguration.class);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 53 with AccessControlManager

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

the class RepoPolicyTreePermissionTest method after.

@Override
public void after() throws Exception {
    try {
        AccessControlManager acMgr = getAccessControlManager(root);
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, null);
        if (acl != null) {
            acMgr.removePolicy(null, acl);
            root.commit();
        }
        accessSession.close();
        noAccessSession.close();
    } finally {
        super.after();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 54 with AccessControlManager

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

the class VersionStorageTest method after.

@Override
public void after() throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/");
    for (AccessControlEntry ace : acl.getAccessControlEntries()) {
        if (testPrincipal.equals(ace.getPrincipal())) {
            acl.removeAccessControlEntry(ace);
        }
    }
    acMgr.setPolicy("/", acl);
    root.commit();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 55 with AccessControlManager

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

the class PermissionHookTest method testReorderAddAndRemoveAces2.

/**
     * ACE    :  0   1   2   3   4   5   6   7
     * Before :  tp  ev  p0  p1  p2  p3
     * After  :      ev      p2  p1  p3  p4  p5
     */
@Test
public void testReorderAddAndRemoveAces2() throws Exception {
    createPrincipals();
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testPath);
    for (int i = 0; i < 4; i++) {
        acl.addAccessControlEntry(principals.get(i), privilegesFromNames(JCR_READ));
    }
    acMgr.setPolicy(testPath, acl);
    root.commit();
    AccessControlEntry[] aces = acl.getAccessControlEntries();
    acl.removeAccessControlEntry(aces[0]);
    acl.removeAccessControlEntry(aces[2]);
    acl.orderBefore(aces[4], aces[3]);
    acl.addAccessControlEntry(principals.get(4), privilegesFromNames(JCR_READ));
    acl.addAccessControlEntry(principals.get(5), privilegesFromNames(JCR_READ));
    acMgr.setPolicy(testPath, acl);
    root.commit();
    Tree entry = getEntry(principals.get(2), testPath, 1);
    assertIndex(1, entry);
    entry = getEntry(principals.get(1), testPath, 2);
    assertIndex(2, entry);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlEntry(javax.jcr.security.AccessControlEntry) Tree(org.apache.jackrabbit.oak.api.Tree) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

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