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);
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations