jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r810471 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/xml/ test/java/org/apache/jackrabbit/core/xml/
Date Wed, 02 Sep 2009 12:10:51 GMT
Author: tripod
Date: Wed Sep  2 12:10:51 2009
New Revision: 810471

URL: http://svn.apache.org/viewvc?rev=810471&view=rev
Log:
JCR-2195 Provide possibility to import protected items using Session/Workspace import 

Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/ProtectedItemHandlers.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/AccessControlImporter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SessionImporter.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/AccessControlImporterTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=810471&r1=810470&r2=810471&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Wed Sep  2 12:10:51 2009
@@ -51,8 +51,8 @@
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 import org.apache.jackrabbit.core.xml.ImportHandler;
 import org.apache.jackrabbit.core.xml.SessionImporter;
-import org.apache.jackrabbit.core.xml.ProtectedItemHandlers;
 import org.apache.jackrabbit.core.xml.AccessControlImporter;
+import org.apache.jackrabbit.core.xml.ProtectedNodeImporter;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
@@ -1174,9 +1174,8 @@
                 ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
         getValidator().checkModify(parent, options, Permission.NONE);
 
-        ProtectedItemHandlers pih = new ProtectedItemHandlers();
-        pih.register(new AccessControlImporter(this, this, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW));
-        SessionImporter importer = new SessionImporter(parent, this, uuidBehavior, pih);
+        ProtectedNodeImporter pi = new AccessControlImporter(this, this, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
+        SessionImporter importer = new SessionImporter(parent, this, uuidBehavior, pi, null);
         return new ImportHandler(importer, this);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/AccessControlImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/AccessControlImporter.java?rev=810471&r1=810470&r2=810471&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/AccessControlImporter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/AccessControlImporter.java
Wed Sep  2 12:10:51 2009
@@ -88,7 +88,11 @@
 
     public boolean start(NodeImpl protectedParent) throws RepositoryException {
         if (isStarted()) {
-            throw new IllegalStateException();
+            // only ok if same parent
+            if (!protectedParent.isSame(parent)) {
+                throw new IllegalStateException();
+            }
+            return true;
         }
         if (isWorkspaceImport) {
             log.debug("AccessControlImporter may not be used with the WorkspaceImporter");

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SessionImporter.java?rev=810471&r1=810470&r2=810471&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SessionImporter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SessionImporter.java
Wed Sep  2 12:10:51 2009
@@ -63,14 +63,14 @@
     private final ReferenceChangeTracker refTracker;
 
     /**
-     * Current importer for protected nodes.
+     * Importer for protected nodes.
      */
-    private ProtectedNodeImporter currentNodeImporter;
+    private final ProtectedNodeImporter pnImporter;
 
     /**
-     * Handlers for protected items.
+     * Importer for protected properties.
      */
-    private final ProtectedItemHandlers protectedItemHandlers;
+    private final ProtectedPropertyImporter ppImporter;
 
     /**
      * Creates a new <code>SessionImporter</code> instance.
@@ -83,7 +83,7 @@
     public SessionImporter(NodeImpl importTargetNode,
                            SessionImpl session,
                            int uuidBehavior) {
-        this(importTargetNode, session, uuidBehavior, null);
+        this(importTargetNode, session, uuidBehavior, null, null);
     }
 
     /**
@@ -92,18 +92,23 @@
      * @param importTargetNode the target node
      * @param session session
      * @param uuidBehavior the uuid behaviro
-     * @param protectedItemHandlers protected item handling
+     * @param pnImporter importer for protected nodes
+     * @param ppImporter importer for protected properties
      */
     public SessionImporter(NodeImpl importTargetNode, SessionImpl session,
                            int uuidBehavior,
-                           ProtectedItemHandlers protectedItemHandlers) {
+                           ProtectedNodeImporter pnImporter,
+                           ProtectedPropertyImporter ppImporter) {
         this.importTargetNode = importTargetNode;
         this.session = session;
         this.uuidBehavior = uuidBehavior;
 
-        this.protectedItemHandlers = protectedItemHandlers == null
-                ? new ProtectedItemHandlers()
-                : protectedItemHandlers;
+        this.ppImporter = ppImporter == null
+                ? new DefaultProtectedPropertyImporter(session, session, false)
+                : ppImporter;
+        this.pnImporter = pnImporter == null
+                ? new DefaultProtectedNodeImporter(session, session, false, uuidBehavior)
+                : pnImporter;
         refTracker = new ReferenceChangeTracker();
 
         parents = new Stack<NodeImpl>();
@@ -267,9 +272,7 @@
             // parent node was skipped, skip this child node too
             parents.push(null); // push null onto stack for skipped node
             // notify the p-i-importer
-            if (currentNodeImporter != null) {
-                currentNodeImporter.startChildInfo(nodeInfo, propInfos);
-            }
+            pnImporter.startChildInfo(nodeInfo, propInfos);
             return;
         }
 
@@ -281,10 +284,9 @@
             // Notify the ProtectedNodeImporter about the start of a item
             // tree that is protected by this parent. If it potentially is
             // able to deal with it, notify it about the child node.
-            currentNodeImporter = protectedItemHandlers.accept(parent);
-            if (currentNodeImporter != null) {
+            if (pnImporter.start(parent)) {
                 log.debug("Protected node -> delegated to ProtectedPropertyImporter");
-                currentNodeImporter.startChildInfo(nodeInfo, propInfos);
+                pnImporter.startChildInfo(nodeInfo, propInfos);
             } /* else: p-i-Importer isn't able to deal with the protected tree.
                  skip the tree below the protected parent */
             return;
@@ -373,7 +375,7 @@
                 log.debug("Skipping protected property " + pi.getName());
 
                 // notify the ProtectedPropertyImporter.
-                if (protectedItemHandlers.handlePropInfo(node, pi, def)) {
+                if (ppImporter.handlePropInfo(node, pi, def)) {
                     // TODO: deal with reference props within the imported tree?        
           
                     log.debug("Protected property -> delegated to ProtectedPropertyImporter");
                 } // else: p-i-Importer isn't able to deal with this property
@@ -393,14 +395,9 @@
     public void endNode(NodeInfo nodeInfo) throws RepositoryException {
         NodeImpl parent = parents.pop();
         if (parent == null) {
-            if (currentNodeImporter != null) {
-                currentNodeImporter.endChildInfo();
-            }
+            pnImporter.endChildInfo();
         } else if (parent.getDefinition().isProtected()) {
-            if (currentNodeImporter != null) {
-                currentNodeImporter.end(parent);
-                currentNodeImporter = null;
-            }
+            pnImporter.end(parent);
             // TODO: deal with reference props within the imported tree?
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/AccessControlImporterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/AccessControlImporterTest.java?rev=810471&r1=810470&r2=810471&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/AccessControlImporterTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/AccessControlImporterTest.java
Wed Sep  2 12:10:51 2009
@@ -87,6 +87,39 @@
                     "</sv:node>" +
                 "</sv:node>" +
             "</sv:node>";
+
+
+    private static final String XML_POLICY_TREE_3   = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+
+            "<sv:node sv:name=\"rep:policy\" " +
+                    "xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"
xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\"
xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\"
xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" +
+                "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" +
+                    "<sv:value>rep:ACL</sv:value>" +
+                "</sv:property>" +
+                "<sv:node sv:name=\"allow\">" +
+                    "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" +
+                        "<sv:value>rep:GrantACE</sv:value>" +
+                    "</sv:property>" +
+                    "<sv:property sv:name=\"rep:principalName\" sv:type=\"String\">"
+
+                        "<sv:value>everyone</sv:value>" +
+                    "</sv:property>" +
+                    "<sv:property sv:name=\"rep:privileges\" sv:type=\"Name\">" +
+                        "<sv:value>jcr:write</sv:value>" +
+                    "</sv:property>" +
+                "</sv:node>" +
+                "<sv:node sv:name=\"allow0\">" +
+                    "<sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\">" +
+                        "<sv:value>rep:GrantACE</sv:value>" +
+                    "</sv:property>" +
+                    "<sv:property sv:name=\"rep:principalName\" sv:type=\"String\">"
+
+                        "<sv:value>admin</sv:value>" +
+                    "</sv:property>" +
+                    "<sv:property sv:name=\"rep:privileges\" sv:type=\"Name\">" +
+                        "<sv:value>jcr:write</sv:value>" +
+                    "</sv:property>" +
+                "</sv:node>" +
+            "</sv:node>";
+
+
     private static final String XML_POLICY_TREE_2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sv:node
sv:name=\"rep:policy\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"
xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\"
xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\"
xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:ACL</sv:value></sv:property><sv:node
sv:name=\"allow\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:GrantACE</sv:value></sv:property><sv:property
sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>everyone</sv:value></sv:property><sv:property
sv:name=\"rep:privileges\" sv:type=\"Name\"><sv:value>jcr:write</sv:value></sv:property></sv:node></sv:node>";
 
     private static final String XML_AC_TREE       = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sv:node
sv:name=\"rep:security\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"
xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\"
xmlns:crx=\"http://www.day.com/crx/1.0\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\"
xmlns:repl=\"http://www.day.com/crx/replication/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\"><sv:property
sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AccessControl</sv:value></sv:property><sv:node
sv:name=\"rep:authorizables\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AccessControl</sv:value></sv:property><sv:node
sv:name=\"rep:groups\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AccessControl</sv:value></sv:property><sv:node
sv:
 name=\"administrators\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:PrincipalAccessControl</sv:value></sv:property><sv:node
sv:name=\"rep:policy\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:ACL</sv:value></sv:property><sv:node
sv:name=\"entry\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:GrantACE</sv:value></sv:property><sv:property
sv:name=\"rep:glob\" sv:type=\"String\"><sv:value>*</sv:value></sv:property><sv:property
sv:name=\"rep:nodePath\" sv:type=\"Path\"><sv:value>/</sv:value></sv:property><sv:property
sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>administrators</sv:value></sv:property><sv:property
sv:name=\"rep:privileges\" sv:type=\"Name\"><sv:value>jcr:all</sv:value></sv:property></sv:node></sv:node></sv:node></sv:node><sv:node
sv:name=\"rep:users\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AccessControl</sv:value></sv:property><sv:node
sv
 :name=\"admin\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AccessControl</sv:value></sv:property><sv:node
sv:name=\"t\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:PrincipalAccessControl</sv:value></sv:property></sv:node><sv:node
sv:name=\"a\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:PrincipalAccessControl</sv:value></sv:property></sv:node></sv:node><sv:node
sv:name=\"anonymous\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:PrincipalAccessControl</sv:value></sv:property></sv:node></sv:node></sv:node></sv:node>";
@@ -165,9 +198,8 @@
         try {
 
             InputStream in = new ByteArrayInputStream(XML_POLICY_TREE.getBytes("UTF-8"));
-            ProtectedItemHandlers pi = new ProtectedItemHandlers();
-            pi.register(piImporter);
-            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
pi);
+            SessionImporter importer = new SessionImporter(target, sImpl,
+                    ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, piImporter, null);
             ImportHandler ih = new ImportHandler(importer, sImpl);
             new ParsingContentHandler(ih).parse(in);
 
@@ -198,6 +230,52 @@
     }
 
     /**
+     * Imports a resource-based ACL containing a single entry.
+     *
+     * @throws Exception
+     */
+    public void testImportACLOnly() throws Exception {
+        try {
+            NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
+            target.addMixin("rep:AccessControllable");
+
+            InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_3.getBytes("UTF-8"));
+            SessionImporter importer = new SessionImporter(target, sImpl,
+                    ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, piImporter, null);
+            ImportHandler ih = new ImportHandler(importer, sImpl);
+            new ParsingContentHandler(ih).parse(in);
+
+            String path = target.getPath();
+
+            AccessControlManager acMgr = sImpl.getAccessControlManager();
+            AccessControlPolicy[] policies = acMgr.getPolicies(path);
+
+            assertEquals(1, policies.length);
+            assertTrue(policies[0] instanceof JackrabbitAccessControlList);
+
+            AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
+            assertEquals(2, entries.length);
+
+            AccessControlEntry entry = entries[0];
+            assertEquals("everyone", entry.getPrincipal().getName());
+            assertEquals(1, entry.getPrivileges().length);
+            assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
+
+            entry = entries[1];
+            assertEquals("admin", entry.getPrincipal().getName());
+            assertEquals(1, entry.getPrivileges().length);
+            assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
+
+            if(entry instanceof JackrabbitAccessControlEntry) {
+                assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
+            }
+
+        } finally {
+            superuser.refresh(false);
+        }
+    }
+
+    /**
      * Imports a resource-based ACL containing a single entry for a policy that
      * already exists.
      *
@@ -219,9 +297,7 @@
         try {
 
             InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_2.getBytes("UTF-8"));
-            ProtectedItemHandlers pi = new ProtectedItemHandlers();
-            pi.register(piImporter);
-            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
pi);
+            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
piImporter, null);
             ImportHandler ih = new ImportHandler(importer, sImpl);
             new ParsingContentHandler(ih).parse(in);
 
@@ -271,9 +347,7 @@
 
             InputStream in = new ByteArrayInputStream(XML_POLICY_ONLY.getBytes("UTF-8"));
 
-            ProtectedItemHandlers pi = new ProtectedItemHandlers();
-            pi.register(piImporter);
-            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
pi);
+            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
piImporter, null);
             ImportHandler ih = new ImportHandler(importer, sImpl);
             new ParsingContentHandler(ih).parse(in);
 
@@ -311,9 +385,7 @@
 
             InputStream in = new ByteArrayInputStream(XML_AC_TREE.getBytes("UTF-8"));
 
-            ProtectedItemHandlers pi = new ProtectedItemHandlers();
-            pi.register(piImporter);
-            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
pi);
+            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
piImporter, null);
             ImportHandler ih = new ImportHandler(importer, sImpl);
             new ParsingContentHandler(ih).parse(in);
 
@@ -342,7 +414,7 @@
 
             InputStream in = new ByteArrayInputStream(XML_POLICY_TREE.getBytes("UTF-8"));
 
-            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
null);
+            SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
null, null);
             ImportHandler ih = new ImportHandler(importer, sImpl);
             new ParsingContentHandler(ih).parse(in);
 



Mime
View raw message