Search in sources :

Example 1 with CompositePattern

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

the class CompositeRestrictionProviderTest method testGetRestrictionPattern.

@Test
public void testGetRestrictionPattern() throws Exception {
    NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
    NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS);
    rNode.setString(REP_GLOB, "*");
    assertFalse(provider.getPattern("/test", aceNode.getTree()) instanceof CompositePattern);
    rNode.setBoolean("boolean", true);
    rNode.setValues("longs", new Value[] { vf.createValue(10), vf.createValue(290) });
    assertTrue(provider.getPattern("/test", rNode.getTree()) instanceof CompositePattern);
}
Also used : CompositePattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with CompositePattern

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

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

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern 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)

Aggregations

AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 CompositePattern (org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern)4 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)4 Test (org.junit.Test)4 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)3 Map (java.util.Map)3 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)3 Tree (org.apache.jackrabbit.oak.api.Tree)3 RestrictionPattern (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern)3