You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2022/09/24 13:00:02 UTC
[jackrabbit-filevault] branch JCRVLT-658 created (now 6823a8f9)
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a change to branch JCRVLT-658
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
at 6823a8f9 JCRVLT-658: Importer fails for invalid namespace names
This branch includes the following new commits:
new 6823a8f9 JCRVLT-658: Importer fails for invalid namespace names
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[jackrabbit-filevault] 01/01: JCRVLT-658: Importer fails for invalid namespace names
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch JCRVLT-658
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
commit 6823a8f9ef427e6cd21603684345b14c7f5ec33a
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Sat Sep 24 13:59:44 2022 +0100
JCRVLT-658: Importer fails for invalid namespace names
---
.../vault/fs/impl/io/DocViewImporter.java | 26 ++++--
.../packaging/integration/NamespaceImportIT.java | 16 ++++
.../META-INF/vault/config.xml | 93 ++++++++++++++++++++++
.../META-INF/vault/definition/.content.xml | 25 ++++++
.../META-INF/vault/filter.xml | 4 +
.../META-INF/vault/nodetypes.cnd | 17 ++++
.../META-INF/vault/properties.xml | 18 +++++
.../badnamespacenames.zip/jcr_root/.content.xml | 6 ++
.../jcr_root/tmp/.content.xml | 4 +
.../jcr_root/tmp/badnamespacenames.xml | 13 +++
10 files changed, 214 insertions(+), 8 deletions(-)
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
index c4bd9431..d898562a 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
@@ -218,8 +218,8 @@ public class DocViewImporter implements DocViewParserHandler {
/**
* {@code true} in case the repository supports same-name siblings
*/
- private final boolean isSnsSupported;
-
+ private final boolean isSnsSupported;
+
/**
* Creates a new importer that will imports the
* items below the given root.
@@ -1200,28 +1200,37 @@ public class DocViewImporter implements DocViewParserHandler {
return effectiveNodeType.getApplicablePropertyDefinition(npResolver.getJCRName(docViewProperty.getName()), docViewProperty.isMultiValue(), docViewProperty.getType()).map(PropertyDefinition::isProtected).orElse(false);
}
+ private String nameToPathComponent(Name name) throws RepositoryException {
+ String nsuri = name.getNamespaceURI();
+ // non-empty URI MUST contain ":" and MUST NOT contain curly braces
+ boolean uriok = nsuri.length() == 0 || (nsuri.indexOf(':') > 0 && nsuri.indexOf('{') < 0 && nsuri.indexOf("}") < 0);
+ return uriok ? name.toString() : npResolver.getJCRName(name);
+ }
+
private Node getNodeByIdOrName(@NotNull Node currentNode, @NotNull DocViewNode2 ni, boolean isIdNewlyAssigned) throws RepositoryException {
Node node = null;
Optional<String> id = ni.getIdentifier();
+ String name = nameToPathComponent(ni.getName());
if (id.isPresent() && !isIdNewlyAssigned) {
try {
node = currentNode.getSession().getNodeByIdentifier(id.get());
} catch (RepositoryException e) {
- log.warn("Newly created node not found by uuid {}: {}", currentNode.getPath() + "/" + ni.getName(), e.toString());
+ log.warn("Newly created node not found by uuid {}: {}", currentNode.getPath() + "/" + name, e.toString());
}
}
if (node == null) {
+ String snsName = nameToPathComponent(ni.getSnsAwareName());
try {
- node = currentNode.getNode(ni.getSnsAwareName().toString());
+ node = currentNode.getNode(snsName);
} catch (RepositoryException e) {
- log.warn("Newly created node not found by SNS aware name {}: {}", currentNode.getPath() + "/" + ni.getSnsAwareName(), e.toString());
+ log.warn("Newly created node not found by SNS aware name {}: {}", currentNode.getPath() + "/" + snsName, e.toString());
}
}
if (node == null) {
try {
- node = currentNode.getNode(ni.getName().toString());
+ node = currentNode.getNode(name);
} catch (RepositoryException e) {
- log.debug("Newly created node not found by name {}: {}", currentNode.getPath() + "/" + ni.getName(), e.toString());
+ log.debug("Newly created node not found by name {}: {}", currentNode.getPath() + "/" + name, e.toString());
throw e;
}
}
@@ -1239,7 +1248,8 @@ public class DocViewImporter implements DocViewParserHandler {
boolean modified = false;
// add properties
for (DocViewProperty2 prop : ni.getProperties()) {
- if (prop != null && !isPropertyProtected(effectiveNodeType, prop) && (overwriteExistingProperties || !node.hasProperty(prop.getName().toString())) && wspFilter.includesProperty(node.getPath() + "/" + npResolver.getJCRName(prop.getName()))) {
+ String name = nameToPathComponent(prop.getName());
+ if (prop != null && !isPropertyProtected(effectiveNodeType, prop) && (overwriteExistingProperties || !node.hasProperty(name)) && wspFilter.includesProperty(node.getPath() + "/" + npResolver.getJCRName(prop.getName()))) {
// check if property is allowed
try {
modified |= prop.apply(node);
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NamespaceImportIT.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NamespaceImportIT.java
index 2225b477..2048b088 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NamespaceImportIT.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/NamespaceImportIT.java
@@ -169,6 +169,22 @@ public class NamespaceImportIT extends IntegrationTestBase {
}
}
+
+ @Test
+ public void testBadNamespaceNames() throws RepositoryException, IOException, PackageException {
+ extractVaultPackageStrict("/test-packages/badnamespacenames.zip");
+
+ assertNodeExists("/tmp/badnamespacenames");
+
+ String prefixBar = admin.getNamespacePrefix("bar");
+ assertNodeExists("/tmp/badnamespacenames/" + prefixBar + ":child");
+ String prefixQux = admin.getNamespacePrefix("qux");
+ assertNodeExists("/tmp/badnamespacenames/" + prefixBar + ":child/" + prefixQux + ":child");
+ // Still fails: why?
+ // String prefixFoo = admin.getNamespacePrefix("foo");
+ // assertProperty("/tmp/badnamespacenames/" + prefixBar + ":child/" + prefixQux + ":child/" + prefixFoo + ":someproperty", "xyz");
+ }
+
/** Simple Oak repository wrapper */
private static final class Instance {
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/config.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/config.xml
new file mode 100644
index 00000000..b525f1c5
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/config.xml
@@ -0,0 +1,93 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<vaultfs version="1.1">
+ <!--
+ Defines the content aggregation. The order of the defined aggregates
+ is important for finding the correct aggregator.
+ -->
+ <aggregates>
+ <!--
+ Defines an aggregate that handles nt:file and nt:resource nodes.
+ -->
+ <aggregate type="file" title="File Aggregate"/>
+
+ <!--
+ Defines an aggregate that handles file/folder like nodes. It matches
+ all nt:hierarchyNode nodes that have or define a jcr:content
+ child node and excludes child nodes that are nt:hierarchyNodes.
+ -->
+ <aggregate type="filefolder" title="File/Folder Aggregate"/>
+
+ <!--
+ Defines an aggregate that handles nt:nodeType nodes and serializes
+ them into .cnd notation.
+ -->
+ <aggregate type="nodetype" title="Node Type Aggregate" />
+
+ <!--
+ Defines an aggregate that defines full coverage for certain node
+ types that cannot be covered by the default aggregator.
+ -->
+ <aggregate type="full" title="Full Coverage Aggregate">
+ <matches>
+ <include nodeType="rep:AccessControl" respectSupertype="true" />
+ <include nodeType="rep:Policy" respectSupertype="true" />
+ <include nodeType="cq:Widget" respectSupertype="true" />
+ <include nodeType="cq:EditConfig" respectSupertype="true" />
+ <include nodeType="cq:WorkflowModel" respectSupertype="true" />
+ <include nodeType="vlt:FullCoverage" respectSupertype="true" />
+ <include nodeType="mix:language" respectSupertype="true" />
+ <include nodeType="sling:OsgiConfig" respectSupertype="true" />
+ </matches>
+ </aggregate>
+
+ <!--
+ Defines an aggregate that handles nt:folder like nodes.
+ -->
+ <aggregate type="generic" title="Folder Aggregate">
+ <matches>
+ <include nodeType="nt:folder" respectSupertype="true" />
+ </matches>
+ <contains>
+ <exclude isNode="true" />
+ </contains>
+ </aggregate>
+
+ <!--
+ Defines the default aggregate
+ -->
+ <aggregate type="generic" title="Default Aggregator" isDefault="true">
+ <matches>
+ <!-- all -->
+ </matches>
+ <contains>
+ <exclude nodeType="nt:hierarchyNode" respectSupertype="true" />
+ </contains>
+ </aggregate>
+
+ </aggregates>
+
+ <!--
+ defines the input handlers
+ -->
+ <handlers>
+ <handler type="folder"/>
+ <handler type="file"/>
+ <handler type="nodetype"/>
+ <handler type="generic"/>
+ </handlers>
+</vaultfs>
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/definition/.content.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/definition/.content.xml
new file mode 100644
index 00000000..c57b6a81
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/definition/.content.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:created="{Date}2015-12-16T16:59:10.779+01:00"
+ jcr:createdBy="admin"
+ jcr:description=""
+ jcr:lastModified="{Date}2015-12-16T16:59:10.779+01:00"
+ jcr:lastModifiedBy="admin"
+ jcr:primaryType="vlt:PackageDefinition"
+ buildCount="5"
+ builtWith="Adobe Experience Manager-6.1.0.20150507"
+ group="my_packages"
+ lastUnwrapped="{Date}2015-12-16T16:59:10.779+01:00"
+ lastUnwrappedBy="admin"
+ lastWrapped="{Date}2015-12-16T16:59:10.779+01:00"
+ lastWrappedBy="admin"
+ name="test_referenceable"
+ version="">
+ <filter jcr:primaryType="nt:unstructured">
+ <f0
+ jcr:primaryType="nt:unstructured"
+ mode="replace"
+ root="/tmp/referenceable"
+ rules="[]"/>
+ </filter>
+</jcr:root>
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/filter.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/filter.xml
new file mode 100644
index 00000000..7705dc81
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/filter.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<workspaceFilter version="1.0">
+ <filter root="/tmp/badnamespacenames"/>
+</workspaceFilter>
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/nodetypes.cnd b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/nodetypes.cnd
new file mode 100644
index 00000000..c348e28e
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/nodetypes.cnd
@@ -0,0 +1,17 @@
+<'vlt'='http://www.day.com/jcr/vault/1.0'>
+<'sling'='http://sling.apache.org/jcr/sling/1.0'>
+<'nt'='http://www.jcp.org/jcr/nt/1.0'>
+<'rep'='internal'>
+
+[vlt:FullCoverage]
+ mixin
+
+[sling:Folder] > nt:folder
+ - * (undefined) multiple
+ - * (undefined)
+ + * (nt:base) = sling:Folder version
+
+[rep:RepoAccessControllable]
+ mixin
+ + rep:repoPolicy (rep:Policy) protected ignore
+
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/properties.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/properties.xml
new file mode 100644
index 00000000..2494f50c
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/META-INF/vault/properties.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+<comment>FileVault Package Properties</comment>
+<entry key="createdBy">admin</entry>
+<entry key="name">test_referenceable</entry>
+<entry key="lastModified">2015-12-16T16:59:10.779+01:00</entry>
+<entry key="lastModifiedBy">admin</entry>
+<entry key="created">2015-12-16T16:59:10.795+01:00</entry>
+<entry key="buildCount">5</entry>
+<entry key="version"/>
+<entry key="dependencies"/>
+<entry key="packageFormatVersion">2</entry>
+<entry key="description"/>
+<entry key="lastWrapped">2015-12-16T16:59:10.779+01:00</entry>
+<entry key="group">my_packages</entry>
+<entry key="lastWrappedBy">admin</entry>
+</properties>
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/.content.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/.content.xml
new file mode 100644
index 00000000..8ea9f2ae
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/.content.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+ jcr:mixinTypes="[rep:AccessControllable,rep:RepoAccessControllable]"
+ jcr:primaryType="rep:root"
+ sling:resourceType="sling:redirect"
+ sling:target="/index.html"/>
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/tmp/.content.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/tmp/.content.xml
new file mode 100644
index 00000000..54084a82
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/tmp/.content.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+ jcr:mixinTypes="[rep:AccessControllable]"
+ jcr:primaryType="sling:Folder"/>
diff --git a/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/tmp/badnamespacenames.xml b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/tmp/badnamespacenames.xml
new file mode 100644
index 00000000..535ebfe4
--- /dev/null
+++ b/vault-core/src/test/resources/test-packages/badnamespacenames.zip/jcr_root/tmp/badnamespacenames.xml
@@ -0,0 +1,13 @@
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:primaryType="sling:Folder"
+ xmlns:foo="bar"
+ xmlns:bar="qux"
+ xmlns:qux="foo">
+ <foo:child
+ jcr:primaryType="nt:unstructured">
+ <bar:child
+ jcr:primaryType="nt:unstructured"
+ qux:someproperty="xyz">
+ </bar:child>
+ </foo:child>
+</jcr:root>