jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1505945 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ oak-core/src/main/jav...
Date Tue, 23 Jul 2013 09:15:31 GMT
Author: angela
Date: Tue Jul 23 09:15:31 2013
New Revision: 1505945

URL: http://svn.apache.org/r1505945
Log:
OAK-764 : Oak error codes 

- complete list of error code names in CommitFailedException
- replace hardcoded error-code names by constants
- add AccessControlViolation error to allow destinguish between permission failure (access
denied) and access control violation
- simplify and unify conversion of commitfailedexception to repositoryexception throughout
the code base

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/ConflictValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidatorTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/JcrUUIDTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/NodeTypeManagementTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
Tue Jul 23 09:15:31 2013
@@ -16,13 +16,16 @@
  */
 package org.apache.jackrabbit.oak.api;
 
+import javax.annotation.Nonnull;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
+import javax.jcr.NamespaceException;
 import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.security.AccessControlException;
 import javax.jcr.version.VersionException;
 
 import static java.lang.String.format;
@@ -44,16 +47,53 @@ public class CommitFailedException exten
     public static final String ACCESS = "Access";
 
     /**
+     * Type name for access control violation errors.
+     */
+    public static final String ACCESS_CONTROL = "AccessControl";
+
+    /**
      * Type name for constraint violation errors.
      */
     public static final String CONSTRAINT = "Constraint";
 
     /**
+     * Type name for referencial integrity violation errors.
+     */
+    public static final String INTEGRITY = "Integrity";
+
+    /**
+     * Type name for lock violation errors.
+     */
+    public static final String LOCK = "Lock";
+
+    /**
+     * Type name for name violation errors.
+     */
+    public static final String NAME = "Name";
+
+    /**
+     * Type name for namespace violation errors.
+     */
+    public static final String NAMESPACE = "Namespace";
+
+    /**
+     * Type name for node type violation errors.
+     */
+    public static final String NODE_TYPE = "NodeType";
+
+    /**
+     * Type name for state violation errors.
+     */
+    public static final String STATE = "State";
+
+    /**
      * Type name for version violation errors.
      */
     public static final String VERSION = "Version";
 
-    /** Serial version UID */
+    /**
+     * Serial version UID
+     */
     private static final long serialVersionUID = 2727602333350620918L;
 
     private final String source;
@@ -100,6 +140,15 @@ public class CommitFailedException exten
     }
 
     /**
+     * Checks whether this is an access control violation exception.
+     *
+     * @return {@code true} iff this is an access control violation exception
+     */
+    public boolean isAccessControlViolation() {
+        return isOfType(ACCESS_CONTROL);
+    }
+
+    /**
      * Checks whether this is a constraint violation exception.
      *
      * @return {@code true} iff this is a constraint violation exception
@@ -143,22 +192,38 @@ public class CommitFailedException exten
      * @return matching repository exception
      */
     public RepositoryException asRepositoryException() {
+        return asRepositoryException(this.getMessage());
+    }
+
+    /**
+     * Wraps the given {@link CommitFailedException} instance using the
+     * appropriate {@link javax.jcr.RepositoryException} subclass based on the
+     * {@link CommitFailedException#getType() type} of the given exception.
+     *
+     * @param message The exception message.
+     * @return matching repository exception
+     */
+    public RepositoryException asRepositoryException(@Nonnull String message) {
         if (isConstraintViolation()) {
-            return new ConstraintViolationException(this);
-        } else if (isOfType("Type")) {
-            return new NoSuchNodeTypeException(this);
+            return new ConstraintViolationException(message, this);
+        } else if (isOfType(NAMESPACE)) {
+            return new NamespaceException(message, this);
+        } else if (isOfType(NODE_TYPE)) {
+            return new NoSuchNodeTypeException(message, this);
         } else if (isAccessViolation()) {
-            return new AccessDeniedException(this);
-        } else if (isOfType("Integrity")) {
-            return new ReferentialIntegrityException(this);
-        } else if (isOfType("State")) {
-            return new InvalidItemStateException(this);
-        } else if (isOfType("Version")) {
-            return new VersionException(this);
-        } else if (isOfType("Lock")) {
-            return new LockException(this);
+            return new AccessDeniedException(message, this);
+        } else if (isAccessControlViolation()) {
+            return new AccessControlException(message, this);
+        } else if (isOfType(INTEGRITY)) {
+            return new ReferentialIntegrityException(message, this);
+        } else if (isOfType(STATE)) {
+            return new InvalidItemStateException(message, this);
+        } else if (isOfType(VERSION)) {
+            return new VersionException(message, this);
+        } else if (isOfType(LOCK)) {
+            return new LockException(message, this);
         } else {
-            return new RepositoryException(this);
+            return new RepositoryException(message, this);
         }
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/ConflictValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/ConflictValidator.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/ConflictValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/ConflictValidator.java
Tue Jul 23 09:15:31 2013
@@ -80,7 +80,7 @@ public class ConflictValidator extends D
             for (String v : property.getValue(STRINGS)) {
                 if (NodeTypeConstants.MIX_REP_MERGE_CONFLICT.equals(v)) {
                     throw new CommitFailedException(
-                            "State", 1, "Unresolved conflicts in " + getPath());
+                            CommitFailedException.STATE, 1, "Unresolved conflicts in " +
getPath());
                 }
             }
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
Tue Jul 23 09:15:31 2013
@@ -44,7 +44,7 @@ class NameValidator extends DefaultValid
             String prefix = name.substring(0, colon);
             if (prefix.isEmpty() || !prefixes.contains(prefix)) {
                 throw new CommitFailedException(
-                        "Name", 1, "Invalid namespace prefix: " + name);
+                        CommitFailedException.NAME, 1, "Invalid namespace prefix: " + name);
             }
         }
 
@@ -58,7 +58,7 @@ class NameValidator extends DefaultValid
             }
             if (local.charAt(i) != '[') {
                 throw new CommitFailedException(
-                        "Name", 2, "Invalid name index " + name);
+                        CommitFailedException.NAME, 2, "Invalid name index " + name);
             } else {
                 local = local.substring(0, i);
             }
@@ -66,7 +66,7 @@ class NameValidator extends DefaultValid
 
         if (!Namespaces.isValidLocalName(local)) {
             throw new CommitFailedException(
-                    "Name", 3, "Invalid name: " + name);
+                    CommitFailedException.NAME, 3, "Invalid name: " + name);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
Tue Jul 23 09:15:31 2013
@@ -47,23 +47,23 @@ class NamespaceValidator extends Default
         }
         if (map.containsKey(prefix)) {
             throw new CommitFailedException(
-                    "Namespace", 1,
+                    CommitFailedException.NAMESPACE, 1,
                     "Namespace mapping already registered: " + prefix);
         } else if (Namespaces.isValidPrefix(prefix)) {
             if (after.isArray() || !STRING.equals(after.getType())) {
                 throw new CommitFailedException(
-                        "Namespace", 2,
+                        CommitFailedException.NAMESPACE, 2,
                         "Invalid namespace mapping: " + prefix);
             } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
                 throw new CommitFailedException(
-                        "Namespace", 3,
+                        CommitFailedException.NAMESPACE, 3,
                         "XML prefixes are reserved: " + prefix);
             } else if (map.containsValue(after.getValue(STRING))) {
                 throw modificationNotAllowed(prefix);
             }
         } else {
             throw new CommitFailedException(
-                    "Namespace", 4,
+                    CommitFailedException.NAMESPACE, 4,
                     "Not a valid namespace prefix: " + prefix);
         }
     }
@@ -86,7 +86,7 @@ class NamespaceValidator extends Default
 
     private static CommitFailedException modificationNotAllowed(String prefix) {
         return new CommitFailedException(
-                "Namespace", 5,
+                CommitFailedException.NAMESPACE, 5,
                 "Namespace modification not allowed: " + prefix);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
Tue Jul 23 09:15:31 2013
@@ -16,12 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.name;
 
-import static org.apache.jackrabbit.oak.api.Type.NAME;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-
 import java.util.Map;
-
-import javax.jcr.AccessDeniedException;
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 
@@ -31,6 +26,9 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+
 /**
  * Writable namespace registry. Mainly for use to implement the full JCR API.
  */
@@ -101,14 +99,8 @@ public abstract class ReadWriteNamespace
         } catch (CommitFailedException e) {
             String message =
                     "Failed to register namespace mapping from "
-                    + prefix + " to " + uri;
-            if (e.isOfType("Namespace")) {
-                throw new NamespaceException(message, e);
-            }  else if (e.isAccessViolation()) {
-                throw new AccessDeniedException(message, e);
-            } else {
-                throw new RepositoryException(message, e);
-            }
+                            + prefix + " to " + uri;
+            throw e.asRepositoryException(message);
         }
     }
 
@@ -119,7 +111,7 @@ public abstract class ReadWriteNamespace
         if (!namespaces.exists() || !namespaces.hasProperty(prefix)) {
             throw new NamespaceException(
                     "Namespace mapping from " + prefix + " to "
-                    + getURI(prefix) + " can not be unregistered");
+                            + getURI(prefix) + " can not be unregistered");
         }
 
         try {
@@ -128,13 +120,7 @@ public abstract class ReadWriteNamespace
             refresh();
         } catch (CommitFailedException e) {
             String message = "Failed to unregister namespace mapping for prefix " + prefix;
-            if (e.isOfType("Namespace")) {
-                throw new NamespaceException(message, e);
-            } else if (e.isAccessViolation()) {
-                throw new AccessDeniedException(message, e);
-            } else {
-                throw new RepositoryException(message, e);
-            }
+            throw e.asRepositoryException(message);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
Tue Jul 23 09:15:31 2013
@@ -16,13 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype.write;
 
-import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.annotation.Nonnull;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
@@ -41,15 +36,19 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
 /**
  * {@code ReadWriteNodeTypeManager} extends the {@link ReadOnlyNodeTypeManager}
  * with support for operations that modify node types.
  * <ul>
- *     <li>{@link #registerNodeType(NodeTypeDefinition, boolean)}</li>
- *     <li>{@link #registerNodeTypes(NodeTypeDefinition[], boolean)}</li>
- *     <li>{@link #unregisterNodeType(String)}</li>
- *     <li>{@link #unregisterNodeTypes(String[])}</li>
- *     <li>plus related template factory methods</li>
+ * <li>{@link #registerNodeType(NodeTypeDefinition, boolean)}</li>
+ * <li>{@link #registerNodeTypes(NodeTypeDefinition[], boolean)}</li>
+ * <li>{@link #unregisterNodeType(String)}</li>
+ * <li>{@link #unregisterNodeTypes(String[])}</li>
+ * <li>plus related template factory methods</li>
  * </ul>
  * Calling any of the above methods will result in a {@link #refresh()} callback
  * to e.g. inform an associated session that it should refresh to make the
@@ -62,14 +61,14 @@ import org.apache.jackrabbit.oak.plugins
  * also want to override the default implementation of
  * {@link ReadOnlyNodeTypeManager} for the following methods:
  * <ul>
- *     <li>{@link #getValueFactory()}</li>
- *     <li>{@link ReadOnlyNodeTypeManager#getNamePathMapper()}</li>
+ * <li>{@link #getValueFactory()}</li>
+ * <li>{@link ReadOnlyNodeTypeManager#getNamePathMapper()}</li>
  * </ul>
  */
 public abstract class ReadWriteNodeTypeManager extends ReadOnlyNodeTypeManager {
 
     /**
-     * Called by the methods {@link #registerNodeType(NodeTypeDefinition,boolean)},
+     * Called by the methods {@link #registerNodeType(NodeTypeDefinition, boolean)},
      * {@link #registerNodeTypes(NodeTypeDefinition[], boolean)},
      * {@link #unregisterNodeType(String)} and {@link #unregisterNodeTypes(String[])}
      * to acquire a fresh {@link Root} instance that can be used to persist the
@@ -123,7 +122,7 @@ public abstract class ReadWriteNodeTypeM
             NodeTypeDefinition ntd, boolean allowUpdate)
             throws RepositoryException {
         return registerNodeTypes(
-                new NodeTypeDefinition[] { ntd }, allowUpdate).nextNodeType();
+                new NodeTypeDefinition[]{ntd}, allowUpdate).nextNodeType();
     }
 
     @Override
@@ -156,11 +155,7 @@ public abstract class ReadWriteNodeTypeM
             return new NodeTypeIteratorAdapter(types);
         } catch (CommitFailedException e) {
             String message = "Failed to register node types.";
-            if (e.isAccessViolation()) {
-                throw new AccessDeniedException(message, e);
-            } else {
-                throw new RepositoryException(message, e);
-            }
+            throw e.asRepositoryException(message);
         }
     }
 
@@ -190,11 +185,7 @@ public abstract class ReadWriteNodeTypeM
             refresh();
         } catch (CommitFailedException e) {
             String message = "Failed to unregister node type " + name;
-            if (e.isAccessViolation()) {
-                throw new AccessDeniedException(message, e);
-            } else {
-                throw new RepositoryException(message, e);
-            }
+            throw e.asRepositoryException(message);
         }
     }
 
@@ -218,11 +209,7 @@ public abstract class ReadWriteNodeTypeM
             refresh();
         } catch (CommitFailedException e) {
             String message = "Failed to unregister node types.";
-            if (e.isAccessViolation()) {
-                throw new AccessDeniedException(message, e);
-            } else {
-                throw new RepositoryException(message, e);
-            }
+            throw e.asRepositoryException(message);
         }
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidator.java
Tue Jul 23 09:15:31 2013
@@ -16,14 +16,10 @@
  */
 package org.apache.jackrabbit.oak.security.authorization;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.CommitFailedException.ACCESS;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
-
 import javax.jcr.security.AccessControlException;
 import javax.jcr.security.Privilege;
 
@@ -41,6 +37,9 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.apache.jackrabbit.util.Text;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.CommitFailedException.ACCESS_CONTROL;
+
 /**
  * Validation for access control information changed by regular JCR (and Jackrabbit)
  * access control management API.
@@ -220,7 +219,7 @@ class AccessControlValidator extends Def
         try {
             restrictionProvider.validateRestrictions(path, aceTree);
         } catch (AccessControlException e) {
-            throw new CommitFailedException(ACCESS, 1, "Access control violation", e);
+            throw new CommitFailedException(ACCESS_CONTROL, 1, "Access control violation",
e);
         }
     }
 
@@ -239,6 +238,6 @@ class AccessControlValidator extends Def
     }
 
     private static CommitFailedException accessViolation(int code, String message) {
-        return new CommitFailedException(ACCESS, code, message);
+        return new CommitFailedException(ACCESS_CONTROL, code, message);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
Tue Jul 23 09:15:31 2013
@@ -118,11 +118,7 @@ class PrivilegeDefinitionWriter implemen
             root.commit();
 
         } catch (CommitFailedException e) {
-            if (e.isAccessViolation()) {
-                throw new AccessDeniedException(e);
-            } else {
-                throw new RepositoryException(e);
-            }
+            throw e.asRepositoryException();
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidatorTest.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidatorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AccessControlValidatorTest.java
Tue Jul 23 09:15:31 2013
@@ -99,8 +99,8 @@ public class AccessControlValidatorTest 
             fail("Policy node with child node ordering");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
-            assertEquals("OakAccess0004: Invalid policy node: Order of children is not stable.",
e.getMessage());
+            assertTrue(e.isAccessControlViolation());
+            assertEquals("OakAccessControl0004: Invalid policy node: Order of children is
not stable.", e.getMessage());
         }
     }
 
@@ -114,7 +114,7 @@ public class AccessControlValidatorTest 
             fail("Only the root node can be made RepoAccessControllable.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         }
     }
 
@@ -128,7 +128,7 @@ public class AccessControlValidatorTest 
             fail("Attempt to add repo-policy with rep:AccessControllable node.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         } finally {
             policy.getTree().remove();
         }
@@ -147,7 +147,7 @@ public class AccessControlValidatorTest 
                 fail("Adding an ACL below access control content should fail");
             } catch (CommitFailedException e) {
                 // success
-                assertTrue(e.isAccessViolation());
+                assertTrue(e.isAccessControlViolation());
             } finally {
                 policy.getTree().remove();
             }
@@ -167,7 +167,7 @@ public class AccessControlValidatorTest 
                 fail("Adding an ACL below access control content should fail");
             } catch (CommitFailedException e) {
                 // success
-                assertTrue(e.isAccessViolation());
+                assertTrue(e.isAccessControlViolation());
             } finally {
                 policy.getTree().remove();
             }
@@ -187,7 +187,7 @@ public class AccessControlValidatorTest 
                 fail("Adding an ACE below an ACE or restriction should fail");
             } catch (CommitFailedException e) {
                 // success
-                assertTrue(e.isAccessViolation());
+                assertTrue(e.isAccessControlViolation());
             } finally {
                 entry.getTree().remove();
             }
@@ -207,7 +207,7 @@ public class AccessControlValidatorTest 
                 fail("Adding an ACE below an ACE or restriction should fail");
             } catch (CommitFailedException e) {
                 // success
-                assertTrue(e.isAccessViolation());
+                assertTrue(e.isAccessControlViolation());
             } finally {
                 entry.getTree().remove();
             }
@@ -226,7 +226,7 @@ public class AccessControlValidatorTest 
                 fail("Writing an isolated ACL without the parent being rep:AccessControllable
should fail.");
             } catch (CommitFailedException e) {
                 // success
-                assertTrue(e.isAccessViolation());
+                assertTrue(e.isAccessControlViolation());
             } finally {
                 // revert pending changes that cannot be saved.
                 policy.getTree().remove();
@@ -247,7 +247,7 @@ public class AccessControlValidatorTest 
                 fail("Writing an isolated ACE should fail.");
             } catch (CommitFailedException e) {
                 // success
-                assertTrue(e.isAccessViolation());
+                assertTrue(e.isAccessControlViolation());
             } finally {
                 // revert pending changes that cannot be saved.
                 ace.getTree().remove();
@@ -264,7 +264,7 @@ public class AccessControlValidatorTest 
             fail("Writing an isolated Restriction should fail.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         } finally {
             // revert pending changes that cannot be saved.
             restriction.getTree().remove();
@@ -282,7 +282,7 @@ public class AccessControlValidatorTest 
             fail("Creating an ACE with invalid privilege should fail.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         }
     }
 
@@ -298,7 +298,7 @@ public class AccessControlValidatorTest 
             fail("Creating an ACE with an abstract privilege should fail.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         }
     }
 
@@ -311,7 +311,7 @@ public class AccessControlValidatorTest 
             fail("Creating an unsupported restriction should fail.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         }
     }
 
@@ -324,7 +324,7 @@ public class AccessControlValidatorTest 
             fail("Creating restriction with invalid type should fail.");
         } catch (CommitFailedException e) {
             // success
-            assertTrue(e.isAccessViolation());
+            assertTrue(e.isAccessControlViolation());
         }
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/JcrUUIDTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/JcrUUIDTest.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/JcrUUIDTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/JcrUUIDTest.java
Tue Jul 23 09:15:31 2013
@@ -55,6 +55,7 @@ public class JcrUUIDTest extends Abstrac
             protected Root getWriteRoot() {
                 return root;
             }
+
             @Override
             protected Tree getTypes() {
                 return root.getTree(NODE_TYPES_PATH);
@@ -63,7 +64,7 @@ public class JcrUUIDTest extends Abstrac
         if (!ntMgr.hasNodeType(NT_NAME)) {
             NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
             tmpl.setName(NT_NAME);
-            tmpl.setDeclaredSuperTypeNames(new String[] {JcrConstants.MIX_REFERENCEABLE,
JcrConstants.NT_UNSTRUCTURED});
+            tmpl.setDeclaredSuperTypeNames(new String[]{JcrConstants.MIX_REFERENCEABLE, JcrConstants.NT_UNSTRUCTURED});
             ntMgr.registerNodeType(tmpl, true);
         }
 
@@ -113,7 +114,7 @@ public class JcrUUIDTest extends Abstrac
             testRoot.commit();
             fail("Creating a referenceable node with an invalid uuid must fail.");
         } catch (CommitFailedException e) {
-            assertEquals(CommitFailedException.CONSTRAINT, e.getType());
+            assertTrue(e.isConstraintViolation());
             assertEquals(12, e.getCode());
         }
     }
@@ -135,7 +136,7 @@ public class JcrUUIDTest extends Abstrac
             testRoot.commit();
             fail("Creating a referenceable node with an boolean uuid must fail.");
         } catch (CommitFailedException e) {
-            assertEquals(CommitFailedException.CONSTRAINT, e.getType());
+            assertTrue(e.isConstraintViolation());
         }
     }
 
@@ -173,7 +174,7 @@ public class JcrUUIDTest extends Abstrac
             testRoot.commit();
             fail("An attempt to change the jcr:uuid property must fail");
         } catch (CommitFailedException e) {
-            assertEquals(CommitFailedException.CONSTRAINT, e.getType());
+            assertTrue(e.isConstraintViolation());
             assertEquals(12, e.getCode());
         }
     }
@@ -215,7 +216,7 @@ public class JcrUUIDTest extends Abstrac
             testRoot.commit();
             fail("Removing the jcr:uuid property of a referenceable node must fail.");
         } catch (CommitFailedException e) {
-            assertEquals(CommitFailedException.CONSTRAINT, e.getType());
+            assertTrue(e.isConstraintViolation());
             assertEquals(22, e.getCode());
         }
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
Tue Jul 23 09:15:31 2013
@@ -17,13 +17,9 @@
 package org.apache.jackrabbit.oak.jcr.version;
 
 import javax.annotation.Nonnull;
-import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
@@ -48,7 +44,7 @@ public class ReadWriteVersionManager ext
     private final Root workspaceRoot;
 
     public ReadWriteVersionManager(@Nonnull Tree versionStorage,
-            @Nonnull Root workspaceRoot) {
+                                   @Nonnull Root workspaceRoot) {
         this.versionStorage = checkNotNull(versionStorage);
         this.workspaceRoot = checkNotNull(workspaceRoot);
     }
@@ -129,10 +125,10 @@ public class ReadWriteVersionManager ext
      *
      * @param versionable the versionable node to check out.
      * @throws UnsupportedRepositoryOperationException
-     *                                   if the versionable tree isn't actually
-     *                                   versionable.
-     * @throws RepositoryException       if an error occurs while checking the
-     *                                   node type of the tree.
+     *                             if the versionable tree isn't actually
+     *                             versionable.
+     * @throws RepositoryException if an error occurs while checking the
+     *                             node type of the tree.
      */
     public void checkout(@Nonnull Tree versionable)
             throws UnsupportedRepositoryOperationException,
@@ -171,18 +167,6 @@ public class ReadWriteVersionManager ext
      * @return matching repository exception
      */
     private static RepositoryException newRepositoryException(@Nonnull CommitFailedException
exception) {
-        if (exception.isConstraintViolation()) {
-            return new ConstraintViolationException(exception);
-        } else if (exception.isAccessViolation()) {
-            return new AccessDeniedException(exception);
-        } else if (exception.isOfType("State")) {
-            return new InvalidItemStateException(exception);
-        } else if (exception.isOfType(CommitFailedException.VERSION)) {
-            return new VersionException(exception);
-        } else if (exception.isOfType("Lock")) {
-            return new LockException(exception);
-        } else {
-            return new RepositoryException(exception);
-        }
+        return exception.asRepositoryException();
     }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/NodeTypeManagementTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/NodeTypeManagementTest.java?rev=1505945&r1=1505944&r2=1505945&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/NodeTypeManagementTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/NodeTypeManagementTest.java
Tue Jul 23 09:15:31 2013
@@ -84,7 +84,6 @@ public class NodeTypeManagementTest exte
         testSession.save();
     }
 
-    @Ignore("OAK-767 : Implement Node#removeMixin")
     @Test
     public void testRemoveMixinWithoutPermission() throws Exception {
         ((Node) superuser.getItem(childNode.getPath())).addMixin(mixinName);
@@ -100,7 +99,6 @@ public class NodeTypeManagementTest exte
         }
     }
 
-    @Ignore("OAK-767 : Implement Node#removeMixin")
     @Test
     public void testRemoveMixin() throws Exception {
         ((Node) superuser.getItem(childNode.getPath())).addMixin(mixinName);



Mime
View raw message