Search in sources :

Example 6 with RestrictionPattern

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

the class RestrictionProviderImplTest method testGetRestrictionPattern.

@Test
public void testGetRestrictionPattern() throws Exception {
    Map<PropertyState, RestrictionPattern> map = newHashMap();
    map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content"));
    List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE);
    map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames));
    NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED);
    Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree();
    // test restrictions individually
    for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) {
        restrictions.setProperty(entry.getKey());
        RestrictionPattern pattern = provider.getPattern("/testPath", restrictions);
        assertEquals(entry.getValue(), pattern);
        restrictions.removeProperty(entry.getKey().getName());
    }
    // test combination on multiple restrictions
    for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) {
        restrictions.setProperty(entry.getKey());
    }
    RestrictionPattern pattern = provider.getPattern("/testPath", restrictions);
    assertTrue(pattern instanceof CompositePattern);
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) CompositePattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern) Tree(org.apache.jackrabbit.oak.api.Tree) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 7 with RestrictionPattern

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

the class RestrictionProviderImplTest method testGetPatternFromRestrictions.

@Test
public void testGetPatternFromRestrictions() throws Exception {
    Map<PropertyState, RestrictionPattern> map = newHashMap();
    map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content"));
    List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE);
    map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames));
    List<String> prefixes = ImmutableList.of("rep", "jcr");
    map.put(PropertyStates.createProperty(REP_PREFIXES, prefixes, Type.STRINGS), new PrefixPattern(prefixes));
    List<String> itemNames = ImmutableList.of("abc", "jcr:primaryType");
    map.put(PropertyStates.createProperty(REP_ITEM_NAMES, itemNames, Type.NAMES), new ItemNamePattern(itemNames));
    NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED);
    Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree();
    // test restrictions individually
    for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) {
        restrictions.setProperty(entry.getKey());
        RestrictionPattern pattern = provider.getPattern("/testPath", provider.readRestrictions("/testPath", tree.getTree()));
        assertEquals(entry.getValue(), pattern);
        restrictions.removeProperty(entry.getKey().getName());
    }
    // test combination on multiple restrictions
    for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) {
        restrictions.setProperty(entry.getKey());
    }
    RestrictionPattern pattern = provider.getPattern("/testPath", provider.readRestrictions("/testPath", tree.getTree()));
    assertTrue(pattern instanceof CompositePattern);
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) CompositePattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern) Tree(org.apache.jackrabbit.oak.api.Tree) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with RestrictionPattern

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

the class SlingRestrictionProviderImplTest method testGetPatternFromTreeResourceTypes.

@Test
public void testGetPatternFromTreeResourceTypes() {
    doReturn(restrictionProperty).when(restrictionNodeTree).getProperty(SlingRestrictionProviderImpl.SLING_RESOURCE_TYPES);
    doReturn(Arrays.asList(RESOURCE_TYPE1, RESOURCE_TYPE2)).when(restrictionProperty).getValue(Type.STRINGS);
    slingRestrictionProviderImpl = new SlingRestrictionProviderImpl();
    RestrictionPattern pattern = slingRestrictionProviderImpl.getPattern(TEST_PATH, restrictionNodeTree);
    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) Test(org.junit.Test)

Aggregations

RestrictionPattern (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern)8 Test (org.junit.Test)7 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)3 Map (java.util.Map)3 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 Tree (org.apache.jackrabbit.oak.api.Tree)3 CompositePattern (org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern)3 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)3 Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)2 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1