Search in sources :

Example 21 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil 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 22 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class PermissionTest method before.

@Before
@Override
public void before() throws Exception {
    super.before();
    NodeUtil rootNode = new NodeUtil(root.getTree("/"));
    NodeUtil testRootNode = rootNode.addChild("testRoot", NT_UNSTRUCTURED);
    NodeUtil a = testRootNode.addChild("a", NT_UNSTRUCTURED);
    NodeUtil b = a.addChild("b", NT_UNSTRUCTURED);
    NodeUtil c = b.addChild("c", NT_UNSTRUCTURED);
    NodeUtil d = c.addChild("d", NT_UNSTRUCTURED);
    d.addChild("e", NT_UNSTRUCTURED);
    root.commit();
    testPrincipal = getTestUser().getPrincipal();
}
Also used : NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Before(org.junit.Before)

Example 23 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class ItemNameRestrictionTest method before.

@Override
public void before() throws Exception {
    super.before();
    Tree rootTree = root.getTree("/");
    NodeUtil f = new NodeUtil(rootTree).getOrAddTree("a/d/b/e/c/f", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    NodeUtil c = f.getParent();
    c.setString("prop", "value");
    c.setString("a", "value");
    testPrincipal = getTestUser().getPrincipal();
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/a");
    vf = new ValueFactoryImpl(root, NamePathMapper.DEFAULT);
    acl.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_ADD_PROPERTIES, PrivilegeConstants.JCR_ADD_CHILD_NODES, PrivilegeConstants.JCR_REMOVE_NODE), true, Collections.<String, Value>emptyMap(), ImmutableMap.of(AccessControlConstants.REP_ITEM_NAMES, new Value[] { vf.createValue("a", PropertyType.NAME), vf.createValue("b", PropertyType.NAME), vf.createValue("c", PropertyType.NAME) }));
    acMgr.setPolicy(acl.getPath(), acl);
    UserManager uMgr = getUserManager(root);
    testGroup = uMgr.createGroup("testGroup" + UUID.randomUUID());
    root.commit();
    testSession = createTestSession();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) Value(javax.jcr.Value) Tree(org.apache.jackrabbit.oak.api.Tree) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Example 24 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class ExternalIdentityValidatorTest method testAddExternalPrincipalNamesAsSystem.

@Test
public void testAddExternalPrincipalNamesAsSystem() throws Exception {
    Root systemRoot = getSystemRoot();
    NodeUtil n = new NodeUtil(systemRoot.getTree(testUserPath));
    n.setString(ExternalIdentityConstants.REP_EXTERNAL_ID, "externalId");
    n.setStrings(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, "principalName");
    systemRoot.commit();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 25 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class ExternalIdentityValidatorTest method testExternalPrincipalNamesSingle.

@Test
public void testExternalPrincipalNamesSingle() throws Exception {
    Root systemRoot = getSystemRoot();
    try {
        NodeUtil n = new NodeUtil(systemRoot.getTree(testUserPath));
        n.setString(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, "id");
        systemRoot.commit();
        fail("Creating rep:externalPrincipalNames as single STRING property must be detected.");
    } catch (CommitFailedException e) {
        // success
        assertEquals(71, e.getCode());
    } finally {
        systemRoot.refresh();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Aggregations

NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)183 Test (org.junit.Test)149 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)74 Tree (org.apache.jackrabbit.oak.api.Tree)67 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)59 Root (org.apache.jackrabbit.oak.api.Root)28 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)14 Before (org.junit.Before)14 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)13 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)13 AccessControlManager (javax.jcr.security.AccessControlManager)12 Principal (java.security.Principal)10 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)8 AccessControlException (javax.jcr.security.AccessControlException)7 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)7 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)6 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 Privilege (javax.jcr.security.Privilege)5 Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)5 AccessControlList (javax.jcr.security.AccessControlList)4