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