jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1436845 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/index/ plugins/index/old/ plugins/nodetype/write/ security/user/
Date Tue, 22 Jan 2013 11:49:16 GMT
Author: angela
Date: Tue Jan 22 11:49:16 2013
New Revision: 1436845

URL: http://svn.apache.org/viewvc?rev=1436845&view=rev
Log:
OAK-570 : Move user mgt related index definitions to security/user

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/index/old/PropertyIndexConstants.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/user/UserInitializer.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=1436845&r1=1436844&r2=1436845&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
Tue Jan 22 11:49:16 2013
@@ -31,4 +31,14 @@ public interface IndexConstants {
 
     String REINDEX_PROPERTY_NAME = "reindex";
 
+    /**
+     * Marks a unique property index.
+     */
+    String UNIQUE = "unique";
+
+    /**
+     * Defines the names of the properties that are covered by a specific
+     * property index definition.
+     */
+    String PROPERTY_NAMES = "propertyNames";
 }

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=1436845&r1=1436844&r2=1436845&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
Tue Jan 22 11:49:16 2013
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.index;
 
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -26,6 +23,10 @@ import java.util.List;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.NodeUtil;
+
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 
 /**
  * TODO document
@@ -33,10 +34,31 @@ import org.apache.jackrabbit.oak.spi.sta
 public class IndexUtils implements IndexConstants {
 
     /**
+     * Create a new property2 index definition below the given {@code indexNode}.
+     *
+     * @param indexNode
+     * @param indexDefName
+     * @param unique
+     * @param propertyNames
+     */
+    public static void createIndexDefinition(NodeUtil indexNode,
+                                             String indexDefName,
+                                             boolean unique,
+                                             String... propertyNames) {
+        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, true);
+        }
+        entry.setNames(IndexConstants.PROPERTY_NAMES, propertyNames);
+    }
+
+    /**
      * Builds a list of the existing index definitions.
      * 
      * Checks only children of the provided state for an index definitions
-     * container node, aka a node named {@link INDEX_DEFINITIONS_NAME}
+     * container node, aka a node named {@link #INDEX_DEFINITIONS_NAME}
      * 
      * @return
      */

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java?rev=1436845&r1=1436844&r2=1436845&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyIndexConstants.java
Tue Jan 22 11:49:16 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.old;
 
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
 
 public interface PropertyIndexConstants {
@@ -50,6 +51,6 @@ public interface PropertyIndexConstants 
     /**
      * Marks a unique index.
      */
-    String UNIQUE = "unique";
+    String UNIQUE = IndexConstants.UNIQUE;
 
 }

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=1436845&r1=1436844&r2=1436845&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
Tue Jan 22 11:49:16 2013
@@ -23,7 +23,6 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.core.RootImpl;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
-import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
@@ -80,25 +79,6 @@ public class InitialContent implements R
                         "propertyNames",
                         ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES),
                         Type.STRINGS));
-            // FIXME OAK-570:user-mgt related unique properties (rep:authorizableId, rep:principalName,
rep:members) are implementation detail and not generic for repo
-            // 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.
-            index.child("authorizableId")
-                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
-                .setProperty("type", "p2")
-                .setProperty("propertyNames", UserConstants.REP_AUTHORIZABLE_ID)
-                .setProperty("reindex", true)
-                .setProperty("unique", true);
-            index.child("principalName")
-                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
-                .setProperty("type", "p2")
-                .setProperty("propertyNames", UserConstants.REP_PRINCIPAL_NAME)
-                .setProperty("reindex", true)
-                .setProperty("unique", true);
-            index.child("members")
-                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
-                .setProperty("type", "p2")
-                .setProperty("propertyNames", UserConstants.REP_MEMBERS)
-                .setProperty("reindex", true);
         }
         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=1436845&r1=1436844&r2=1436845&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
Tue Jan 22 11:49:16 2013
@@ -18,16 +18,20 @@ package org.apache.jackrabbit.oak.securi
 
 import javax.jcr.RepositoryException;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.core.RootImpl;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,6 +49,15 @@ import org.slf4j.LoggerFactory;
  *     or {@link UserConstants#DEFAULT_ANONYMOUS_ID} if the config option is
  *     missing.</li>
  * </ul>
+ *
+ * In addition this initializer sets up index definitions for the following
+ * user related properties:
+ *
+ * <ul>
+ *     <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 {
 
@@ -68,19 +81,23 @@ public class UserInitializer implements 
         UserManager userManager = userConfiguration.getUserManager(root, NamePathMapper.DEFAULT);
 
         try {
-            boolean modified = false;
+            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);
+
             String adminId = userConfiguration.getConfigurationParameters().getConfigValue(PARAM_ADMIN_ID,
DEFAULT_ADMIN_ID);
             if (userManager.getAuthorizable(adminId) == null) {
                 // TODO: init admin with null password and force application to set it.
                 userManager.createUser(adminId, adminId);
-                modified = true;
             }
             String anonymousId = userConfiguration.getConfigurationParameters().getConfigValue(PARAM_ANONYMOUS_ID,
DEFAULT_ANONYMOUS_ID);
             if (userManager.getAuthorizable(anonymousId) == null) {
                 userManager.createUser(anonymousId, null);
-                modified = true;
             }
-            if (modified) {
+            if (root.hasPendingChanges()) {
                 root.commit();
             }
         } catch (RepositoryException e) {



Mime
View raw message