jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1524804 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ main/java/org/apache/jackrabbit/oak/util/ test/java/org/apache/jackrabbit/oak/ test/java/org/apache/jackrabbit/oak/s...
Date Thu, 19 Sep 2013 18:50:12 GMT
Author: jukka
Date: Thu Sep 19 18:50:11 2013
New Revision: 1524804

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

Replace String[] with Iterable<String> as getStrings() and getNames() return value

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriterTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java?rev=1524804&r1=1524803&r2=1524804&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
Thu Sep 19 18:50:11 2013
@@ -633,8 +633,8 @@ public class AccessControlManagerImpl im
 
     @Nonnull
     private Set<Privilege> getPrivileges(@Nonnull Tree aceTree) throws RepositoryException
{
-        String[] privNames = checkNotNull(TreeUtil.getStrings(aceTree, REP_PRIVILEGES));
-        Set<Privilege> privileges = new HashSet<Privilege>(privNames.length);
+        Iterable<String> privNames = checkNotNull(TreeUtil.getStrings(aceTree, REP_PRIVILEGES));
+        Set<Privilege> privileges = new HashSet<Privilege>();
         for (String name : privNames) {
             privileges.add(privilegeManager.getPrivilege(name));
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java?rev=1524804&r1=1524803&r2=1524804&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlValidator.java
Thu Sep 19 18:50:11 2013
@@ -16,17 +16,19 @@
  */
 package org.apache.jackrabbit.oak.security.authorization.accesscontrol;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.security.AccessControlException;
 import javax.jcr.security.Privilege;
 
 import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -213,8 +215,8 @@ class AccessControlValidator extends Def
         // enforced on the oak level.
     }
 
-    private void checkValidPrivileges(String[] privilegeNames) throws CommitFailedException
{
-        if (privilegeNames == null || privilegeNames.length == 0) {
+    private void checkValidPrivileges(Iterable<String> privilegeNames) throws CommitFailedException
{
+        if (privilegeNames == null || Iterables.isEmpty(privilegeNames)) {
             throw accessViolation(9, "Missing privileges.");
         }
         for (String privilegeName : privilegeNames) {
@@ -249,8 +251,8 @@ class AccessControlValidator extends Def
 
 
     private static void checkMixinTypes(Tree parentTree) throws CommitFailedException {
-        String[] mixinNames = TreeUtil.getStrings(parentTree, JcrConstants.JCR_MIXINTYPES);
-        if (mixinNames != null && Arrays.asList(mixinNames).contains(MIX_REP_REPO_ACCESS_CONTROLLABLE))
{
+        Iterable<String> mixinNames = TreeUtil.getNames(parentTree, JcrConstants.JCR_MIXINTYPES);
+        if (mixinNames != null && Iterables.contains(mixinNames, MIX_REP_REPO_ACCESS_CONTROLLABLE))
{
             checkValidRepoAccessControlled(parentTree);
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1524804&r1=1524803&r2=1524804&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Thu Sep 19 18:50:11 2013
@@ -36,7 +36,9 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
 import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -222,7 +224,7 @@ public class NodeUtil {
     }
 
     @CheckForNull
-    public String[] getStrings(String name) {
+    public Iterable<String> getStrings(String name) {
         return TreeUtil.getStrings(tree, name);
     }
 
@@ -251,15 +253,15 @@ public class NodeUtil {
     }
 
     @CheckForNull
-    public String[] getNames(String propertyName, String... defaultValues) {
-        String[] strings = getStrings(propertyName);
-        if (strings == null) {
-            strings = defaultValues;
-        }
-        for (int i = 0; i < strings.length; i++) {
-            strings[i] = mapper.getJcrName(strings[i]);
-        }
-        return strings;
+    public Iterable<String> getNames(String propertyName) {
+        return Iterables.transform(
+                TreeUtil.getNames(tree, propertyName),
+                new Function<String, String>() {
+                    @Override
+                    public String apply(String input) {
+                        return mapper.getJcrName(input);
+                    }
+                });
     }
 
     public void setNames(String propertyName, String... values) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java?rev=1524804&r1=1524803&r2=1524804&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
Thu Sep 19 18:50:11 2013
@@ -81,12 +81,12 @@ public final class TreeUtil {
     }
 
     @CheckForNull
-    public static String[] getStrings(Tree tree, String propertyName) {
+    public static Iterable<String> getStrings(Tree tree, String propertyName) {
         PropertyState property = tree.getProperty(propertyName);
         if (property == null) {
             return null;
         } else {
-            return Iterables.toArray(property.getValue(STRINGS), String.class);
+            return property.getValue(STRINGS);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java?rev=1524804&r1=1524803&r2=1524804&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
Thu Sep 19 18:50:11 2013
@@ -16,7 +16,12 @@
  */
 package org.apache.jackrabbit.oak;
 
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.util.Arrays;
+import java.util.List;
 import java.util.UUID;
+
 import javax.annotation.Nullable;
 import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
@@ -159,11 +164,16 @@ public abstract class AbstractSecurityTe
     }
 
     protected Privilege[] privilegesFromNames(String... privilegeNames) throws RepositoryException
{
-        Privilege[] privs = new Privilege[privilegeNames.length];
-        for (int i = 0; i < privilegeNames.length; i++) {
-            privs[i] = getPrivilegeManager(root).getPrivilege(privilegeNames[i]);
+        return privilegesFromNames(Arrays.asList(privilegeNames));
+    }
+
+    protected Privilege[] privilegesFromNames(Iterable<String> privilegeNames) throws
RepositoryException {
+        PrivilegeManager manager = getPrivilegeManager(root);
+        List<Privilege> privs = newArrayList();
+        for (String name : privilegeNames) {
+            privs.add(manager.getPrivilege(name));
         }
-        return privs;
+        return privs.toArray(new Privilege[privs.size()]);
     }
 
     protected PrivilegeManager getPrivilegeManager(Root root) {

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=1524804&r1=1524803&r2=1524804&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:50:11 2013
@@ -30,6 +30,8 @@ import org.apache.jackrabbit.oak.util.Tr
 import org.junit.After;
 import org.junit.Test;
 
+import com.google.common.collect.Iterables;
+
 import static java.util.Arrays.asList;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertTrue;
@@ -84,7 +86,8 @@ public class PrivilegeDefinitionWriterTe
 
         Tree tmpTree = privRoot.getChild("tmp");
         assertTrue(TreeUtil.getBoolean(tmpTree, REP_IS_ABSTRACT));
-        assertArrayEquals(new String[] {JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL},
-                TreeUtil.getStrings(tmpTree, REP_AGGREGATES));
+        assertArrayEquals(
+                new String[] {JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL},
+                Iterables.toArray(TreeUtil.getStrings(tmpTree, REP_AGGREGATES), String.class));
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java?rev=1524804&r1=1524803&r2=1524804&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java
Thu Sep 19 18:50:11 2013
@@ -19,12 +19,15 @@ package org.apache.jackrabbit.oak.securi
 import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
 import java.util.Map;
+
 import javax.jcr.GuestCredentials;
 import javax.jcr.SimpleCredentials;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
@@ -126,8 +129,10 @@ public class UserInitializerTest extends
 
         Tree princName = oakIndex.getChild("principalName");
         assertIndexDefinition(princName, UserConstants.REP_PRINCIPAL_NAME, true);
-        String[] declaringNtNames = TreeUtil.getStrings(princName, IndexConstants.DECLARING_NODE_TYPES);
-        assertArrayEquals(new String[]{UserConstants.NT_REP_AUTHORIZABLE}, declaringNtNames);
+        Iterable<String> declaringNtNames = TreeUtil.getStrings(princName, IndexConstants.DECLARING_NODE_TYPES);
+        assertArrayEquals(
+                new String[]{UserConstants.NT_REP_AUTHORIZABLE},
+                Iterables.toArray(declaringNtNames, String.class));
 
         Tree members = oakIndex.getChild("members");
         assertIndexDefinition(members, UserConstants.REP_MEMBERS, false);
@@ -237,6 +242,8 @@ public class UserInitializerTest extends
         assertTrue(tree.exists());
 
         assertEquals(isUnique, TreeUtil.getBoolean(tree, IndexConstants.UNIQUE_PROPERTY_NAME));
-        assertArrayEquals(propName, new String[]{propName}, TreeUtil.getStrings(tree, IndexConstants.PROPERTY_NAMES));
+        assertArrayEquals(
+                propName, new String[]{propName},
+                Iterables.toArray(TreeUtil.getStrings(tree, IndexConstants.PROPERTY_NAMES),
String.class));
     }
 }



Mime
View raw message