You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2006/09/25 15:05:33 UTC

svn commit: r449676 - in /jackrabbit/trunk/contrib/spi: jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/

Author: angela
Date: Mon Sep 25 06:05:32 2006
New Revision: 449676

URL: http://svn.apache.org/viewvc?view=rev&rev=449676
Log:
work in progress

- avoid usage of JCR event types for SPI events (and vice versa)
- fix checkPermission

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?view=diff&rev=449676&r1=449675&r2=449676
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java Mon Sep 25 06:05:32 2006
@@ -375,33 +375,36 @@
         String[] actionsArr = actions.split(",");
 
         Path targetPath = getQPath(absPath);
+
         boolean isGranted;
+        // The given abs-path may point to a non-existing item
         if (itemExists(absPath)) {
             ItemState itemState = getHierarchyManager().getItemState(targetPath);
             isGranted = getAccessManager().isGranted(itemState, actionsArr);
         } else {
-            // The given abs-path may point to a non-existing item
-            Path parentPath = targetPath;
             NodeState parentState = null;
+            Path parentPath = targetPath;
             while (parentState == null) {
                 parentPath = parentPath.getAncestor(1);
                 if (itemManager.itemExists(parentPath)) {
                     ItemState itemState = getHierarchyManager().getItemState(parentPath);
                     if (itemState.isNode()) {
-                        parentState = itemState.getParent();
+                        parentState = (NodeState) itemState;
                     }
                 }
             }
+            // parentState is the nearest existing nodeState or the root state.
             try {
                 Path relPath = parentPath.computeRelativePath(targetPath);
                 isGranted = getAccessManager().isGranted(parentState, relPath, actionsArr);
-                if (!isGranted) {
-                    throw new AccessControlException(actions);
-                }
             } catch (MalformedPathException e) {
                 // should not occurs
                 throw new RepositoryException(e);
             }
+        }
+
+        if (!isGranted) {
+            throw new AccessControlException("Access control violation: path = " + absPath + ", actions = " + actions);
         }
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?view=diff&rev=449676&r1=449675&r2=449676
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java Mon Sep 25 06:05:32 2006
@@ -59,6 +59,7 @@
 import org.apache.jackrabbit.util.IteratorHelper;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.NodeId;
@@ -275,10 +276,10 @@
                 }
             };
             int allTypes = Event.NODE_ADDED | Event.NODE_REMOVED |
-                    Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
+                Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
             // register for all events
             service.addEventListener(sessionInfo, service.getRootId(sessionInfo),
-                    l, allTypes, true, null, null);
+                l, allTypes, true, null, null);
         }
         return l;
     }
@@ -370,35 +371,75 @@
         }
     }
     //------------------------------------------------------< AccessManager >---
-
     /**
      * @see AccessManager#isGranted(NodeState, Path, String[])
      */
     public boolean isGranted(NodeState parentState, Path relPath, String[] actions) throws ItemNotFoundException, RepositoryException {
-        // TODO: 'createNodeId' is basically wrong since isGranted is unspecific for any item.
-        ItemId id = getIdFactory().createNodeId(parentState.getNodeId(), relPath);
-        return service.isGranted(sessionInfo, id, actions);
+        // TODO: TOBEFIXED. 
+        ItemState wspState = parentState.getOverlayedState();
+        if (wspState == null) {
+            Path.PathBuilder pb = new Path.PathBuilder();
+            pb.addAll(relPath.getElements());
+            while (wspState == null) {
+                pb.addFirst(parentState.getName());
+
+                parentState = parentState.getParent();
+                wspState = parentState.getOverlayedState();
+            }
+            try {
+                relPath = pb.getPath();
+            } catch (MalformedPathException e) {
+                throw new RepositoryException(e);
+            }
+        }
+
+
+        if (wspState == null) {
+            // internal error. should never occur
+            throw new RepositoryException("Internal error: Unable to retrieve overlayed state in hierarchy.");
+        } else {
+            NodeId parentId = ((NodeState)parentState).getNodeId();
+            // TODO: 'createNodeId' is basically wrong since isGranted is unspecific for any item.
+            ItemId id = getIdFactory().createNodeId(parentId, relPath);
+            return service.isGranted(sessionInfo, id, actions);
+        }
     }
 
     /**
      * @see AccessManager#isGranted(ItemState, String[])
      */
     public boolean isGranted(ItemState itemState, String[] actions) throws ItemNotFoundException, RepositoryException {
-        return service.isGranted(sessionInfo, itemState.getId(), actions);
+        ItemState wspState = itemState.getOverlayedState();
+        // a 'new' state can always be read, written and removed
+        // TODO: correct?
+        if (wspState == null) {
+            return true;
+        }
+        return service.isGranted(sessionInfo, wspState.getId(), actions);
     }
 
     /**
      * @see AccessManager#canRead(ItemState)
      */
     public boolean canRead(ItemState itemState) throws ItemNotFoundException, RepositoryException {
-        return service.isGranted(sessionInfo, itemState.getId(), AccessManager.READ);
+        ItemState wspState = itemState.getOverlayedState();
+        // a 'new' state can always be read
+        if (wspState == null) {
+            return true;
+        }
+        return service.isGranted(sessionInfo, wspState.getId(), AccessManager.READ);
     }
 
     /**
      * @see AccessManager#canRemove(ItemState)
      */
     public boolean canRemove(ItemState itemState) throws ItemNotFoundException, RepositoryException {
-        return service.isGranted(sessionInfo, itemState.getId(), AccessManager.REMOVE);
+        ItemState wspState = itemState.getOverlayedState();
+        // a 'new' state can always be removed again
+        if (wspState == null) {
+            return true;
+        }
+        return service.isGranted(sessionInfo, wspState.getId(), AccessManager.REMOVE);
     }
 
     /**
@@ -416,7 +457,6 @@
 
     //---------------------------------------------------------< XML import >---
     public void importXml(NodeState parentState, InputStream xmlStream, int uuidBehaviour) throws RepositoryException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, ItemExistsException, VersionException {
-        // TODO check retrieval of nodeId
         NodeId parentId = parentState.getNodeId();
         service.importXml(sessionInfo, parentId, xmlStream, uuidBehaviour);
     }

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?view=diff&rev=449676&r1=449675&r2=449676
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java Mon Sep 25 06:05:32 2006
@@ -80,11 +80,11 @@
 import org.apache.jackrabbit.webdav.xml.Namespace;
 import org.apache.jackrabbit.webdav.header.CodedUrlHeader;
 import org.apache.jackrabbit.webdav.header.IfHeader;
-import org.apache.jackrabbit.webdav.header.DepthHeader;
 import org.apache.jackrabbit.webdav.search.SearchConstants;
 import org.apache.jackrabbit.webdav.jcr.version.report.RepositoryDescriptorsReport;
 import org.apache.jackrabbit.webdav.jcr.version.report.RegisteredNamespacesReport;
 import org.apache.jackrabbit.webdav.jcr.version.report.NodeTypesReport;
+import org.apache.jackrabbit.webdav.jcr.version.report.JcrPrivilegeReport;
 import org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeConstants;
 import org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeProperty;
 import org.apache.jackrabbit.webdav.jcr.property.ValuesProperty;
@@ -315,6 +315,14 @@
         return parentId;
     }
 
+    //--------------------------------------------------------------------------
+
+    private EventIterator retrieveEvents() {
+        // todo
+        return null;
+    }
+
+
     //--------------------------------------------------< RepositoryService >---
     /**
      * @see RepositoryService#getIdFactory()
@@ -441,13 +449,13 @@
      * @see RepositoryService#isGranted(SessionInfo, ItemId, String[] actions)
      */
     public boolean isGranted(SessionInfo sessionInfo, ItemId itemId, String[] actions) throws RepositoryException {
-        PropFindMethod method = null;
+        ReportMethod method = null;
         try {
-            DavPropertyNameSet propNameSet = new DavPropertyNameSet();
-            propNameSet.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
-
             String uri = getItemUri(itemId, sessionInfo);
-            method = new PropFindMethod(uri, propNameSet, DepthHeader.DEPTH_0);
+            ReportInfo reportInfo = new ReportInfo(JcrPrivilegeReport.PRIVILEGES_REPORT);
+            reportInfo.setContentElement(DomUtil.hrefToXml(uri, domFactory));
+
+            method = new ReportMethod(getWorkspaceUri(sessionInfo.getWorkspaceName()), reportInfo);
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
@@ -461,7 +469,7 @@
             }
             // build set of privileges from given actions. NOTE: since the actions
             // have no qualifying namespace, the {@link ItemResourceConstants#NAMESPACE}
-            // is used. // TODO check if correct.
+            // is used.
             Set requiredPrivileges = new HashSet();
             for (int i = 0; i < actions.length; i++) {
                requiredPrivileges.add(Privilege.getPrivilege(actions[i], ItemResourceConstants.NAMESPACE));
@@ -754,8 +762,7 @@
                 // on the server.
                 batchImpl.end(client, success);
             }
-            // TODO retrieve events.
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -781,8 +788,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -808,8 +814,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -835,8 +840,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -924,8 +928,7 @@
             // TODO: ev. need to take care of 'timeout' ?
             // TODO: ev. evaluate lock response, if depth and type is according to request?
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -952,8 +955,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -988,8 +990,7 @@
 
             sessionInfo.removeLockToken(lockToken);
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1014,9 +1015,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // String vUri = method.getVersionUri();
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1041,8 +1040,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1095,8 +1093,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1124,8 +1121,7 @@
             method.checkSuccess();
 
             // TODO: need to evaluate response?
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1164,9 +1160,8 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: need to evaluate response?
-            // TODO: retrieve events
-            return null;
+            // TODO: ev. evaluate response
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1191,8 +1186,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1219,8 +1213,7 @@
             getClient(sessionInfo).executeMethod(method);
             method.checkSuccess();
 
-            // TODO: retrieve events
-            return null;
+            return retrieveEvents();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1277,22 +1270,21 @@
      */
     public void addEventListener(SessionInfo sessionInfo, NodeId nodeId, EventListener listener, int eventTypes, boolean isDeep, String[] uuids, QName[] nodeTypeIds) throws RepositoryException {
         // build event types
-        // TODO: server expected JCR-event types... currently spi types are used
         List eTypes = new ArrayList();
         if ((eventTypes & Event.NODE_ADDED) == Event.NODE_ADDED) {
-            eTypes.add(SubscriptionImpl.getEventType(Event.NODE_ADDED));
+            eTypes.add(SubscriptionImpl.getEventType(javax.jcr.observation.Event.NODE_ADDED));
         }
         if ((eventTypes & Event.NODE_REMOVED) == Event.NODE_REMOVED) {
-            eTypes.add(SubscriptionImpl.getEventType(Event.NODE_REMOVED));
+            eTypes.add(SubscriptionImpl.getEventType(javax.jcr.observation.Event.NODE_REMOVED));
         }
         if ((eventTypes & Event.PROPERTY_ADDED) == Event.PROPERTY_ADDED) {
-            eTypes.add(SubscriptionImpl.getEventType(Event.PROPERTY_ADDED));
+            eTypes.add(SubscriptionImpl.getEventType(javax.jcr.observation.Event.PROPERTY_ADDED));
         }
         if ((eventTypes & Event.PROPERTY_REMOVED) == Event.PROPERTY_REMOVED) {
-            eTypes.add(SubscriptionImpl.getEventType(Event.PROPERTY_REMOVED));
+            eTypes.add(SubscriptionImpl.getEventType(javax.jcr.observation.Event.PROPERTY_REMOVED));
         }
         if ((eventTypes & Event.PROPERTY_CHANGED) == Event.PROPERTY_CHANGED) {
-            eTypes.add(SubscriptionImpl.getEventType(Event.PROPERTY_CHANGED));
+            eTypes.add(SubscriptionImpl.getEventType(javax.jcr.observation.Event.PROPERTY_CHANGED));
         }
         EventType[] etArr = (EventType[]) eTypes.toArray(new EventType[eTypes.size()]);
 
@@ -1608,8 +1600,6 @@
                 }
 
                 methods.add(method);
-
-                // TODO: retrieve location header (in order to detect index) and update id-mapping
             } catch (IOException e) {
                 throw new RepositoryException(e);
             } catch (ParserConfigurationException e) {