public boolean canRemoveNode(String s) { boolean canRemoveNd = true; Iterator it = ntd.getNodeDefinitionTemplates().iterator(); NodeDefinition nd = null; while (it.hasNext()) { nd = (NodeDefinitionTemplate) it.next(); if ((nd != null) && (nd.getName().equals(s)) && (nd.isProtected() || nd.isMandatory())) { canRemoveNd = false; return canRemoveNd; } } return canRemoveNd; }
protected void removeChildNodes(final Node node) throws RepositoryException { for (Node child : new NodeIterable(node.getNodes())) { if (!child.getDefinition().isProtected()) { child.remove(); } } }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
@Override public void endNode(NodeInfo nodeInfo) throws RepositoryException { Tree parent = parents.pop(); if (parent == null) { if (pnImporter != null) { pnImporter.endChildInfo(); } } else if (getDefinition(parent).isProtected()) { if (pnImporter != null) { pnImporter.end(parent); // and reset the pnImporter field waiting for the next protected // parent -> selecting again from available importers pnImporter = null; } } idLookup.rememberImportedUUIDs(parent); }
@Override public boolean canAddChildNode(String childNodeName) { // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { return !definition.isProtected() && definition.getDefaultPrimaryType() != null; } } return false; }
@Override public void endNode(NodeInfo nodeInfo) throws RepositoryException { Tree parent = parents.pop(); if (parent == null) { if (pnImporter != null) { pnImporter.endChildInfo(); } } else if (getDefinition(parent).isProtected()) { if (pnImporter != null) { pnImporter.end(parent); // and reset the pnImporter field waiting for the next protected // parent -> selecting again from available importers pnImporter = null; } } idLookup.rememberImportedUUIDs(parent); }
/** * {@inheritDoc} */ public void endNode(NodeInfo nodeInfo) throws RepositoryException { NodeImpl parent = parents.pop(); if (parent == null) { if (pnImporter != null) { pnImporter.endChildInfo(); } } else if (parent.getDefinition().isProtected()) { if (pnImporter != null) { pnImporter.end(parent); // and reset the pnImporter field waiting for the next protected // parent -> selecting again from available importers pnImporter = null; } } }
@Override public void endNode(NodeInfo nodeInfo) throws RepositoryException { Tree parent = parents.pop(); if (parent == null) { if (pnImporter != null) { pnImporter.endChildInfo(); } } else if (getDefinition(parent).isProtected()) { if (pnImporter != null) { pnImporter.end(parent); // and reset the pnImporter field waiting for the next protected // parent -> selecting again from available importers pnImporter = null; } } idLookup.rememberImportedUUIDs(parent); }
@Override public boolean canAddChildNode(String childNodeName) { // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { return !definition.isProtected() && definition.getDefaultPrimaryType() != null; } } return false; }
/** * {@inheritDoc} */ public void endNode(NodeInfo nodeInfo) throws RepositoryException { NodeImpl parent = parents.pop(); if (parent == null) { if (pnImporter != null) { pnImporter.endChildInfo(); } } else if (parent.getDefinition().isProtected()) { if (pnImporter != null) { pnImporter.end(parent); // and reset the pnImporter field waiting for the next protected // parent -> selecting again from available importers pnImporter = null; } } }
@Override public boolean canAddChildNode(String childNodeName) { // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { return !definition.isProtected() && definition.getDefaultPrimaryType() != null; } } return false; }
/** * Throw a {@link ConstraintViolationException} if this node is protected (based on the its node definition). * * @throws ConstraintViolationException if this node's definition indicates that the node is protected * @throws RepositoryException if an error occurs retrieving the definition for this node */ private void checkNotProtected() throws ConstraintViolationException, RepositoryException { if (getDefinition().isProtected()) { throw new ConstraintViolationException(JcrI18n.cannotRemoveItemWithProtectedDefinition.text(getPath())); } }
/** * Throw a {@link ConstraintViolationException} if this node is protected (based on the its node definition). * * @throws ConstraintViolationException if this node's definition indicates that the node is protected * @throws RepositoryException if an error occurs retrieving the definition for this node */ private void checkNotProtected() throws ConstraintViolationException, RepositoryException { if (getDefinition().isProtected()) { throw new ConstraintViolationException(JcrI18n.cannotRemoveItemWithProtectedDefinition.text(getPath())); } }
@Test public void shouldNotAllowAddingMixinToProtectedNodes() throws Exception { Node rootNode = session.getRootNode(); Node systemNode = rootNode.getNode("jcr:system"); assertThat(systemNode.getDefinition().isProtected(), is(true)); assertThat(systemNode.canAddMixin("mix:versionable"), is(false)); }
private void clear(final Node node) throws RepositoryException { for (Property property : new PropertyIterable(node.getProperties())) { if (!property.getDefinition().isProtected()) { property.remove(); } } for (Node child : new NodeIterable(node.getNodes())) { if (!child.getDefinition().isProtected()) { child.remove(); } } for (NodeType nodeType : node.getMixinNodeTypes()) { if (!nodeType.isNodeType(JcrConstants.MIX_VERSIONABLE)) { node.removeMixin(nodeType.getName()); } } }
@Override public void checkMandatoryItems(Tree tree) throws ConstraintViolationException { for (NodeType nodeType : nodeTypes.values()) { for (PropertyDefinition pd : nodeType.getPropertyDefinitions()) { String name = pd.getName(); if (pd.isMandatory() && !pd.isProtected() && tree.getProperty(name) == null) { throw new ConstraintViolationException( "Property '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) { String name = nd.getName(); if (nd.isMandatory() && !nd.isProtected() && !tree.hasChild(name)) { throw new ConstraintViolationException( "Node '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } } }
public void testNonProtectedNode() throws Exception { if (!testRootNode.getDefinition().isProtected()) { ProtectedNodeImporter piImporter = createImporter(); piImporter.init(sImpl, sImpl, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, null); assertFalse(piImporter.start((NodeImpl) testRootNode)); } else { throw new NotExecutableException(); } }
@Test public void testAccessControlItemsAreProtectedByNodeTypeDefinition() throws Exception { ReadOnlyNodeTypeManager ntMgr = ReadOnlyNodeTypeManager.getInstance(root, NamePathMapper.DEFAULT); Tree aTree = root.getTree("/test/a"); Tree policyTree = aTree.getChild(ThreeRolesConstants.REP_3_ROLES_POLICY); NodeDefinition policyDef = ntMgr.getDefinition(aTree, policyTree); assertTrue(policyDef.isProtected()); for (String propName : new String[] {ThreeRolesConstants.REP_READERS, ThreeRolesConstants.REP_EDITORS, ThreeRolesConstants.REP_OWNERS}) { PropertyDefinition propDef = ntMgr.getDefinition(policyTree, policyTree.getProperty(propName), true); assertTrue(propDef.isProtected()); } Repository jcrRepository = buildJcrRepository(); // EXERCISE: test protected status of items using JCR API calls // EXERCISE: verify that the protected status of the access control content is enforced // ... write your code here }
@Test public void testUserNode() throws Exception { Tree pwdTree = root.getTree(user.getPath()).getChild(UserConstants.REP_PWD); assertTrue(pwdTree.exists()); assertTrue(TreeUtil.isNodeType(pwdTree, UserConstants.NT_REP_PASSWORD, root.getTree(NodeTypeConstants.NODE_TYPES_PATH))); ReadOnlyNodeTypeManager ntMgr = ReadOnlyNodeTypeManager.getInstance(root, getNamePathMapper()); assertTrue(ntMgr.getDefinition(pwdTree.getParent(), pwdTree).isProtected()); PropertyState property = pwdTree.getProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED); assertNotNull(property); assertEquals(Type.LONG, property.getType()); assertTrue(property.getValue(Type.LONG, 0) > 0); // protected properties must not be exposed by User#hasProperty assertFalse(user.hasProperty(UserConstants.REP_PWD + "/" + UserConstants.REP_PASSWORD_LAST_MODIFIED)); }