jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1443483 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/ main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ main/java/org/apache/jackrabbit/oak/security/authorization/ main/java/org/apach...
Date Thu, 07 Feb 2013 13:59:39 GMT
Author: angela
Date: Thu Feb  7 13:59:39 2013
New Revision: 1443483

URL: http://svn.apache.org/viewvc?rev=1443483&view=rev
Log:
OAK-396: Limit property index to nodes of given type 

- adjust utilities
- add constant in IndexConstants
- change UserInitializer to specify rep:User and rep:Group as declaring node types
- change AccessControlInitializer: specify ace node types as declaring node types

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.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/plugins/index/IndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java?rev=1443483&r1=1443482&r2=1443483&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
Thu Feb  7 13:59:39 2013
@@ -41,4 +41,10 @@ public interface IndexConstants {
      * property index definition.
      */
     String PROPERTY_NAMES = "propertyNames";
+
+    /**
+     * Defines the property name of the "declaringNodeTypes" property with
+     * allows to restrict a given index definition to specific node types.
+     */
+    String DECLARING_NODE_TYPES = "declaringNodeTypes";
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1443483&r1=1443482&r2=1443483&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
Thu Feb  7 13:59:39 2013
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
@@ -53,18 +55,19 @@ public class IndexUtils implements Index
     /**
      * Create a new property2 index definition below the given {@code indexNode}.
      *
-     * @param index The oak:index node builder
-     * @param indexDefName The name of the new property index.
-     * @param reindex {@code true} if the the reindex flag should be turned on.
-     * @param unique {@code true} if the index is expected the assert property
-     * uniqueness.
+     * @param index         The oak:index node builder
+     * @param indexDefName  The name of the new property index.
+     * @param reindex       {@code true} if the the reindex flag should be turned on.
+     * @param unique        {@code true} if the index is expected the assert property
+     *                      uniqueness.
      * @param propertyNames The property names that should be indexed.
      */
-    public static void createIndexDefinition(NodeBuilder index,
-                                             String indexDefName,
+    public static void createIndexDefinition(@Nonnull NodeBuilder index,
+                                             @Nonnull String indexDefName,
                                              boolean reindex,
                                              boolean unique,
-                                             List<String> propertyNames) {
+                                             @Nonnull List<String> propertyNames,
+                                             @Nullable List<String> declaringNodeTypeNames)
{
         NodeBuilder entry = index.child(indexDefName)
                 .setProperty(JCR_PRIMARYTYPE, IndexConstants.INDEX_DEFINITIONS_NODE_TYPE,
Type.NAME)
                 .setProperty(IndexConstants.TYPE_PROPERTY_NAME, "p2")
@@ -78,6 +81,9 @@ public class IndexUtils implements Index
         } else {
             entry.setProperty(PropertyStates.createProperty(IndexConstants.PROPERTY_NAMES,
propertyNames, Type.STRINGS));
         }
+        if (declaringNodeTypeNames != null && !declaringNodeTypeNames.isEmpty())
{
+            entry.setProperty(PropertyStates.createProperty(IndexConstants.DECLARING_NODE_TYPES,
declaringNodeTypeNames, Type.STRINGS));
+        }
     }
 
     /**
@@ -87,30 +93,35 @@ public class IndexUtils implements Index
      * @param indexDefName
      * @param unique
      * @param propertyNames
+     * @param declaringNodeTypeNames
      */
-    public static void createIndexDefinition(NodeUtil indexNode,
-                                             String indexDefName,
+    public static void createIndexDefinition(@Nonnull NodeUtil indexNode,
+                                             @Nonnull String indexDefName,
                                              boolean unique,
-                                             String... propertyNames) {
+                                             @Nonnull String[] propertyNames,
+                                             @Nullable String[] declaringNodeTypeNames) {
         NodeUtil entry = indexNode.getOrAddChild(indexDefName, IndexConstants.INDEX_DEFINITIONS_NODE_TYPE);
         entry.setString(IndexConstants.TYPE_PROPERTY_NAME, "p2");
         entry.setBoolean(IndexConstants.REINDEX_PROPERTY_NAME, true);
         if (unique) {
             entry.setBoolean(IndexConstants.UNIQUE_PROPERTY_NAME, true);
         }
+        if (declaringNodeTypeNames != null && declaringNodeTypeNames.length >
0) {
+            entry.setStrings(IndexConstants.DECLARING_NODE_TYPES, declaringNodeTypeNames);
+        }
         entry.setStrings(IndexConstants.PROPERTY_NAMES, propertyNames);
     }
 
     /**
      * Builds a list of the existing index definitions.
-     * 
+     * <p/>
      * Checks only children of the provided state for an index definitions
      * container node, aka a node named {@link #INDEX_DEFINITIONS_NAME}
-     * 
+     *
      * @return
      */
     public static List<IndexDefinition> buildIndexDefinitions(NodeState state,
-            String indexConfigPath, String typeFilter) {
+                                                              String indexConfigPath, String
typeFilter) {
         NodeState definitions = state.getChildNode(INDEX_DEFINITIONS_NAME);
         if (definitions == null) {
             return Collections.emptyList();
@@ -130,10 +141,9 @@ public class IndexUtils implements Index
 
     /**
      * Builds an {@link IndexDefinition} out of a {@link ChildNodeEntry}
-     * 
      */
     private static IndexDefinition getDefinition(String path,
-            ChildNodeEntry def, String typeFilter) {
+                                                 ChildNodeEntry def, String typeFilter) {
         String name = def.getName();
         NodeState ns = def.getNodeState();
         PropertyState typeProp = ns.getProperty(TYPE_PROPERTY_NAME);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java?rev=1443483&r1=1443482&r2=1443483&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
Thu Feb  7 13:59:39 2013
@@ -56,19 +56,20 @@ public class InitialContent implements R
             system.setProperty(JCR_PRIMARYTYPE, "rep:system", Type.NAME);
 
             system.child(JCR_VERSIONSTORAGE)
-                .setProperty(JCR_PRIMARYTYPE, "rep:versionStorage", Type.NAME);
+                    .setProperty(JCR_PRIMARYTYPE, "rep:versionStorage", Type.NAME);
             system.child("jcr:nodeTypes")
-                .setProperty(JCR_PRIMARYTYPE, "rep:nodeTypes", Type.NAME);
+                    .setProperty(JCR_PRIMARYTYPE, "rep:nodeTypes", Type.NAME);
             system.child("jcr:activities")
-                .setProperty(JCR_PRIMARYTYPE, "rep:Activities", Type.NAME);
+                    .setProperty(JCR_PRIMARYTYPE, "rep:Activities", Type.NAME);
         }
 
         if (!root.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
             NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
 
-            IndexUtils.createIndexDefinition(index, "uuid", true, true, ImmutableList.<String>of(JCR_UUID));
+            IndexUtils.createIndexDefinition(index, "uuid", true, true,
+                    ImmutableList.<String>of(JCR_UUID), null);
             IndexUtils.createIndexDefinition(index, "nodetype", true, false,
-                    ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES));
+                    ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES), null);
         }
         try {
             branch.setRoot(root.getNodeState());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java?rev=1443483&r1=1443482&r2=1443483&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
Thu Feb  7 13:59:39 2013
@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
 /**
  * AccessControlInitializer... TODO
  */
-public class AccessControlInitializer implements RepositoryInitializer {
+public class AccessControlInitializer implements RepositoryInitializer, AccessControlConstants
{
 
     /**
      * logger instance
@@ -43,9 +43,9 @@ public class AccessControlInitializer im
         NodeBuilder root = branch.getRoot().builder();
         NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
 
-        // TODO OAK-396: add declaring node type information
         IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false,
-                ImmutableList.<String>of(AccessControlConstants.REP_PRINCIPAL_NAME));
+                ImmutableList.<String>of(REP_PRINCIPAL_NAME),
+                ImmutableList.<String>of(NT_REP_DENY_ACE, NT_REP_GRANT_ACE));
 
         try {
             branch.setRoot(root.getNodeState());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1443483&r1=1443482&r2=1443483&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Thu Feb  7 13:59:39 2013
@@ -39,24 +39,24 @@ import org.slf4j.LoggerFactory;
  * Creates initial set of users to be present in the repository. This
  * implementation uses the {@code UserManager} such as defined by the
  * user configuration.
- *
+ * <p/>
  * Currently the following users are created:
- *
+ * <p/>
  * <ul>
- *     <li>An administrator user using {@link UserConstants#PARAM_ADMIN_ID}
- *     or {@link UserConstants#DEFAULT_ADMIN_ID} if the config option is missing.</li>
- *     <li>An administrator user using {@link UserConstants#PARAM_ANONYMOUS_ID}
- *     or {@link UserConstants#DEFAULT_ANONYMOUS_ID} if the config option is
- *     missing.</li>
+ * <li>An administrator user using {@link UserConstants#PARAM_ADMIN_ID}
+ * or {@link UserConstants#DEFAULT_ADMIN_ID} if the config option is missing.</li>
+ * <li>An administrator user using {@link UserConstants#PARAM_ANONYMOUS_ID}
+ * or {@link UserConstants#DEFAULT_ANONYMOUS_ID} if the config option is
+ * missing.</li>
  * </ul>
- *
+ * <p/>
  * In addition this initializer sets up index definitions for the following
  * user related properties:
- *
+ * <p/>
  * <ul>
- *     <li>{@link UserConstants#REP_AUTHORIZABLE_ID}</li>
- *     <li>{@link UserConstants#REP_PRINCIPAL_NAME}</li>
- *     <li>{@link UserConstants#REP_MEMBERS}</li>
+ * <li>{@link UserConstants#REP_AUTHORIZABLE_ID}</li>
+ * <li>{@link UserConstants#REP_PRINCIPAL_NAME}</li>
+ * <li>{@link UserConstants#REP_MEMBERS}</li>
  * </ul>
  */
 public class UserInitializer implements RepositoryInitializer, UserConstants {
@@ -83,10 +83,11 @@ public class UserInitializer implements 
         try {
             NodeUtil rootTree = new NodeUtil(root.getTree("/"));
             NodeUtil index = rootTree.getOrAddChild(IndexConstants.INDEX_DEFINITIONS_NAME,
JcrConstants.NT_UNSTRUCTURED);
-            IndexUtils.createIndexDefinition(index, "authorizableId", true, UserConstants.REP_AUTHORIZABLE_ID);
-            // FIXME OAK-396: rep:principalName only needs to be unique if defined with user/group
nodes -> add defining nt-info to uniqueness constraint otherwise ac-editing will fail.
-            IndexUtils.createIndexDefinition(index, "principalName", true, UserConstants.REP_PRINCIPAL_NAME);
-            IndexUtils.createIndexDefinition(index, "members", false, UserConstants.REP_MEMBERS);
+            IndexUtils.createIndexDefinition(index, "authorizableId", true, new String[]{REP_AUTHORIZABLE_ID},
null);
+            IndexUtils.createIndexDefinition(index, "principalName", true,
+                    new String[]{REP_PRINCIPAL_NAME},
+                    new String[]{NT_REP_GROUP, NT_REP_USER});
+            IndexUtils.createIndexDefinition(index, "members", false, new String[]{UserConstants.REP_MEMBERS},
null);
 
             String adminId = userConfiguration.getConfigurationParameters().getConfigValue(PARAM_ADMIN_ID,
DEFAULT_ADMIN_ID);
             if (userManager.getAuthorizable(adminId) == null) {
@@ -108,4 +109,4 @@ public class UserInitializer implements 
             throw new RuntimeException(e);
         }
     }
-}
\ 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=1443483&r1=1443482&r2=1443483&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 Feb  7 13:59:39 2013
@@ -94,7 +94,7 @@ public class UserInitializerTest extends
 
     @Test
     public void testUserIndexDefinitions() throws Exception {
-        Tree oakIndex = root.getTree('/' +IndexConstants.INDEX_DEFINITIONS_NAME);
+        Tree oakIndex = root.getTree('/' + IndexConstants.INDEX_DEFINITIONS_NAME);
         assertNotNull(oakIndex);
 
         Tree id = oakIndex.getChild("authorizableId");
@@ -102,6 +102,8 @@ 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_GROUP, UserConstants.NT_REP_USER},
declaringNtNames);
 
         Tree members = oakIndex.getChild("members");
         assertIndexDefinition(members, UserConstants.REP_MEMBERS, false);
@@ -111,6 +113,6 @@ public class UserInitializerTest extends
         assertNotNull(tree);
 
         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}, TreeUtil.getStrings(tree, IndexConstants.PROPERTY_NAMES));
     }
-}
\ No newline at end of file
+}



Mime
View raw message