jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1524803 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/privilege/ main/java/org/apache/jackrabbit/oak/spi/security/privilege/ test/java/org/apache/jackrabbit/oak/security/privilege/
Date Thu, 19 Sep 2013 18:49:03 GMT
Author: jukka
Date: Thu Sep 19 18:49:02 2013
New Revision: 1524803

URL: http://svn.apache.org/r1524803
Log:
OAK-1027: Avoid turning multivalued properties to String arrays

Use Iterable<String> in the ImmutablePrivilegeDefinition constructor so we don't have
to go through a String array or an extra Set instance

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriterTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java?rev=1524803&r1=1524802&r2=1524803&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
Thu Sep 19 18:49:02 2013
@@ -16,14 +16,18 @@
  */
 package org.apache.jackrabbit.oak.security.privilege;
 
+import static java.util.Arrays.asList;
+
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
 import com.google.common.collect.ImmutableMap;
+
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -169,11 +173,11 @@ class PrivilegeDefinitionWriter implemen
     private static Collection<PrivilegeDefinition> getBuiltInDefinitions() {
         Map<String, PrivilegeDefinition> definitions = new LinkedHashMap<String,
PrivilegeDefinition>();
         for (String privilegeName : NON_AGGR_PRIVILEGES) {
-            PrivilegeDefinition def = new ImmutablePrivilegeDefinition(privilegeName, false);
+            PrivilegeDefinition def = new ImmutablePrivilegeDefinition(privilegeName, false,
null);
             definitions.put(privilegeName, def);
         }
         for (String privilegeName : AGGREGATE_PRIVILEGES.keySet()) {
-            PrivilegeDefinition def = new ImmutablePrivilegeDefinition(privilegeName, false,
AGGREGATE_PRIVILEGES.get(privilegeName));
+            PrivilegeDefinition def = new ImmutablePrivilegeDefinition(privilegeName, false,
asList(AGGREGATE_PRIVILEGES.get(privilegeName)));
             definitions.put(privilegeName, def);
         }
         PrivilegeDefinition all = new ImmutablePrivilegeDefinition(JCR_ALL, false, definitions.keySet());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java?rev=1524803&r1=1524802&r2=1524803&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java
Thu Sep 19 18:49:02 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.spi.security.privilege;
 
-import java.util.Collections;
 import java.util.Set;
 import javax.annotation.Nonnull;
 
@@ -32,20 +31,16 @@ public final class ImmutablePrivilegeDef
     private final boolean isAbstract;
     private final Set<String> declaredAggregateNames;
 
-    public ImmutablePrivilegeDefinition(String name, boolean isAbstract,
-                                        Set<String> declaredAggregateNames) {
+    public ImmutablePrivilegeDefinition(
+            String name, boolean isAbstract,
+            Iterable<String> declaredAggregateNames) {
         this.name = name;
         this.isAbstract = isAbstract;
-        this.declaredAggregateNames = ImmutableSet.copyOf(declaredAggregateNames);
-    }
-
-    public ImmutablePrivilegeDefinition(String name, boolean isAbstract,
-                                        String... declaredAggregateNames) {
-        this.name = name;
-        this.isAbstract = isAbstract;
-        this.declaredAggregateNames = (declaredAggregateNames == null) ?
-                Collections.<String>emptySet() :
-                ImmutableSet.copyOf(declaredAggregateNames);
+        ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+        if (declaredAggregateNames != null) {
+            builder.addAll(declaredAggregateNames);
+        }
+        this.declaredAggregateNames = builder.build();
     }
 
     //------------------------------------------------< PrivilegeDefinition >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeUtil.java?rev=1524803&r1=1524802&r2=1524803&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeUtil.java
Thu Sep 19 18:49:02 2013
@@ -18,8 +18,10 @@ package org.apache.jackrabbit.oak.spi.se
 
 import javax.annotation.Nonnull;
 
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.util.TreeUtil;
 
 /**
@@ -52,8 +54,11 @@ public final class PrivilegeUtil impleme
     public static PrivilegeDefinition readDefinition(@Nonnull Tree definitionTree) {
         String name = definitionTree.getName();
         boolean isAbstract = TreeUtil.getBoolean(definitionTree, REP_IS_ABSTRACT);
-        String[] declAggrNames = TreeUtil.getStrings(definitionTree, REP_AGGREGATES);
-
+        Iterable<String> declAggrNames = null;
+        PropertyState property = definitionTree.getProperty(REP_AGGREGATES);
+        if (property != null) {
+            declAggrNames = property.getValue(Type.NAMES);
+        }
         return new ImmutablePrivilegeDefinition(name, isAbstract, declAggrNames);
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriterTest.java?rev=1524803&r1=1524802&r2=1524803&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriterTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriterTest.java
Thu Sep 19 18:49:02 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.security.privilege;
 
-import java.util.Collections;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.AbstractSecurityTest;
@@ -31,6 +30,7 @@ import org.apache.jackrabbit.oak.util.Tr
 import org.junit.After;
 import org.junit.Test;
 
+import static java.util.Arrays.asList;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -51,7 +51,7 @@ public class PrivilegeDefinitionWriterTe
     public void testNameCollision() {
         try {
             PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(root);
-            writer.writeDefinition(new ImmutablePrivilegeDefinition(JCR_READ, true, Collections.<String>emptySet()));
+            writer.writeDefinition(new ImmutablePrivilegeDefinition(JCR_READ, true, null));
             fail("name collision");
         } catch (RepositoryException e) {
             // success
@@ -64,7 +64,7 @@ public class PrivilegeDefinitionWriterTe
         Root tmpRoot = repo.login(null, null).getLatestRoot();
         try {
             PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(tmpRoot);
-            writer.writeDefinition(new ImmutablePrivilegeDefinition("newName", true, Collections.<String>emptySet()));
+            writer.writeDefinition(new ImmutablePrivilegeDefinition("newName", true, null));
             fail("missing privilege root");
         } catch (RepositoryException e) {
             // success
@@ -76,7 +76,8 @@ public class PrivilegeDefinitionWriterTe
     @Test
     public void testWriteDefinition() throws Exception {
         PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(root);
-        writer.writeDefinition(new ImmutablePrivilegeDefinition("tmp", true, JCR_READ_ACCESS_CONTROL,
JCR_MODIFY_ACCESS_CONTROL));
+        writer.writeDefinition(new ImmutablePrivilegeDefinition(
+                "tmp", true, asList(JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL)));
 
         Tree privRoot = root.getTree(PRIVILEGES_PATH);
         assertTrue(privRoot.hasChild("tmp"));



Mime
View raw message