Search in sources :

Example 26 with PrivilegeBits

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.

the class PrivilegeBitsProviderTest method testAggregation.

@Test
public void testAggregation() throws RepositoryException {
    PrivilegeBits writeBits = bitsProvider.getBits(JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE, JCR_MODIFY_PROPERTIES);
    Set<String> names = bitsProvider.getPrivilegeNames(writeBits);
    assertEquals(1, names.size());
    assertEquals(JCR_WRITE, names.iterator().next());
}
Also used : PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 27 with PrivilegeBits

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.

the class PrivilegeBitsProviderTest method testRedundantAggregation.

@Test
public void testRedundantAggregation() throws RepositoryException {
    PrivilegeBits writeBits = bitsProvider.getBits(REP_WRITE);
    Set<String> names = bitsProvider.getPrivilegeNames(writeBits);
    assertEquals(1, names.size());
    assertEquals(REP_WRITE, names.iterator().next());
    writeBits = bitsProvider.getBits(REP_WRITE, JCR_WRITE);
    names = bitsProvider.getPrivilegeNames(writeBits);
    assertEquals(1, names.size());
    assertEquals(REP_WRITE, names.iterator().next());
}
Also used : PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 28 with PrivilegeBits

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.

the class PrivilegeBitsProviderTest method testGetPrivilegeNames.

@Test
public void testGetPrivilegeNames() throws RepositoryException {
    PrivilegeBits bits = bitsProvider.getBits(JCR_READ_ACCESS_CONTROL);
    Set<String> names = bitsProvider.getPrivilegeNames(bits);
    assertEquals(1, names.size());
    assertEquals(JCR_READ_ACCESS_CONTROL, names.iterator().next());
}
Also used : PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 29 with PrivilegeBits

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.

the class PrivilegeUpgradeTest method verifyCustomPrivilegeBits.

@Test
public void verifyCustomPrivilegeBits() throws Exception {
    JackrabbitSession session = createAdminSession();
    try {
        Node privilegeRoot = session.getNode(PrivilegeConstants.PRIVILEGES_PATH);
        Node testPrivilegeNode = privilegeRoot.getNode("test:privilege");
        long l = getLong(testPrivilegeNode);
        PrivilegeBits pb = readBits(testPrivilegeNode, PrivilegeConstants.REP_BITS);
        Node testPrivilege2Node = privilegeRoot.getNode("test:privilege2");
        long l2 = getLong(testPrivilege2Node);
        PrivilegeBits pb2 = readBits(testPrivilege2Node, PrivilegeConstants.REP_BITS);
        PrivilegeBits nextExpected;
        if (l < l2) {
            assertEquals(PrivilegeBits.NEXT_AFTER_BUILT_INS, pb);
            assertEquals(pb.nextBits(), pb2);
            nextExpected = pb2.nextBits();
        } else {
            assertEquals(PrivilegeBits.NEXT_AFTER_BUILT_INS, pb2);
            assertEquals(pb2.nextBits(), pb);
            nextExpected = pb.nextBits();
        }
        // make sure the next-value has been properly set
        PrivilegeBits nextBits = readBits(privilegeRoot, PrivilegeConstants.REP_NEXT);
        assertEquals(nextExpected, nextBits);
        Node testAggregateNode = privilegeRoot.getNode("test:aggregate");
        PrivilegeBits aggrPb = readBits(testAggregateNode, PrivilegeConstants.REP_BITS);
        PrivilegeBits expected = PrivilegeBits.getInstance(PrivilegeBits.BUILT_IN.get(PrivilegeConstants.JCR_READ), pb).unmodifiable();
        assertEquals(expected, aggrPb);
        Node testAggregate2Node = privilegeRoot.getNode("test:aggregate2");
        PrivilegeBits aggr2Pb = readBits(testAggregate2Node, PrivilegeConstants.REP_BITS);
        PrivilegeBits expected2 = PrivilegeBits.getInstance(aggrPb, pb2).unmodifiable();
        assertEquals(expected2, aggr2Pb);
    } finally {
        session.logout();
    }
}
Also used : Node(javax.jcr.Node) PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Aggregations

PrivilegeBits (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits)29 Test (org.junit.Test)18 Tree (org.apache.jackrabbit.oak.api.Tree)9 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)8 PrivilegeBitsProvider (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBitsProvider)6 Nonnull (javax.annotation.Nonnull)5 Principal (java.security.Principal)2 Nullable (javax.annotation.Nullable)2 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)2 ImmutableTree (org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree)2 ACE (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE)2 AggregatedPermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Node (javax.jcr.Node)1 Privilege (javax.jcr.security.Privilege)1