jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1446289 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: ./ plugins/version/ security/authorization/ security/privilege/ spi/commit/ spi/security/
Date Thu, 14 Feb 2013 18:18:01 GMT
Author: angela
Date: Thu Feb 14 18:18:01 2013
New Revision: 1446289

URL: http://svn.apache.org/r1446289
Log:
OAK-625 : Ability to pass workspace name to a CommitHook

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitHookProvider.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionablePathHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlConfigurationImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/PermissionHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/SecurityConfiguration.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1446289&r1=1446288&r2=1446289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Thu Feb
14 18:18:01 2013
@@ -33,9 +33,11 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.IndexHookManager;
 import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CommitHookProvider;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
@@ -79,7 +81,7 @@ public class Oak {
 
     private List<ValidatorProvider> validatorProviders = newArrayList();
 
-    private List<CommitHook> securityHooks = newArrayList();
+    private List<CommitHookProvider> securityHookProviders = newArrayList();
 
     // TODO: review if we really want to have the OpenSecurityProvider as default.
     private SecurityProvider securityProvider = new OpenSecurityProvider();
@@ -174,9 +176,16 @@ public class Oak {
      * is used to create the content repository.
      */
     private void withSecurityHooks() {
-        if (!securityHooks.isEmpty()) {
-            commitHooks.addAll(securityHooks);
-            securityHooks = newArrayList();
+        if (!securityHookProviders.isEmpty()) {
+            for (CommitHookProvider provider : securityHookProviders) {
+                // FIXME: hack to pass the workspace name into the commit hook
+                // FIXME: this needs to be re-factored once we add support for multiple workspaces
support (OAK-118)
+                CommitHook hook = provider.getCommitHook(defaultWorkspaceName);
+                if (hook != EmptyHook.INSTANCE) {
+                    commitHooks.add(hook);
+                }
+            }
+            securityHookProviders = newArrayList();
         }
     }
 
@@ -216,7 +225,7 @@ public class Oak {
         this.securityProvider = securityProvider;
         for (SecurityConfiguration sc : securityProvider.getSecurityConfigurations()) {
             validatorProviders.addAll(sc.getValidatorProviders());
-            securityHooks.addAll(sc.getCommitHooks());
+            securityHookProviders.add(sc.getCommitHookProvider());
             initializers.add(sc.getRepositoryInitializer());
         }
         return this;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionablePathHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionablePathHook.java?rev=1446289&r1=1446288&r2=1446289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionablePathHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionablePathHook.java
Thu Feb 14 18:18:01 2013
@@ -41,6 +41,12 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 public class VersionablePathHook implements CommitHook {
 
+    private final String workspaceName;
+
+    public VersionablePathHook(String workspaceName) {
+        this.workspaceName = workspaceName;
+    }
+
     @Nonnull
     @Override
     public NodeState processCommit(final NodeState before, NodeState after) throws CommitFailedException
{
@@ -51,7 +57,7 @@ public class VersionablePathHook impleme
         return rootBuilder.getNodeState();
     }
 
-    private static final class Diff extends DefaultNodeStateDiff implements VersionConstants
{
+    private final class Diff extends DefaultNodeStateDiff implements VersionConstants {
 
         private final ReadWriteVersionManager versionManager;
         private final Node nodeAfter;
@@ -71,8 +77,6 @@ public class VersionablePathHook impleme
                     vhBuilder.setProperty(JcrConstants.JCR_MIXINTYPES, MIX_REP_VERSIONABLE_PATHS,
Type.PATH);
                 }
 
-                // FIXME: property pass the current workspace name to the processCommit call.
-                String workspaceName = "default";
                 String versionablePath = nodeAfter.path;
                 vhBuilder.setProperty(workspaceName, versionablePath);
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlConfigurationImpl.java?rev=1446289&r1=1446288&r2=1446289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlConfigurationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlConfigurationImpl.java
Thu Feb 14 18:18:01 2013
@@ -24,12 +24,13 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.jcr.security.AccessControlManager;
 
-import com.google.common.collect.ImmutableList;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.version.VersionablePathHook;
 import org.apache.jackrabbit.oak.security.authorization.restriction.RestrictionProviderImpl;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CommitHookProvider;
+import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.Context;
@@ -60,6 +61,31 @@ public class AccessControlConfigurationI
 
     @Nonnull
     @Override
+    public RepositoryInitializer getRepositoryInitializer() {
+        return new AccessControlInitializer();
+    }
+
+    @Nonnull
+    @Override
+    public CommitHookProvider getCommitHookProvider() {
+        return new CommitHookProvider() {
+            @Override
+            public CommitHook getCommitHook(String workspaceName) {
+                return new CompositeHook(new PermissionHook(workspaceName), new VersionablePathHook(workspaceName));
+            }
+        };
+    }
+
+    @Override
+    public List<ValidatorProvider> getValidatorProviders() {
+        List<ValidatorProvider> vps = new ArrayList<ValidatorProvider>();
+        vps.add(new PermissionValidatorProvider(securityProvider));
+        vps.add(new AccessControlValidatorProvider(securityProvider));
+        return Collections.unmodifiableList(vps);
+    }
+
+    @Nonnull
+    @Override
     public List<ProtectedItemImporter> getProtectedItemImporters() {
         return Collections.<ProtectedItemImporter>singletonList(new AccessControlImporter(securityProvider));
     }
@@ -83,25 +109,4 @@ public class AccessControlConfigurationI
         // TODO OAK-51
         return new TmpPermissionProvider(root, principals, securityProvider);
     }
-
-    @Nonnull
-    @Override
-    public RepositoryInitializer getRepositoryInitializer() {
-        return new AccessControlInitializer();
-    }
-
-    @Nonnull
-    @Override
-    public List<CommitHook> getCommitHooks() {
-        // TODO: review if VersionablePathHook should be included here
-        return ImmutableList.of(new PermissionHook(), new VersionablePathHook());
-    }
-
-    @Override
-    public List<ValidatorProvider> getValidatorProviders() {
-        List<ValidatorProvider> vps = new ArrayList<ValidatorProvider>();
-        vps.add(new PermissionValidatorProvider(securityProvider));
-        vps.add(new AccessControlValidatorProvider(securityProvider));
-        return Collections.unmodifiableList(vps);
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/PermissionHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/PermissionHook.java?rev=1446289&r1=1446288&r2=1446289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/PermissionHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/PermissionHook.java
Thu Feb 14 18:18:01 2013
@@ -46,13 +46,17 @@ public class PermissionHook implements C
 
     private static final Logger log = LoggerFactory.getLogger(PermissionHook.class);
 
+    private final String workspaceName;
+
+    PermissionHook(String workspaceName) {
+        this.workspaceName = workspaceName;
+    }
+
     @Nonnull
     @Override
     public NodeState processCommit(final NodeState before, NodeState after) throws CommitFailedException
{
         NodeBuilder rootBuilder = after.builder();
 
-        // TODO: retrieve workspace name
-        String workspaceName = "default";
         NodeBuilder permissionRoot = getPermissionRoot(rootBuilder, workspaceName);
         ReadOnlyNodeTypeManager ntMgr = ReadOnlyNodeTypeManager.getInstance(before);
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImpl.java?rev=1446289&r1=1446288&r2=1446289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImpl.java
Thu Feb 14 18:18:01 2013
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CommitHookProvider;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.Context;
@@ -51,8 +52,13 @@ public class PrivilegeConfigurationImpl 
 
     @Nonnull
     @Override
-    public List<CommitHook> getCommitHooks() {
-        return Collections.<CommitHook>singletonList(new JcrAllCommitHook());
+    public CommitHookProvider getCommitHookProvider() {
+        return new CommitHookProvider() {
+            @Override
+            public CommitHook getCommitHook(String workspaceName) {
+                return new JcrAllCommitHook();
+            }
+        };
     }
 
     @Nonnull

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitHookProvider.java?rev=1446289&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitHookProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitHookProvider.java
Thu Feb 14 18:18:01 2013
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.spi.commit;
+
+import javax.annotation.Nonnull;
+
+/**
+ * {@code CommitHookProvider} TODO
+ *
+ * FIXME: needs re-evaluation and review once we add support for multiple workspaces (OAK-118)
+ */
+public interface CommitHookProvider {
+
+    /**
+     * Create a new {@code CommitHook} to deal with modifications on the
+     * workspace with the specified {@code workspaceName}.
+     *
+     * @param workspaceName The name of the workspace.
+     * @return A CommitHook instance.
+     */
+    @Nonnull
+    CommitHook getCommitHook(String workspaceName);
+
+    /**
+     * Default implementation that returns an {@code EmptyHook}.
+     */
+    final class Empty implements CommitHookProvider {
+
+        @Override
+        public CommitHook getCommitHook(String workspaceName) {
+            return EmptyHook.INSTANCE;
+        }
+    }
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/SecurityConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/SecurityConfiguration.java?rev=1446289&r1=1446288&r2=1446289&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/SecurityConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/SecurityConfiguration.java
Thu Feb 14 18:18:01 2013
@@ -22,8 +22,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
-import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.commit.CommitHookProvider;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.lifecycle.CompositeInitializer;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
@@ -41,7 +40,7 @@ public interface SecurityConfiguration {
     RepositoryInitializer getRepositoryInitializer();
 
     @Nonnull
-    List<CommitHook> getCommitHooks();
+    CommitHookProvider getCommitHookProvider();
 
     @Nonnull
     List<ValidatorProvider> getValidatorProviders();
@@ -71,8 +70,8 @@ public interface SecurityConfiguration {
 
         @Nonnull
         @Override
-        public List<CommitHook> getCommitHooks() {
-            return Collections.<CommitHook>singletonList(new EmptyHook());
+        public CommitHookProvider getCommitHookProvider() {
+            return new CommitHookProvider.Empty();
         }
 
         @Nonnull



Mime
View raw message