Search in sources :

Example 11 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class CompositeRestrictionProviderTest method testReadRestrictions.

@Test
public void testReadRestrictions() throws Exception {
    NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
    aceNode.setBoolean("boolean", true);
    aceNode.setValues("longs", new Value[] { vf.createValue(10), vf.createValue(290) });
    aceNode.setString(REP_GLOB, "*");
    // empty array
    aceNode.setNames(REP_NT_NAMES);
    aceNode.setString("invalid", "val");
    aceNode.setStrings("invalid2", "val1", "val2", "val3");
    Set<Restriction> restrictions = provider.readRestrictions("/test", aceNode.getTree());
    assertEquals(4, restrictions.size());
    for (Restriction r : restrictions) {
        String name = r.getDefinition().getName();
        if (!supported.contains(name)) {
            fail("read unsupported restriction");
        }
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 12 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project sling by apache.

the class SlingRestrictionProviderImplTest method testGetPatternFromRestrictionsResourceTypesWithDescendants.

@Test
public void testGetPatternFromRestrictionsResourceTypesWithDescendants() {
    doReturn(SlingRestrictionProviderImpl.SLING_RESOURCE_TYPES_WITH_DESCENDANTS).when(definition).getName();
    doReturn(Arrays.asList(RESOURCE_TYPE1, RESOURCE_TYPE2)).when(restrictionProperty).getValue(Type.STRINGS);
    slingRestrictionProviderImpl = new SlingRestrictionProviderImpl();
    RestrictionPattern pattern = slingRestrictionProviderImpl.getPattern(TEST_PATH, new HashSet<Restriction>(Arrays.asList(restriction)));
    assertTrue(pattern instanceof ResourceTypePattern);
    ResourceTypePattern resourceTypePattern = (ResourceTypePattern) pattern;
    assertTrue(resourceTypePattern.isMatchChildren());
    assertEquals(TEST_PATH, resourceTypePattern.getLimitedToPath());
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Test(org.junit.Test)

Example 13 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project sling by apache.

the class SlingRestrictionProviderImplTest method testGetPatternFromRestrictionsResourceTypes.

@Test
public void testGetPatternFromRestrictionsResourceTypes() {
    doReturn(SlingRestrictionProviderImpl.SLING_RESOURCE_TYPES).when(definition).getName();
    doReturn(Arrays.asList(RESOURCE_TYPE1, RESOURCE_TYPE2)).when(restrictionProperty).getValue(Type.STRINGS);
    slingRestrictionProviderImpl = new SlingRestrictionProviderImpl();
    RestrictionPattern pattern = slingRestrictionProviderImpl.getPattern(TEST_PATH, new HashSet<Restriction>(Arrays.asList(restriction)));
    assertTrue(pattern instanceof ResourceTypePattern);
    ResourceTypePattern resourceTypePattern = (ResourceTypePattern) pattern;
    assertFalse(resourceTypePattern.isMatchChildren());
    assertEquals(TEST_PATH, resourceTypePattern.getLimitedToPath());
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Test(org.junit.Test)

Example 14 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class EntryTest method testGetRestrictionForMultiValued2.

/**
 * @since OAK 1.0: support for multi-value restrictions
 */
@Test
public void testGetRestrictionForMultiValued2() throws Exception {
    // single value restriction stored in multi-value property
    Restriction singleNameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, new Value[] { nameValue });
    ACE ace = createEntry(ImmutableSet.of(singleNameRestr));
    Value val = ace.getRestriction(AccessControlConstants.REP_NT_NAMES);
    assertEquals(nameValue, val);
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) Value(javax.jcr.Value) Test(org.junit.Test)

Example 15 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class EntryTest method testGetRestrictionForMultiValued.

/**
 * @since OAK 1.0: support for multi-value restrictions
 */
@Test(expected = ValueFormatException.class)
public void testGetRestrictionForMultiValued() throws Exception {
    // multivalued restriction
    Restriction nameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, nameValues);
    ACE ace = createEntry(ImmutableSet.of(nameRestr));
    ace.getRestriction(AccessControlConstants.REP_NT_NAMES);
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) Test(org.junit.Test)

Aggregations

Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)39 Test (org.junit.Test)33 Value (javax.jcr.Value)12 ACE (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 AccessControlException (javax.jcr.security.AccessControlException)6 Tree (org.apache.jackrabbit.oak.api.Tree)6 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)5 Nonnull (javax.annotation.Nonnull)2 RestrictionImpl (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionImpl)2 RestrictionPattern (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AccessControlEntry (javax.jcr.security.AccessControlEntry)1 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)1 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)1 Privilege (javax.jcr.security.Privilege)1 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 ImmutableACL (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ImmutableACL)1