From 6b49666d4a399ca9256d0504fc6801b386c6201f Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Mon, 15 Jan 2024 10:40:46 -0800 Subject: [PATCH] bug fixes for immutable and invalid node property handling --- cadc-vos-server/build.gradle | 2 +- .../org/opencadc/vospace/server/Utils.java | 20 ++++++++++++------- .../server/actions/CreateNodeAction.java | 3 ++- .../server/actions/UpdateNodeAction.java | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cadc-vos-server/build.gradle b/cadc-vos-server/build.gradle index 7440f787..3e7b37dc 100644 --- a/cadc-vos-server/build.gradle +++ b/cadc-vos-server/build.gradle @@ -16,7 +16,7 @@ sourceCompatibility = 1.8 group = 'org.opencadc' -version = '2.0.6' +version = '2.0.7' description = 'OpenCADC VOSpace server' def git_url = 'https://github.com/opencadc/vos' diff --git a/cadc-vos-server/src/main/java/org/opencadc/vospace/server/Utils.java b/cadc-vos-server/src/main/java/org/opencadc/vospace/server/Utils.java index 59efae02..19640736 100644 --- a/cadc-vos-server/src/main/java/org/opencadc/vospace/server/Utils.java +++ b/cadc-vos-server/src/main/java/org/opencadc/vospace/server/Utils.java @@ -80,6 +80,7 @@ import org.opencadc.vospace.ContainerNode; import org.opencadc.vospace.Node; import org.opencadc.vospace.NodeProperty; +import org.opencadc.vospace.VOS; /** * Utility methods @@ -158,17 +159,22 @@ public static String getPath(Node node) { * @param newProps set of new Node Properties to be used for the update * @param immutable set of immutable property keys to skip */ - public static void updateNodeProperties(Set oldProps, Set newProps, Set immutable) { + public static void updateNodeProperties(Set oldProps, Set newProps, Set immutable) + throws Exception { for (Iterator newIter = newProps.iterator(); newIter.hasNext(); ) { NodeProperty newProperty = newIter.next(); - if (!immutable.contains(newProperty.getKey())) { - if (oldProps.contains(newProperty)) { - oldProps.remove(newProperty); - } - if (!newProperty.isMarkedForDeletion()) { - oldProps.add(newProperty); + if (newProperty.getKey().toASCIIString().startsWith(VOS.VOSPACE_URI_NAMESPACE)) { + if (!VOS.VOSPACE_CORE_PROPERTIES.contains(newProperty.getKey())) { + throw NodeFault.InvalidArgument.getStatus("non-standard property uri in namespace " + + VOS.VOSPACE_URI_NAMESPACE + ": " + newProperty.getKey()); } } + if (oldProps.contains(newProperty)) { + oldProps.remove(newProperty); + } + if (!newProperty.isMarkedForDeletion() && !immutable.contains(newProperty.getKey())) { + oldProps.add(newProperty); + } } } diff --git a/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/CreateNodeAction.java b/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/CreateNodeAction.java index 898cd991..a5c5a129 100644 --- a/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/CreateNodeAction.java +++ b/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/CreateNodeAction.java @@ -183,12 +183,13 @@ public void doAction() throws Exception { } // pick out eligible admin-only props (they are immutable to normal users) - List allowedAdminProps = Utils.getAdminProps(clientNode, nodePersistence.getAdminProps(), caller, + final List allowedAdminProps = Utils.getAdminProps(clientNode, nodePersistence.getAdminProps(), caller, nodePersistence); // sanitize input properties into clean set Set np = new HashSet<>(); Utils.updateNodeProperties(np, clientNode.getProperties(), nodePersistence.getImmutableProps()); + clientNode.getProperties().clear(); clientNode.getProperties().addAll(np); clientNode.getProperties().addAll(allowedAdminProps); diff --git a/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/UpdateNodeAction.java b/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/UpdateNodeAction.java index 975aba99..a8042e75 100644 --- a/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/UpdateNodeAction.java +++ b/cadc-vos-server/src/main/java/org/opencadc/vospace/server/actions/UpdateNodeAction.java @@ -141,7 +141,7 @@ public void doAction() throws Exception { } public static Node updateProperties(Node serverNode, Node clientNode, NodePersistence nodePersistence, Subject caller) - throws NodeNotSupportedException { + throws Exception { // merge change request if (clientNode.clearReadOnlyGroups || !clientNode.getReadOnlyGroup().isEmpty()) { serverNode.getReadOnlyGroup().clear();