You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:47:23 UTC
[sling-org-apache-sling-jcr-contentparser] 02/04: SLING-6960 JCR
Content Parser: Ignore security:acl and security:principals nodes
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.contentparser-1.2.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentparser.git
commit 24061b1f16e0a2893aadade3e057042cb5a105ef
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Jun 14 17:22:03 2017 +0000
SLING-6960 JCR Content Parser: Ignore security:acl and security:principals nodes
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/contentparser@1798723 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/jcr/contentparser/ParserOptions.java | 11 ++++++++-
.../jcr/contentparser/impl/JsonContentParser.java | 27 ++++++++++++++++------
.../sling/jcr/contentparser/package-info.java | 2 +-
.../contentparser/impl/JsonContentParserTest.java | 2 +-
src/test/resources/content-test/content.json | 10 ++++++++
5 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/sling/jcr/contentparser/ParserOptions.java b/src/main/java/org/apache/sling/jcr/contentparser/ParserOptions.java
index d3e87fa..1c006ea 100644
--- a/src/main/java/org/apache/sling/jcr/contentparser/ParserOptions.java
+++ b/src/main/java/org/apache/sling/jcr/contentparser/ParserOptions.java
@@ -49,6 +49,15 @@ public final class ParserOptions {
)));
/**
+ * Default list of resource names that should be ignored.
+ */
+ public static final Set<String> DEFAULT_IGNORE_RESOURCE_NAMES
+ = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ "security:acl",
+ "security:principals"
+ )));
+
+ /**
* List of JSON parser features activated by default.
*/
public static final EnumSet<JsonParserFeature> DEFAULT_JSON_PARSER_FEATURES
@@ -57,7 +66,7 @@ public final class ParserOptions {
private String defaultPrimaryType = DEFAULT_PRIMARY_TYPE;
private boolean detectCalendarValues;
private Set<String> ignorePropertyNames;
- private Set<String> ignoreResourceNames;
+ private Set<String> ignoreResourceNames = DEFAULT_IGNORE_RESOURCE_NAMES;
private Set<String> removePropertyNamePrefixes = DEFAULT_REMOVE_PROPERTY_NAME_PREFIXES;
private EnumSet<JsonParserFeature> jsonParserFeatures = DEFAULT_JSON_PARSER_FEATURES;
diff --git a/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java b/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
index 054be85..9b88282 100644
--- a/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
+++ b/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
@@ -117,15 +117,28 @@ public final class JsonContentParser implements ContentParser {
Map<String,JsonObject> children = new LinkedHashMap<>();
for (Map.Entry<String, JsonValue> entry : object.entrySet()) {
String childName = entry.getKey();
- Object value = convertValue(entry.getValue());
- boolean isResource = (value instanceof JsonObject);
+ Object value = null;
boolean ignore = false;
- if (isResource) {
- ignore = helper.ignoreResource(childName);
+ try {
+ value = convertValue(entry.getValue());
+ }
+ catch (ParseException ex) {
+ if (helper.ignoreResource(childName) || helper.ignoreProperty(helper.cleanupPropertyName(childName))) {
+ ignore = true;
+ }
+ else {
+ throw ex;
+ }
}
- else {
- childName = helper.cleanupPropertyName(childName);
- ignore = helper.ignoreProperty(childName);
+ boolean isResource = (value instanceof JsonObject);
+ if (!ignore) {
+ if (isResource) {
+ ignore = helper.ignoreResource(childName);
+ }
+ else {
+ childName = helper.cleanupPropertyName(childName);
+ ignore = helper.ignoreProperty(childName);
+ }
}
if (!ignore) {
if (isResource) {
diff --git a/src/main/java/org/apache/sling/jcr/contentparser/package-info.java b/src/main/java/org/apache/sling/jcr/contentparser/package-info.java
index 5cf33d1..51afb23 100644
--- a/src/main/java/org/apache/sling/jcr/contentparser/package-info.java
+++ b/src/main/java/org/apache/sling/jcr/contentparser/package-info.java
@@ -19,5 +19,5 @@
/**
* Parser for repository content serialized e.g. as JSON or JCR XML.
*/
-@org.osgi.annotation.versioning.Version("1.2.0")
+@org.osgi.annotation.versioning.Version("1.3.0")
package org.apache.sling.jcr.contentparser;
diff --git a/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java b/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
index b8f3598..9d789fc 100644
--- a/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
+++ b/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
@@ -137,7 +137,7 @@ public class JsonContentParserTest {
@Test
public void testIgnoreResourcesProperties() throws Exception {
ContentParser underTest = ContentParserFactory.create(ContentType.JSON,
- new ParserOptions().ignoreResourceNames(ImmutableSet.of("header", "newslist"))
+ new ParserOptions().ignoreResourceNames(ImmutableSet.of("header", "newslist", "security:acl", "security:principals"))
.ignorePropertyNames(ImmutableSet.of("jcr:title")));
ContentElement content = parse(underTest, file);
ContentElement child = content.getChild("jcr:content");
diff --git a/src/test/resources/content-test/content.json b/src/test/resources/content-test/content.json
index c30d34e..8890044 100644
--- a/src/test/resources/content-test/content.json
+++ b/src/test/resources/content-test/content.json
@@ -20,6 +20,16 @@
"utf8Property": "äöü߀",
"jcr:reference:refpro1": "abc",
"jcr:path:pathprop1": "def",
+ /* should be ignored */
+ "security:acl": [
+ { "principal": "TestGroup1", "granted": ["jcr:read","jcr:write"] },
+ { "principal": "TestUser1", "granted": ["jcr:read"], "denied": ["jcr:write"] }
+ ],
+ /* should be ignored */
+ "security:principals": [
+ { "name": "TestUser1", "password": "mypassword", "extraProp1": "extraProp1Value" },
+ { "name": "TestGroup1", "isgroup": "true", "members": ["TestUser1"], "extraProp1": "extraProp1Value" }
+ ],
"par": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "foundation/components/parsys",
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.