@Test(expected = CommitFailedException.class) public void testInvalidAggregation() throws Exception { Root before = adminSession.getLatestRoot(); Tree defsBefore = before.getTree(PRIVILEGES_PATH); defsBefore.getChild(REP_READ_NODES).remove(); Tree privDefs = root.getTree(PRIVILEGES_PATH); Tree newPriv = TreeUtil.addChild(privDefs, "newPriv", NT_REP_PRIVILEGE); PrivilegeBits.getInstance(PrivilegeBits.BUILT_IN.get(JCR_READ), PrivilegeBits.BUILT_IN.get(JCR_ADD_CHILD_NODES)).writeTo(newPriv); newPriv.setProperty(REP_AGGREGATES, ImmutableList.of(JCR_READ, JCR_ADD_CHILD_NODES), Type.NAMES); TreeProvider tp = mock(TreeProvider.class); when(tp.createReadOnlyTree(any(Tree.class), anyString(), any(NodeState.class))).thenReturn(newPriv); try { PrivilegeValidator validator = new PrivilegeValidator(before, root, tp); validator.childNodeAdded("newPriv", getTreeProvider().asNodeState(newPriv)); } catch (CommitFailedException e) { throw assertCommitFailed(e, 47); } }
@Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { if (isPrivilegeDefinition(after)) { Tree parent = getPrivilegesTree(rootBefore); if (NamespaceConstants.RESERVED_PREFIXES.contains(Text.getNamespacePrefix(name))) { String msg = "Failed to register custom privilege: Definition uses reserved namespace: " + name; throw new CommitFailedException("Privilege", 1, msg); } Tree tree = treeProvider.createReadOnlyTree(parent, name, after); validateDefinition(tree); } return null; }
PrivilegeValidator extends DefaultValidator implements PrivilegeConstants { @Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { if (isPrivilegeDefinition(after)) { Tree parent = getPrivilegesTree(rootBefore); if (NamespaceConstants.RESERVED_PREFIXES.contains(Text.getNamespacePrefix(name))) { String msg = "Failed to register custom privilege: Definition uses reserved namespace: " + name; throw new CommitFailedException("Privilege", 1, msg); } Tree tree = treeProvider.createReadOnlyTree(parent, name, after); validateDefinition(tree); } return null; } }
PrivilegeValidator extends DefaultValidator implements PrivilegeConstants { @Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { if (isPrivilegeDefinition(after)) { Tree parent = getPrivilegesTree(rootBefore); if (NamespaceConstants.RESERVED_PREFIXES.contains(Text.getNamespacePrefix(name))) { String msg = "Failed to register custom privilege: Definition uses reserved namespace: " + name; throw new CommitFailedException("Privilege", 1, msg); } Tree tree = treeProvider.createReadOnlyTree(parent, name, after); validateDefinition(tree); } return null; } PrivilegeValidator(@NotNull Root before, @NotNull Root after, @NotNull TreeProvider treeProvider); }
PrivilegeValidator extends DefaultValidator implements PrivilegeConstants { @Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { if (isPrivilegeDefinition(after)) { Tree parent = getPrivilegesTree(rootBefore); if (NamespaceConstants.RESERVED_PREFIXES.contains(Text.getNamespacePrefix(name))) { String msg = "Failed to register custom privilege: Definition uses reserved namespace: " + name; throw new CommitFailedException("Privilege", 1, msg); } Tree tree = treeProvider.createReadOnlyTree(parent, name, after); validateDefinition(tree); } return null; } PrivilegeValidator(@NotNull Root before, @NotNull Root after, @NotNull TreeProvider treeProvider); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before); }
PrivilegeValidator extends DefaultValidator implements PrivilegeConstants { @Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { if (isPrivilegeDefinition(after)) { Tree parent = getPrivilegesTree(rootBefore); if (NamespaceConstants.RESERVED_PREFIXES.contains(Text.getNamespacePrefix(name))) { String msg = "Failed to register custom privilege: Definition uses reserved namespace: " + name; throw new CommitFailedException("Privilege", 1, msg); } Tree tree = treeProvider.createReadOnlyTree(parent, name, after); validateDefinition(tree); } return null; } PrivilegeValidator(@NotNull Root before, @NotNull Root after, @NotNull TreeProvider treeProvider); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before);  }