private int getOPV(NodeBuilder node, PropertyState property) throws RepositoryException { if (property.getName().charAt(0) == ':') { // FIXME: handle child order properly return OnParentVersionAction.COPY; } else { return ntMgr.getDefinition(TreeFactory.createReadOnlyTree(node.getNodeState()), property, false).getOnParentVersion(); } }
private int getOPV(NodeBuilder node, PropertyState property) throws RepositoryException { if (property.getName().charAt(0) == ':') { // FIXME: handle child order properly return OnParentVersionAction.COPY; } else { return ntMgr.getDefinition(TreeFactory.createReadOnlyTree(node.getNodeState()), property, false).getOnParentVersion(); } }
private int getOPV(NodeBuilder node, PropertyState property) throws RepositoryException { if (property.getName().charAt(0) == ':') { // FIXME: handle child order properly return OnParentVersionAction.COPY; } else { return ntMgr.getDefinition(TreeFactory.createReadOnlyTree(node.getNodeState()), property, false).getOnParentVersion(); } }
private void checkProtectedProperty(@NotNull Tree parent, @NotNull PropertyState property) throws RepositoryException { ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager(); PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, false); if (def.isProtected()) { throw new ConstraintViolationException( "Attempt to set an protected property " + property.getName()); } }
private void checkProtectedProperty(@NotNull Tree parent, @NotNull PropertyState property) throws RepositoryException { ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager(); PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, false); if (def.isProtected()) { throw new ConstraintViolationException( "Attempt to set an protected property " + property.getName()); } }
private void checkProtectedProperty(@Nonnull Tree parent, @Nonnull PropertyState property) throws RepositoryException { ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager(); PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, false); if (def.isProtected()) { throw new ConstraintViolationException( "Attempt to set an protected property " + property.getName()); } }
private boolean isIgnoreOnOPV() throws CommitFailedException { if (this.parent != null) { try { NodeDefinition definition = this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createTree(parent.node), this.name); return definition.getOnParentVersion() == OnParentVersionAction.IGNORE; } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } return false; }
private boolean isIgnoreOnOPV() throws CommitFailedException { if (this.parent != null) { try { NodeDefinition definition = this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createTree(parent.node), this.name); return definition.getOnParentVersion() == OnParentVersionAction.IGNORE; } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } return false; }
private boolean isIgnoreOnOPV() throws CommitFailedException { if (this.parent != null) { try { NodeDefinition definition = this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createTree(parent.node), this.name); return definition.getOnParentVersion() == OnParentVersionAction.IGNORE; } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } return false; }
private int getOPV(PropertyState property) throws CommitFailedException { try { return this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createReadOnlyTree(this.node.getNodeState()), property, false).getOnParentVersion(); } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } }
private int getOPV(PropertyState property) throws CommitFailedException { try { return this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createReadOnlyTree(this.node.getNodeState()), property, false).getOnParentVersion(); } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } }
private int getOPV(PropertyState property) throws CommitFailedException { try { return this.vMgr.getNodeTypeManager().getDefinition(TreeFactory.createReadOnlyTree(this.node.getNodeState()), property, false).getOnParentVersion(); } catch (Exception e) { throw new CommitFailedException(CommitFailedException.VERSION, VersionExceptionCode.UNEXPECTED_REPOSITORY_EXCEPTION.ordinal(), e.getMessage()); } } }
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException { // ignore hidden tree if (childName.startsWith(":")) { return IGNORE; } ImmutableTree parentTree = new ImmutableTree(parent.getNodeState()); NodeState childState; if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) { // need to translate into a regular node to get proper OPV value NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME); builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES); childState = builder.getNodeState(); } else { childState = child.getNodeState(); } ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState); return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion(); }
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException { // ignore hidden tree if (childName.startsWith(":")) { return IGNORE; } ImmutableTree parentTree = new ImmutableTree(parent.getNodeState()); NodeState childState; if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) { // need to translate into a regular node to get proper OPV value NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME); builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES); childState = builder.getNodeState(); } else { childState = child.getNodeState(); } ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState); return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion(); }
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException { // ignore hidden tree if (childName.startsWith(":")) { return IGNORE; } ImmutableTree parentTree = new ImmutableTree(parent.getNodeState()); NodeState childState; if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) { // need to translate into a regular node to get proper OPV value NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE); builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME); builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES); childState = builder.getNodeState(); } else { childState = child.getNodeState(); } ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState); return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion(); }
private void resetToDefaultValue(NodeBuilder dest, PropertyState p) throws RepositoryException { Tree tree = TreeFactory.createReadOnlyTree(dest.getNodeState()); PropertyDefinition def = ntMgr.getDefinition(tree, p, true); Value[] values = def.getDefaultValues(); if (values != null) { if (p.isArray()) { p = PropertyStates.createProperty(p.getName(), values); dest.setProperty(p); } else if (values.length > 0) { p = PropertyStates.createProperty(p.getName(), values[0]); dest.setProperty(p); } } }
private void resetToDefaultValue(NodeBuilder dest, PropertyState p) throws RepositoryException { Tree tree = TreeFactory.createReadOnlyTree(dest.getNodeState()); PropertyDefinition def = ntMgr.getDefinition(tree, p, true); Value[] values = def.getDefaultValues(); if (values != null) { if (p.isArray()) { p = PropertyStates.createProperty(p.getName(), values); dest.setProperty(p); } else if (values.length > 0) { p = PropertyStates.createProperty(p.getName(), values[0]); dest.setProperty(p); } } }
private void resetToDefaultValue(NodeBuilder dest, PropertyState p) throws RepositoryException { Tree tree = TreeFactory.createReadOnlyTree(dest.getNodeState()); PropertyDefinition def = ntMgr.getDefinition(tree, p, true); Value[] values = def.getDefaultValues(); if (values != null) { if (p.isArray()) { p = PropertyStates.createProperty(p.getName(), values); dest.setProperty(p); } else if (values.length > 0) { p = PropertyStates.createProperty(p.getName(), values[0]); dest.setProperty(p); } } }
@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)); }