Search in sources :

Example 1 with RestrictionPattern

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

the class RestrictionProviderImplTest method testGetPatternForAllSupported.

@Test
public void testGetPatternForAllSupported() 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, prefixes, 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();
    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) 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 2 with RestrictionPattern

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern 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 3 with RestrictionPattern

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

the class SlingRestrictionProviderImplTest method testGetPatternFromTreeResourceTypesWithDescendants.

@Test
public void testGetPatternFromTreeResourceTypesWithDescendants() {
    doReturn(restrictionProperty).when(restrictionNodeTree).getProperty(SlingRestrictionProviderImpl.SLING_RESOURCE_TYPES_WITH_DESCENDANTS);
    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;
    assertTrue(resourceTypePattern.isMatchChildren());
    assertEquals(TEST_PATH, resourceTypePattern.getLimitedToPath());
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) Test(org.junit.Test)

Example 4 with RestrictionPattern

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern 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 5 with RestrictionPattern

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

the class RestrictionProviderImpl method getPattern.

//------------------------------------------------< RestrictionProvider >---
@Nonnull
@Override
public RestrictionPattern getPattern(String oakPath, @Nonnull Tree tree) {
    if (oakPath == null) {
        return RestrictionPattern.EMPTY;
    } else {
        List<RestrictionPattern> patterns = new ArrayList<RestrictionPattern>(NUMBER_OF_DEFINITIONS);
        PropertyState glob = tree.getProperty(REP_GLOB);
        if (glob != null) {
            patterns.add(GlobPattern.create(oakPath, glob.getValue(Type.STRING)));
        }
        PropertyState ntNames = tree.getProperty(REP_NT_NAMES);
        if (ntNames != null) {
            patterns.add(new NodeTypePattern(ntNames.getValue(Type.NAMES)));
        }
        PropertyState prefixes = tree.getProperty(REP_PREFIXES);
        if (prefixes != null) {
            patterns.add(new PrefixPattern(prefixes.getValue(Type.STRINGS)));
        }
        PropertyState itemNames = tree.getProperty(REP_ITEM_NAMES);
        if (itemNames != null) {
            patterns.add(new ItemNamePattern(itemNames.getValue(Type.NAMES)));
        }
        return CompositePattern.create(patterns);
    }
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) ArrayList(java.util.ArrayList) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

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