jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1381238 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type: NodeTypeImpl.java TypeValidator.java
Date Wed, 05 Sep 2012 16:39:53 GMT
Author: mduerig
Date: Wed Sep  5 16:39:53 2012
New Revision: 1381238

URL: http://svn.apache.org/viewvc?rev=1381238&view=rev
Log:
OAK-66: JCR Node Type Management
node type validation (WIP)
TODO: temporary solution for handing SNS for child node constraints
TODO: temporary solution for writing protected items

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java?rev=1381238&r1=1381237&r2=1381238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
Wed Sep  5 16:39:53 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.type;
 
+import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -34,8 +35,10 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
+import javax.security.auth.Subject;
 
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
+import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -293,7 +296,7 @@ class NodeTypeImpl implements NodeType {
     public boolean canAddChildNode(String childNodeName) {
         for (NodeDefinition definition : getChildNodeDefinitions()) {
             String name = definition.getName();
-            if ((childNodeName.equals(name) && !definition.isProtected())
+            if ((matches(childNodeName, name) && !isProtected(definition))
                     || "*".equals(name)) {
                 return true;
             }
@@ -314,7 +317,7 @@ class NodeTypeImpl implements NodeType {
         }
         for (NodeDefinition definition : getChildNodeDefinitions()) {
             String name = definition.getName();
-            if ((childNodeName.equals(name) && !definition.isProtected())
+            if ((matches(childNodeName, name) && !isProtected(definition))
                     || "*".equals(name)) {
                 for (String required : definition.getRequiredPrimaryTypeNames()) {
                     if (type.isNodeType(required)) {
@@ -335,7 +338,7 @@ class NodeTypeImpl implements NodeType {
     public boolean canRemoveNode(String nodeName) {
         for (PropertyDefinition definition : getPropertyDefinitions()) {
             String name = definition.getName();
-            if (nodeName.equals(name)) {
+            if (matches(nodeName, name)) {
                 if (definition.isMandatory() || definition.isProtected()) {
                     return false;
                 }
@@ -357,4 +360,15 @@ class NodeTypeImpl implements NodeType {
         return true;
     }
 
+    private static boolean matches(String childNodeName, String name) {
+        // TODO need a better way to handle SNS
+        return childNodeName.startsWith(name);
+    }
+
+    private static boolean isProtected(NodeDefinition definition) {
+        // TODO need a better way for setting protected items internally
+        Subject subject = Subject.getSubject(AccessController.getContext());
+        return !subject.getPrincipals().contains(AdminPrincipal.INSTANCE) && definition.isProtected();
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java?rev=1381238&r1=1381237&r2=1381238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
Wed Sep  5 16:39:53 2012
@@ -278,8 +278,7 @@ class TypeValidator implements Validator
             return Iterables.any(allTypes, new Predicate<NodeType>() {
                 @Override
                 public boolean apply(NodeType nt) {
-                    return true;
-                    // TODO return nt.canAddChildNode(name, ntName);
+                    return nt.canAddChildNode(name, ntName);
                 }
             });
         }



Mime
View raw message