You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2023/04/27 07:41:47 UTC

[jackrabbit-filevault] 01/01: JCRVLT-705 export special properties which are not protected

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch bugfix/export-special-named-unprotected-properties
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit 60d7f0e00646c71c72ea8f296af0132333a82f84
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Apr 27 09:41:38 2023 +0200

    JCRVLT-705 export special properties which are not protected
    
    Properties with special names should only be excluded from the export in
    case they are really protected.
    In some cases "jcr:created" properties are unprotected.
---
 .../vault/fs/impl/io/DocViewSAXFormatter.java      |  2 +-
 .../vault/fs/impl/io/DocViewSaxFormatterIT.java    | 38 ++++++++++++++++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java
index 166f8766..813dd13c 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXFormatter.java
@@ -222,7 +222,7 @@ public class DocViewSAXFormatter implements AggregateWalkListener {
      */
     @Override
     public void onProperty(Property prop, int level) throws RepositoryException {
-        if (IGNORED_PROTECTED_PROPERTIES.contains(prop.getName())) {
+        if (IGNORED_PROTECTED_PROPERTIES.contains(prop.getName()) && prop.getDefinition().isProtected()) {
             return;
         }
 
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
index 39b195d3..081bd6fd 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSaxFormatterIT.java
@@ -17,11 +17,18 @@
 
 package org.apache.jackrabbit.vault.fs.impl.io;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.time.ZoneOffset;
+import java.util.Calendar;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 
 import javax.jcr.GuestCredentials;
 import javax.jcr.ItemExistsException;
@@ -43,6 +50,7 @@ import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
+import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.vault.fs.Mounter;
 import org.apache.jackrabbit.vault.fs.api.Aggregate;
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
@@ -54,8 +62,6 @@ import org.apache.jackrabbit.vault.util.JcrConstants;
 import org.junit.Assume;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-
 public class DocViewSaxFormatterIT extends IntegrationTestBase {
 
     static String getSerializedAggregate(Session session, String rootNodePath) throws URISyntaxException, RepositoryException, IOException {
@@ -226,4 +232,32 @@ public class DocViewSaxFormatterIT extends IntegrationTestBase {
                 "    jcr:primaryType=\"nt:unstructured\"\n" +
                 "    customMv=\"[value2,value3,value1]\"/>\n", serialization); // don't sort other mv-properties
     }
+
+    @Test
+    public void testUnprotectedAndProtectedProperties() throws RepositoryException, URISyntaxException, IOException {
+        Node node = JcrUtils.getOrCreateByPath("/testroot", NodeType.NT_UNSTRUCTURED, admin);
+        node.addMixin(JcrConstants.MIX_LOCKABLE);
+        node.addMixin(JcrConstants.MIX_LAST_MODIFIED); // adds protected, auto-created properties jcr:lastModified (DATE) and jcr:lastModifiedBy (String)
+        node.addMixin(JcrConstants.MIX_VERSIONABLE);
+        Calendar date = Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC), Locale.ROOT);
+        node.setProperty("jcr:created", date);
+        admin.save();
+
+        String serialization = getSerializedAggregate(admin, "/testroot");
+
+        assertTrue(node.hasProperty(JcrConstants.JCR_BASEVERSION));
+        // export should contain both protected and unprotected properties
+        // only the ones which have a special name and(!) are protected are excluded (like jcr:baseVersion)
+        assertEquals("valid xml",
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\"\n" +
+                "    jcr:created=\"{Date}"+ ISO8601.format(date) + "\"\n" +
+                "    jcr:isCheckedOut=\"{Boolean}true\"\n" +
+                "    jcr:lastModified=\"{Date}" + ISO8601.format(node.getProperty("jcr:lastModified").getDate()) + "\"\n" +
+                "    jcr:lastModifiedBy=\"admin\"\n" +
+                "    jcr:mixinTypes=\"[mix:lastModified,mix:lockable,mix:versionable]\"\n" +
+                "    jcr:primaryType=\"nt:unstructured\"\n" +
+                "    jcr:uuid=\"" + node.getIdentifier() + "\"/>\n"
+                , serialization); 
+    }
 }