jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r651184 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
Date Thu, 24 Apr 2008 08:04:09 GMT
Author: angela
Date: Thu Apr 24 01:04:05 2008
New Revision: 651184

URL: http://svn.apache.org/viewvc?rev=651184&view=rev
Log:
replace deprecated AccessManager.isGranted(ItemId, int) by  AccessManager.canRead(Path)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java?rev=651184&r1=651183&r2=651184&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
Thu Apr 24 01:04:05 2008
@@ -18,8 +18,10 @@
 
 import org.apache.jackrabbit.core.ItemId;
 import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.security.AccessManager;
 import org.apache.jackrabbit.core.state.ItemState;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,6 +52,8 @@
      */
     private static final Logger log = LoggerFactory.getLogger(EventConsumer.class);
 
+    private final PathFactory pathFactory = PathFactoryImpl.getInstance();
+
     /**
      * The <code>Session</code> associated with this <code>EventConsumer</code>.
      */
@@ -150,7 +154,7 @@
                 ItemId targetId = state.getTargetId();
                 boolean granted = false;
                 try {
-                    granted = canRead(targetId);
+                    granted = canRead(state);
                 } catch (RepositoryException e) {
                     log.warn("Unable to check access rights for item: " + targetId);
                 }
@@ -176,20 +180,28 @@
      */
     void prepareDeleted(EventStateCollection events, Iterator deletedItems) {
         Set denied = null;
+        Set deletedIds = new HashSet();
         while (deletedItems.hasNext()) {
-            ItemState item = (ItemState) deletedItems.next();
-            // check read permission
-            boolean granted = false;
-            try {
-                granted = canRead(item.getId());
-            } catch (RepositoryException e) {
-                log.warn("Unable to check access rights for item: " + item.getId());
-            }
-            if (!granted) {
-                if (denied == null) {
-                    denied = new HashSet();
+            deletedIds.add(((ItemState) deletedItems.next()).getId());
+        }
+
+        for (Iterator it = events.iterator(); it.hasNext();) {
+            EventState evState = (EventState) it.next();
+            ItemId targetId = evState.getTargetId();
+            if (deletedIds.contains(targetId)) {
+                // check read permission
+                boolean granted = false;
+                try {
+                    granted = canRead(evState);
+                } catch (RepositoryException e) {
+                    log.warn("Unable to check access rights for item: " + targetId);
+                }
+                if (!granted) {
+                    if (denied == null) {
+                        denied = new HashSet();
+                    }
+                    denied.add(targetId);
                 }
-                denied.add(item.getId());
             }
         }
         if (denied != null) {
@@ -213,7 +225,7 @@
                     || state.getType() == Event.PROPERTY_ADDED
                     || state.getType() == Event.PROPERTY_CHANGED) {
                 ItemId targetId = state.getTargetId();
-                if (!canRead(targetId)) {
+                if (!canRead(state)) {
                     if (denied == null) {
                         denied = new HashSet();
                     }
@@ -271,7 +283,16 @@
         return hashCode;
     }
 
-    private boolean canRead(ItemId itemId) throws RepositoryException {
-        return session.getAccessManager().isGranted(itemId, AccessManager.READ);
+    /**
+     * Returns <code>true</code> if the item corresponding to the specified
+     * <code>eventState</code> can be read the the current session.
+     *
+     * @param eventState
+     * @return
+     * @throws RepositoryException
+     */
+    private boolean canRead(EventState eventState) throws RepositoryException {
+        Path targetPath = pathFactory.create(eventState.getParentPath(), eventState.getChildRelPath().getName(),
eventState.getChildRelPath().getNormalizedIndex(), true);
+        return session.getAccessManager().canRead(targetPath);
     }
 }



Mime
View raw message