private static NodeUtil createACE(NodeUtil acl, String aceName, String ntName, String principalName, String... privilegeNames) throws AccessDeniedException { NodeUtil ace = acl.addChild(aceName, ntName); ace.setString(REP_PRINCIPAL_NAME, principalName); ace.setNames(REP_PRIVILEGES, privilegeNames); return ace; }
/** * Combination of {@link #getChild(String)} and {@link #addChild(String, String)} * in case no tree exists with the specified name. * * @param name The name of the child item. * @param primaryTypeName The name of the primary node type. * @return The new child node with the specified name and primary type. * @throws AccessDeniedException If the child does not exist after creation. */ @NotNull public NodeUtil getOrAddChild(String name, String primaryTypeName) throws AccessDeniedException { NodeUtil child = getChild(name); return (child != null) ? child : addChild(name, primaryTypeName); }
private NodeUtil createAcl() throws AccessDeniedException { NodeUtil testRoot = getTestRoot(); testRoot.setNames(JcrConstants.JCR_MIXINTYPES, MIX_REP_ACCESS_CONTROLLABLE); NodeUtil acl = testRoot.addChild(REP_POLICY, NT_REP_ACL); NodeUtil ace = createACE(acl, aceName, NT_REP_GRANT_ACE, testPrincipal.getName(), PrivilegeConstants.JCR_READ); ace.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); return acl; }
private Tree getAceTree(Restriction... restrictions) throws Exception { NodeUtil rootNode = new NodeUtil(root.getTree("/")); NodeUtil tmp = rootNode.addChild("testRoot", JcrConstants.NT_UNSTRUCTURED); Tree ace = tmp.addChild("rep:policy", NT_REP_ACL).addChild("ace0", NT_REP_GRANT_ACE).getTree(); restrictionProvider.writeRestrictions(tmp.getTree().getPath(), ace, ImmutableSet.copyOf(restrictions)); return ace; }
@Test public void testNotIsDeclaredMemberMissingMembersProperty() throws Exception { Tree grTree = getTree(createGroup()); Tree memberTree = getTree(createUser()); NodeUtil memberList = new NodeUtil(grTree).addChild(REP_MEMBERS_LIST, NT_REP_MEMBER_REFERENCES_LIST); memberList.addChild("member1", NT_REP_MEMBER_REFERENCES).setStrings(REP_MEMBERS, getContentID("another")); assertFalse(mp.isDeclaredMember(grTree, memberTree)); }
@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(); }
@Test public void testRemoveExternalPrincipalNamesAsSystem() throws Exception { Root systemRoot = getSystemRoot(); NodeUtil n = new NodeUtil(systemRoot.getTree(externalUserPath)); // removal with system root must succeed n.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES); systemRoot.commit(); }
@Test public void testModifyExternalPrincipalNamesAsSystem() throws Exception { Root systemRoot = getSystemRoot(); NodeUtil n = new NodeUtil(systemRoot.getTree(externalUserPath)); // changing with system root must succeed n.setStrings(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES, "principalNames"); systemRoot.commit(); }
private NodeUtil getTestRoot() { return new NodeUtil(root.getTree(testPath)); }
@NotNull Tree createTokenTree(@NotNull TokenInfo base, @NotNull NodeUtil parent, @NotNull String ntName) throws AccessDeniedException { Tree tokenTree = getTokenTree(base); Tree tree = parent.addChild("token", ntName).getTree(); tree.setProperty(tokenTree.getProperty(JcrConstants.JCR_UUID)); tree.setProperty(tokenTree.getProperty(TOKEN_ATTRIBUTE_KEY)); tree.setProperty(tokenTree.getProperty(TOKEN_ATTRIBUTE_EXPIRY)); return tree; } }
public void setName(String propertyName, String value) { String oakName = getOakName(value); tree.setProperty(propertyName, oakName, NAME); }
@Test public void testAdmininistrativePermissions() throws AccessDeniedException, CommitFailedException { // EXERCISE walk through the read access Tree rootTree = root.getTree("/"); // EXERCISE walk through the add + remove NodeUtil child = new NodeUtil(rootTree).addChild("test", NodeTypeConstants.NT_OAK_UNSTRUCTURED); root.commit(); child.getTree().remove(); root.commit(); }
@Test public void testIsDeclaredMemberMissingMembersProperty() throws Exception { Tree grTree = getTree(createGroup()); Tree memberTree = getTree(createUser()); NodeUtil memberList = new NodeUtil(grTree).addChild(REP_MEMBERS_LIST, NT_REP_MEMBER_REFERENCES_LIST); memberList.addChild("member1", NT_REP_MEMBER_REFERENCES).setStrings(REP_MEMBERS, getContentID(memberTree)); assertTrue(mp.isDeclaredMember(grTree, memberTree)); }
@Override @Test public void testRemoveRepExternalIdAsSystem() throws Exception { Root systemRoot = getSystemRoot(); NodeUtil n = new NodeUtil(systemRoot.getTree(externalUserPath)); n.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); systemRoot.commit(); } }
@Override @Test public void testRepExternalIdMultiple() throws Exception { Root systemRoot = getSystemRoot(); NodeUtil n = new NodeUtil(systemRoot.getTree(testUserPath)); n.setStrings(ExternalIdentityConstants.REP_EXTERNAL_ID, "id", "id2"); systemRoot.commit(); }
@NotNull public NodeUtil getParent() { return new NodeUtil(tree.getParent(), mapper); }
@Nullable public NodeUtil getChild(String name) { Tree child = tree.getChild(name); return child.exists() ? new NodeUtil(child, mapper) : null; }
@Override public void before() throws Exception { super.before(); node = new NodeUtil(root.getTree(SUPPORTED_PATH)); }
@Override public void before() throws Exception { super.before(); node = new NodeUtil(root.getTree("/")); }