jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1363287 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: security/privilege/PrivilegeRegistry.java util/TODO.java
Date Thu, 19 Jul 2012 10:33:01 GMT
Author: jukka
Date: Thu Jul 19 10:33:00 2012
New Revision: 1363287

URL: http://svn.apache.org/viewvc?rev=1363287&view=rev
Log:
OAK-64: Privilege Management

Use the TODO class from OAK-193 to control the dummy registerDefinition() implementation.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeRegistry.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeRegistry.java?rev=1363287&r1=1363286&r2=1363287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeRegistry.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeRegistry.java
Thu Jul 19 10:33:00 2012
@@ -17,13 +17,17 @@
 package org.apache.jackrabbit.oak.security.privilege;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Callable;
+
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.util.ArrayUtils;
+import org.apache.jackrabbit.oak.util.TODO;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeProvider;
 
@@ -60,7 +64,7 @@ public class PrivilegeRegistry implement
         // TODO: define where custom privileges are being stored.
 
         for (String privilegeName : SIMPLE_PRIVILEGES) {
-            PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, false, new
String[0]);
+            PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, false);
             definitions.put(privilegeName, def);
         }
 
@@ -70,11 +74,11 @@ public class PrivilegeRegistry implement
         }
 
         // TODO: jcr:all needs to be recalculated if custom privileges are registered
-        definitions.put(JCR_ALL, new PrivilegeDefinitionImpl(JCR_ALL, false, new String[]
{
+        definitions.put(JCR_ALL, new PrivilegeDefinitionImpl(JCR_ALL, false,
             JCR_READ, JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL,
             JCR_VERSION_MANAGEMENT, JCR_LOCK_MANAGEMENT, JCR_LIFECYCLE_MANAGEMENT,
             JCR_RETENTION_MANAGEMENT, JCR_WORKSPACE_MANAGEMENT, JCR_NODE_TYPE_DEFINITION_MANAGEMENT,
-            JCR_NAMESPACE_MANAGEMENT, REP_PRIVILEGE_MANAGEMENT, REP_WRITE}));
+            JCR_NAMESPACE_MANAGEMENT, REP_PRIVILEGE_MANAGEMENT, REP_WRITE));
     }
 
     //--------------------------------------------------< PrivilegeProvider >---
@@ -90,15 +94,22 @@ public class PrivilegeRegistry implement
     }
 
     @Override
-    public PrivilegeDefinition registerDefinition(String privilegeName,
-                                                  boolean isAbstract,
-                                                  Set<String> declaredAggregateNames)
throws RepositoryException {
+    public PrivilegeDefinition registerDefinition(
+            final String privilegeName, final boolean isAbstract,
+            final Set<String> declaredAggregateNames)
+            throws RepositoryException {
         // TODO: check permission, validate and persist the custom definition
-        PrivilegeDefinition definition = new PrivilegeDefinitionImpl(
-                privilegeName, isAbstract,
-                declaredAggregateNames.toArray(new String[declaredAggregateNames.size()]));
-        definitions.put(privilegeName, definition);
-        return definition;
+        return TODO.dummyImplementation().call(new Callable<PrivilegeDefinition>()
{
+            @Override
+            public PrivilegeDefinition call() throws Exception {
+                PrivilegeDefinition definition = new PrivilegeDefinitionImpl(
+                        privilegeName, isAbstract,
+                        new HashSet<String>(declaredAggregateNames));
+                // TODO: update jcr:all
+                definitions.put(privilegeName, definition);
+                return definition;
+            }
+        });
     }
 
 
@@ -111,10 +122,15 @@ public class PrivilegeRegistry implement
         private final Set<String> declaredAggregateNames;
 
         private PrivilegeDefinitionImpl(String name, boolean isAbstract,
-                                        String[] declaredAggregateNames) {
+                                        Set<String> declaredAggregateNames) {
             this.name = name;
             this.isAbstract = isAbstract;
-            this.declaredAggregateNames = ArrayUtils.toSet(declaredAggregateNames);
+            this.declaredAggregateNames = declaredAggregateNames;
+        }
+
+        private PrivilegeDefinitionImpl(String name, boolean isAbstract,
+                                        String... declaredAggregateNames) {
+            this(name, isAbstract, ArrayUtils.toSet(declaredAggregateNames));
         }
 
         //--------------------------------------------< PrivilegeDefinition >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java?rev=1363287&r1=1363286&r2=1363287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TODO.java Thu
Jul 19 10:33:00 2012
@@ -16,8 +16,11 @@
  */
 package org.apache.jackrabbit.oak.util;
 
+import java.util.concurrent.Callable;
+
 import javax.jcr.UnsupportedRepositoryOperationException;
 
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,6 +42,10 @@ public class TODO {
         return new TODO("unimplemented");
     }
 
+    public static TODO dummyImplementation() {
+        return new TODO("dummy implementation");
+    }
+
     private final UnsupportedOperationException exception;
 
     private final Logger logger;
@@ -68,4 +75,21 @@ public class TODO {
             logger.warn(message, exception);
         }
     }
+
+    public <T> T call(Callable<T> callable)
+            throws UnsupportedRepositoryOperationException {
+        if (strict) {
+            throw new UnsupportedRepositoryOperationException(
+                    message, exception);
+        } else if (log) {
+            logger.warn(message, exception);
+        }
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new UnsupportedRepositoryOperationException(
+                    message + " failure", e);
+        }
+    }
+
 }



Mime
View raw message