jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r812570 [17/24] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/ jackrabbit-api/src/main/appended-resources/ jackrabbit-api/src/main/appended-resources/META-INF/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabb...
Date Tue, 08 Sep 2009 16:09:45 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java Tue Sep  8 16:09:28 2009
@@ -23,6 +23,9 @@
 
 import junit.framework.TestCase;
 
+/**
+ * Tests a file system implementation.
+ */
 public abstract class AbstractFileSystemTest extends TestCase {
 
     private FileSystem fs;
@@ -69,70 +72,9 @@
         assertEquals(3, fs.length("/folder/file"));
         verifyStreamInput(fs.getInputStream("/folder/file"), sampleBytes);
 
-        // Copy the file
-        fs.copy("/folder/file", "/folder/file2");
-        assertTrue(fs.exists("/folder/file"));
-        assertFalse(fs.isFolder("/folder/file"));
-        assertTrue(fs.isFile("/folder/file"));
-        assertTrue(fs.exists("/folder/file2"));
-        assertFalse(fs.isFolder("/folder/file2"));
-        assertTrue(fs.isFile("/folder/file2"));
-        list = fs.list("/folder");
-        Arrays.sort(list);
-        assertEquals(2, list.length);
-        assertEquals("file", list[0]);
-        assertEquals("file2", list[1]);
-        assertEquals(3, fs.length("/folder/file2"));
-        verifyStreamInput(fs.getInputStream("/folder/file2"), sampleBytes);
-
-        // Delete the copy
-        fs.deleteFile("/folder/file2");
-        assertFalse(fs.exists("/folder/file2"));
-        assertFalse(fs.isFolder("/folder/file2"));
-        assertFalse(fs.isFile("/folder/file2"));
-        list = fs.list("/folder");
-        assertEquals(1, list.length);
-        assertEquals("file", list[0]);
-
-        // Move the file
-        fs.move("/folder/file", "/folder/file2");
-        assertFalse(fs.exists("/folder/file"));
-        assertFalse(fs.isFolder("/folder/file"));
-        assertFalse(fs.isFile("/folder/file"));
-        assertTrue(fs.exists("/folder/file2"));
-        assertFalse(fs.isFolder("/folder/file2"));
-        assertTrue(fs.isFile("/folder/file2"));
-        list = fs.list("/folder");
-        assertEquals(1, list.length);
-        assertEquals("file2", list[0]);
-        assertEquals(3, fs.length("/folder/file2"));
-        verifyStreamInput(fs.getInputStream("/folder/file2"), sampleBytes);
-
-        // Move the folder
-        fs.move("/folder", "/folder2");
-        assertFalse(fs.exists("/folder"));
-        assertFalse(fs.isFolder("/folder"));
-        assertFalse(fs.isFile("/folder"));
-        assertTrue(fs.exists("/folder2"));
-        assertTrue(fs.isFolder("/folder2"));
-        assertFalse(fs.isFile("/folder2"));
-        assertFalse(fs.exists("/folder/file2"));
-        assertFalse(fs.isFolder("/folder/file2"));
-        assertFalse(fs.isFile("/folder/file2"));
-        assertTrue(fs.exists("/folder2/file2"));
-        assertFalse(fs.isFolder("/folder2/file2"));
-        assertTrue(fs.isFile("/folder2/file2"));
-        list = fs.list("/");
-        assertEquals(1, list.length);
-        assertEquals("folder2", list[0]);
-        list = fs.list("/folder2");
-        assertEquals(1, list.length);
-        assertEquals("file2", list[0]);
-        assertEquals(3, fs.length("/folder2/file2"));
-        verifyStreamInput(fs.getInputStream("/folder2/file2"), sampleBytes);
-
         // Create a subfolder
         fs.createFolder("/folder2/subfolder");
+        createFile("/folder2/file2", sampleBytes);
         assertTrue(fs.exists("/folder2/subfolder"));
         assertTrue(fs.isFolder("/folder2/subfolder"));
         assertFalse(fs.isFile("/folder2/subfolder"));
@@ -149,7 +91,7 @@
         assertEquals(1, list.length);
         assertEquals("subfolder", list[0]);
 
-        // Try to create a file coliding with an exisiting folder
+        // Try to create a file colliding with an existing folder
         try {
             createFile("/folder2/subfolder", sampleBytes);
             fail("FileSystemException expected");
@@ -171,6 +113,7 @@
         assertEquals(0, fs.listFolders("/folder2").length);
 
         // Delete the folder
+        fs.deleteFolder("/folder");
         fs.deleteFolder("/folder2");
         assertFalse(fs.exists("/folder2"));
         assertFalse(fs.isFolder("/folder2"));
@@ -185,9 +128,6 @@
         Thread.sleep(100);
         createFile("/file2", sampleBytes);
         assertTrue(fs.lastModified("/file1") <= fs.lastModified("/file2"));
-        Thread.sleep(100);
-        fs.touch("/file1");
-        assertTrue(fs.lastModified("/file1") >= fs.lastModified("/file2"));
 
         // Try to create a file inside a nonexistent folder
         try {
@@ -211,61 +151,6 @@
         assertEquals("subfolder", list[0]);
     }
 
-    public void testMoveFile_destFolderDoesNotExist() throws Exception {
-        // Create a folder with a file
-        fs.createFolder("/folder");
-        createFile("/folder/file", sampleBytes);
-
-        // Check that the destination folder and file do not exist
-        assertFalse(fs.exists("/folder2"));
-        assertFalse(fs.exists("/folder2/file"));
-
-        // Move the file into a non-existent directory
-        fs.move("/folder/file", "/folder2/file");
-
-        // Check that the file has been moved
-        assertFalse(fs.exists("/folder/file"));
-        assertFalse(fs.isFolder("/folder/file"));
-        assertFalse(fs.isFile("/folder/file"));
-        assertTrue(fs.exists("/folder2/file"));
-        assertFalse(fs.isFolder("/folder2/file"));
-        assertTrue(fs.isFile("/folder2/file"));
-
-        // Check that folder2 has been silently created
-        assertTrue(fs.exists("/folder2"));
-        assertTrue(fs.isFolder("/folder2"));
-        assertFalse(fs.isFile("/folder2"));
-    }
-    
-    public void testMoveFolder_destFolderDoesNotExist() throws Exception {
-        // Create a folder with a file
-        fs.createFolder("/folder");
-        createFile("/folder/file", sampleBytes);
-        // Check that the destination folder and file do not exist
-        assertFalse(fs.exists("/folder2"));
-        assertFalse(fs.exists("/folder2/folder3"));
-        assertFalse(fs.exists("/folder2/folder3/file"));
-
-        // Move the folder into a non-existent directory
-        fs.move("/folder", "/folder2/folder3");
-
-        // Assert
-        assertFalse(fs.exists("/folder"));
-        assertFalse(fs.exists("/folder/file"));
-        
-        assertTrue(fs.exists("/folder2"));
-        assertTrue(fs.isFolder("/folder2"));
-        assertFalse(fs.isFile("/folder2"));
-
-        assertTrue(fs.exists("/folder2/folder3"));
-        assertTrue(fs.isFolder("/folder2/folder3"));
-        assertFalse(fs.isFile("/folder2/folder3"));
-
-        assertTrue(fs.exists("/folder2/folder3/file"));
-        assertFalse(fs.isFolder("/folder2/folder3/file"));
-        assertTrue(fs.isFile("/folder2/folder3/file"));
-    }
-
     private void verifyStreamInput(
             InputStream inputStream, byte[] expectedBytes) throws IOException {
         byte[] resultBytes = new byte[3];

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystemTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystemTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystemTest.java Tue Sep  8 16:09:28 2009
@@ -22,6 +22,9 @@
 import org.apache.jackrabbit.core.fs.AbstractFileSystemTest;
 import org.apache.jackrabbit.core.fs.FileSystem;
 
+/**
+ * Tests the Apache Derby file system.
+ */
 public class DerbyFileSystemTest extends AbstractFileSystemTest {
 
     private File file;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/local/LocalFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/local/LocalFileSystemTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/local/LocalFileSystemTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/local/LocalFileSystemTest.java Tue Sep  8 16:09:28 2009
@@ -22,25 +22,29 @@
 import org.apache.jackrabbit.core.fs.AbstractFileSystemTest;
 import org.apache.jackrabbit.core.fs.FileSystem;
 
+/**
+ * Tests the local file system.
+ */
 public class LocalFileSystemTest extends AbstractFileSystemTest {
 
-    private File file;
+    private String tempDirectory;
 
     protected FileSystem getFileSystem() {
         LocalFileSystem filesystem = new LocalFileSystem();
-        filesystem.setPath(file.getPath());
+        filesystem.setPath(tempDirectory);
         return filesystem;
     }
 
     protected void setUp() throws Exception {
-        file = File.createTempFile("jackrabbit", "localfs");
+        File file = File.createTempFile("jackrabbit", "localfs");
+        tempDirectory = file.getPath();
         file.delete();
         super.setUp();
     }
 
     protected void tearDown() throws Exception {
         super.tearDown();
-        delete(file);
+        delete(new File(tempDirectory));
     }
 
     private void delete(File file) throws IOException {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystemTest.java Tue Sep  8 16:09:28 2009
@@ -19,6 +19,9 @@
 import org.apache.jackrabbit.core.fs.AbstractFileSystemTest;
 import org.apache.jackrabbit.core.fs.FileSystem;
 
+/**
+ * Tests the in-memory file system.
+ */
 public class MemoryFileSystemTest extends AbstractFileSystemTest {
 
     protected FileSystem getFileSystem() {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/id/NodeIdTest.java Tue Sep  8 16:09:28 2009
@@ -78,4 +78,29 @@
         }
     }
 
+    public void testUuidFormat() {
+        long maxHigh = 0, maxLow = 0, minHigh = -1L, minLow = -1L;
+        for (int i = 0; i < 100; i++) {
+            NodeId id = new NodeId();
+            assertUuidFormat(id);
+            maxHigh |= id.getMostSignificantBits();
+            maxLow |= id.getLeastSignificantBits();
+            minHigh &= id.getMostSignificantBits();
+            minLow &= id.getLeastSignificantBits();
+        }
+        NodeId max = new NodeId(maxHigh, maxLow);
+        assertEquals("ffffffff-ffff-4fff-bfff-ffffffffffff", max.toString());
+        NodeId min = new NodeId(minHigh, minLow);
+        assertEquals("00000000-0000-4000-8000-000000000000", min.toString());
+    }
+
+    private void assertUuidFormat(NodeId id) {
+        long high = id.getMostSignificantBits();
+        long low = id.getLeastSignificantBits();
+        long high2 = (high & (~0xf000L)) | 0x4000L; // version 4 (random)
+        assertEquals(high, high2);
+        long low2 = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; // variant (Leach-Salz)
+        assertEquals(low, low2);
+    }
+
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java Tue Sep  8 16:09:28 2009
@@ -65,6 +65,14 @@
     private static final String TEST_NS_CND_NODETYPES =
         "test_ns_cnd_nodetypes.cnd";
 
+    /** Name of the xml nodetype file with same node type name definitions. */
+    private static final String TEST_SAME_NT_NAME_XML_NODETYPES =
+        "test_same_nt_name_xml_nodetypes.xml";
+
+    /** Name of the cnd nodetype file with same node type name definitions. */
+    private static final String TEST_SAME_NT_NAME_CND_NODETYPES =
+        "test_same_nt_name_cnd_nodetypes.cnd";
+
     private static final NameFactory FACTORY = NameFactoryImpl.getInstance();
 
     /** Test node types definitions. */
@@ -252,6 +260,24 @@
         }
     }
 
+    /** Test for same node type name on node type import. */
+    public void testInvalidXMLNodeTypes() throws Exception {
+        JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager)
+            superuser.getWorkspace().getNodeTypeManager();
+        try {
+            ntm.registerNodeTypes(
+                TestAll.class.getResourceAsStream(TEST_SAME_NT_NAME_XML_NODETYPES),
+                JackrabbitNodeTypeManager.TEXT_XML);
+            fail("Importing multiple node types with the same name must fail");
+        } catch (RepositoryException e) {
+            if (e.getCause() instanceof InvalidNodeTypeDefException) {
+               // Expected
+            } else {
+               throw e;
+            }
+        }
+    }
+
     /** Test for namespace registration on node type import. */
     public void testImportCNDNodeTypes() throws Exception {
         try {
@@ -271,6 +297,24 @@
         }
     }
 
+    /** Test for same node type name on node type import. */
+    public void testInvalidCNDNodeTypes() throws Exception {
+        JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager)
+            superuser.getWorkspace().getNodeTypeManager();
+        try {
+            ntm.registerNodeTypes(
+                TestAll.class.getResourceAsStream(TEST_SAME_NT_NAME_CND_NODETYPES),
+                JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+            fail("Importing multiple node types with the same name must fail");
+        } catch (RepositoryException e) {
+            if (e.getCause() instanceof InvalidNodeTypeDefException) {
+               // Expected
+            } else {
+               throw e;
+            }
+        }
+    }
+
     /** Test for the empty item definition. */
     public void testEmptyItem() {
         PropDef def = getPropDef("itemNodeType", "emptyItem");

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java Tue Sep  8 16:09:28 2009
@@ -35,6 +35,7 @@
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
+import org.apache.jackrabbit.core.query.lucene.SearchIndex;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
 /**
@@ -139,6 +140,7 @@
      */
     protected void executeXPathQuery(String xpath, Node[] nodes)
             throws RepositoryException {
+        getSearchIndex().flush();
         QueryResult res = qm.createQuery(xpath, Query.XPATH).execute();
         checkResult(res, nodes);
     }
@@ -153,6 +155,7 @@
      */
     protected void executeSQLQuery(String sql, Node[] nodes)
             throws RepositoryException {
+        getSearchIndex().flush();
         QueryResult res = qm.createQuery(sql, Query.SQL).execute();
         checkResult(res, nodes);
     }
@@ -253,9 +256,11 @@
     }
 
     /**
+     * Returns a reference to the underlying search index.
+     *
      * @return the query handler inside the {@link #qm query manager}.
      */
-    protected QueryHandler getQueryHandler() {
-        return ((QueryManagerImpl) qm).getQueryHandler();
+    protected SearchIndex getSearchIndex() {
+        return (SearchIndex) ((QueryManagerImpl) qm).getQueryHandler();
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java Tue Sep  8 16:09:28 2009
@@ -104,6 +104,21 @@
                 "apache jackrabbit");
     }
 
+    public void testEncodeIllegalCharsNoHighlights() throws RepositoryException {
+        String text = "bla <strong>bla</strong> bla";
+        String excerpt = createExcerpt("bla &lt;strong&gt;bla&lt;/strong&gt; bla");
+        Node n = testRootNode.addNode(nodeName1);
+        n.setProperty("text", text);
+        n.setProperty("other", "foo");
+        superuser.save();
+
+        String stmt = getStatement("foo");
+        QueryResult result = executeQuery(stmt);
+        RowIterator rows = result.getRows();
+        assertEquals(1, rows.getSize());
+        assertEquals(excerpt, rows.nextRow().getValue("rep:excerpt(text)").getString());
+    }
+
     private void checkExcerpt(String text, String fragmentText, String terms)
             throws RepositoryException {
         String excerpt = createExcerpt(fragmentText);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LargeResultSetTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LargeResultSetTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LargeResultSetTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/LargeResultSetTest.java Tue Sep  8 16:09:28 2009
@@ -34,7 +34,7 @@
         createNodes(testRootNode, 10, 5, 0);
         superuser.save();
 
-        SearchIndex index = (SearchIndex) getQueryHandler();
+        SearchIndex index = getSearchIndex();
         int resultFetchSize = index.getResultFetchSize();
         try {
             String stmt = testPath + "//*[@" + jcrPrimaryType + "] order by @jcr:score descending";

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/OrderByTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/OrderByTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/OrderByTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/OrderByTest.java Tue Sep  8 16:09:28 2009
@@ -33,7 +33,7 @@
 /**
  * Tests queries with order by.
  */
-public class OrderByTest extends AbstractQueryTest {
+public class OrderByTest extends AbstractIndexingTest {
 
     public void testOrderByScore() throws RepositoryException {
         Node n1 = testRootNode.addNode("node1");
@@ -51,12 +51,12 @@
 
         String sql = "SELECT value FROM nt:unstructured WHERE " +
                 "jcr:path LIKE '" + testRoot + "/%' ORDER BY jcr:score, value";
-        Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+        Query q = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
         QueryResult result = q.execute();
         checkResult(result, 3);
 
         String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by jcr:score(), @value";
-        q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+        q = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
         result = q.execute();
         checkResult(result, 3);
     }
@@ -148,31 +148,31 @@
     //------------------------------< helper >----------------------------------
 
     private Value getValue(String value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value);
+        return session.getValueFactory().createValue(value);
     }
 
     private Value getValue(long value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value);
+        return session.getValueFactory().createValue(value);
     }
 
     private Value getValue(double value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value);
+        return session.getValueFactory().createValue(value);
     }
 
     private Value getValue(boolean value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value);
+        return session.getValueFactory().createValue(value);
     }
 
     private Value getValue(Calendar value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value);
+        return session.getValueFactory().createValue(value);
     }
 
     private Value getNameValue(String value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value, PropertyType.NAME);
+        return session.getValueFactory().createValue(value, PropertyType.NAME);
     }
 
     private Value getPathValue(String value) throws RepositoryException {
-        return superuser.getValueFactory().createValue(value, PropertyType.PATH);
+        return session.getValueFactory().createValue(value, PropertyType.PATH);
     }
 
     /**
@@ -185,8 +185,8 @@
     private void checkChildAxis(Value[] values) throws RepositoryException {
         // child/prop is part of the test indexing configuration,
         // this will use SimpleScoreDocComparator internally
-        checkChildAxis(values, "child", "prop");
-        cleanUpTestRoot(superuser);
+        checkChildAxis(values, "child", "property");
+        cleanUpTestRoot(session);
         // c/p is not in the indexing configuration,
         // this will use RelPathScoreDocComparator internally
         checkChildAxis(values, "c", "p");

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingAggregateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingAggregateTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingAggregateTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingAggregateTest.java Tue Sep  8 16:09:28 2009
@@ -58,7 +58,6 @@
         resource.setProperty("jcr:data", new ByteArrayInputStream(out.toByteArray()));
 
         testRootNode.save();
-        waitUntilQueueEmpty();
 
         executeSQLQuery(sqlDog, new Node[]{file});
 
@@ -68,7 +67,6 @@
         writer.flush();
         resource.setProperty("jcr:data", new ByteArrayInputStream(out.toByteArray()));
         testRootNode.save();
-        waitUntilQueueEmpty();
 
         executeSQLQuery(sqlCat, new Node[]{file});
 
@@ -95,22 +93,10 @@
         resource.setProperty("jcr:mimeType", "text/plain");
         resource.setProperty("jcr:data", new ByteArrayInputStream(out.toByteArray()));
         testRootNode.save();
-        waitUntilQueueEmpty();
 
         executeSQLQuery(sqlCat, new Node[]{file});
     }
 
-    protected void waitUntilQueueEmpty() throws Exception {
-        SearchIndex index = (SearchIndex) getQueryHandler();
-        IndexingQueue queue = index.getIndex().getIndexingQueue();
-        index.getIndex().flush();
-        synchronized (index.getIndex()) {
-            while (queue.getNumPendingDocuments() > 0) {
-                index.getIndex().wait(50);
-            }
-        }
-    }
-
     public void testContentLastModified() throws RepositoryException {
         List expected = new ArrayList();
         long time = System.currentTimeMillis();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java Tue Sep  8 16:09:28 2009
@@ -50,7 +50,7 @@
 
     public void testQueue() throws Exception {
         Extractor.sleepTime = 200;
-        SearchIndex index = (SearchIndex) getQueryHandler();
+        SearchIndex index = getSearchIndex();
         IndexingQueue queue = index.getIndex().getIndexingQueue();
 
         assertEquals(0, queue.getNumPendingDocuments());
@@ -70,11 +70,8 @@
         NodeIterator nodes = q.execute().getNodes();
         assertFalse(nodes.hasNext());
 
-        synchronized (index.getIndex()) {
-            while (queue.getNumPendingDocuments() > 0) {
-                index.getIndex().wait(50);
-            }
-        }
+        index.flush();
+        assertEquals(0, queue.getNumPendingDocuments());
 
         q = qm.createQuery(testPath + "/*[jcr:contains(., 'fox')]", Query.XPATH);
         nodes = q.execute().getNodes();
@@ -83,8 +80,7 @@
 
     public void testInitialIndex() throws Exception {
         Extractor.sleepTime = 200;
-        SearchIndex index = (SearchIndex) getQueryHandler();
-        File indexDir = new File(index.getPath());
+        File indexDir = new File(getSearchIndex().getPath());
 
         // fill workspace
         Node testFolder = testRootNode.addNode("folder", "nt:folder");
@@ -133,25 +129,45 @@
         }
 
         qm = session.getWorkspace().getQueryManager();
-        index = (SearchIndex) getQueryHandler();
-        IndexingQueue queue = index.getIndex().getIndexingQueue();
-
-        // flush index to make sure any documents in the buffer are written
-        // to the index. this is to make sure all nodes are pushed either to
-        // the index or to the indexing queue
-        index.getIndex().flush();
-
-        synchronized (index.getIndex()) {
-            while (queue.getNumPendingDocuments() > 0) {
-                index.getIndex().wait(50);
-            }
-        }
+        getSearchIndex().flush();
 
         String stmt = testPath + "//element(*, nt:resource)[jcr:contains(., 'fox')] order by @jcr:score descending";
         Query q = qm.createQuery(stmt, Query.XPATH);
         assertEquals(num, q.execute().getNodes().getSize());
     }
 
+    /*
+     * Test case for JCR-2082
+     */
+    public void testReaderUpToDate() throws Exception {
+        Extractor.sleepTime = 10;
+        SearchIndex index = getSearchIndex();
+        File indexDir = new File(index.getPath());
+
+        // shutdown workspace
+        RepositoryImpl repo = (RepositoryImpl) session.getRepository();
+        session.logout();
+        session = null;
+        superuser.logout();
+        superuser = null;
+        TestHelper.shutdownWorkspace(WORKSPACE_NAME, repo);
+
+        // delete index
+        try {
+            FileUtil.delete(indexDir);
+        } catch (IOException e) {
+            fail("Unable to delete index directory");
+        }
+
+        // start workspace again by getting a session
+        session = getHelper().getSuperuserSession(WORKSPACE_NAME);
+
+        qm = session.getWorkspace().getQueryManager();
+
+        Query q = qm.createQuery(testPath, Query.XPATH);
+        assertEquals(1, getSize(q.execute().getNodes()));
+    }
+
     private int createFiles(Node folder, byte[] data,
                             int filesPerLevel, int levels, int count)
             throws RepositoryException {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java Tue Sep  8 16:09:28 2009
@@ -27,7 +27,6 @@
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
-import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -198,14 +197,14 @@
     public void testCanAccessDeniedWorkspace() throws RepositoryException, NotExecutableException {
         Session s = getHelper().getReadOnlySession();
         try {
-            Set allAccessibles = new HashSet(Arrays.asList(superuser.getWorkspace().getAccessibleWorkspaceNames()));
-            Set sWorkspaceNames = new HashSet(Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames()));
+            Set<String> allAccessibles = new HashSet<String>(Arrays.asList(superuser.getWorkspace().getAccessibleWorkspaceNames()));
+            Set<String> sWorkspaceNames = new HashSet<String>(Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames()));
 
             if (!allAccessibles.removeAll(sWorkspaceNames) || allAccessibles.isEmpty()) {
                 throw new NotExecutableException("No workspace name found that exists but is not accessible for ReadOnly session.");
             }
 
-            String notAccessibleName = allAccessibles.iterator().next().toString();
+            String notAccessibleName = allAccessibles.iterator().next();
             assertFalse(getAccessManager(s).canAccess(notAccessibleName));
         } finally {
             s.logout();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractACLTemplateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractACLTemplateTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractACLTemplateTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractACLTemplateTest.java Tue Sep  8 16:09:28 2009
@@ -16,6 +16,15 @@
  */
 package org.apache.jackrabbit.core.security.authorization;
 
+import java.security.Principal;
+import java.util.Collections;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.security.AccessControlEntry;
+import javax.jcr.security.AccessControlException;
+import javax.jcr.security.Privilege;
+
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
 import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
@@ -25,14 +34,6 @@
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.api.security.AbstractAccessControlTest;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.security.AccessControlEntry;
-import javax.jcr.security.AccessControlException;
-import javax.jcr.security.Privilege;
-import java.security.Principal;
-import java.util.Collections;
-
 /**
  * <code>AbstractACLTemplateTest</code>...
  */
@@ -171,15 +172,15 @@
     public void testAddEntry() throws RepositoryException, NotExecutableException {
         JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
         Privilege[] privs = privilegesFromName(Privilege.JCR_READ);
-        assertTrue(pt.addEntry(testPrincipal, privs, true, Collections.EMPTY_MAP));
+        assertTrue(pt.addEntry(testPrincipal, privs, true, Collections.<String, Value>emptyMap()));
     }
 
     public void testAddEntryTwice() throws RepositoryException, NotExecutableException {
         JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
         Privilege[] privs = privilegesFromName(Privilege.JCR_READ);
 
-        pt.addEntry(testPrincipal, privs, true, Collections.EMPTY_MAP);
-        assertFalse(pt.addEntry(testPrincipal, privs, true, Collections.EMPTY_MAP));
+        pt.addEntry(testPrincipal, privs, true, Collections.<String, Value>emptyMap());
+        assertFalse(pt.addEntry(testPrincipal, privs, true, Collections.<String, Value>emptyMap()));
     }
 
     public void testEffect() throws RepositoryException, NotExecutableException {
@@ -196,8 +197,7 @@
         int allows = PrivilegeRegistry.NO_PRIVILEGE;
         int denies = PrivilegeRegistry.NO_PRIVILEGE;
         AccessControlEntry[] entries = pt.getAccessControlEntries();
-        for (int i = 0; i < entries.length; i++) {
-            AccessControlEntry ace = entries[i];
+        for (AccessControlEntry ace : entries) {
             if (testPrincipal.equals(ace.getPrincipal()) && ace instanceof JackrabbitAccessControlEntry) {
                 int entryBits = PrivilegeRegistry.getBits(ace.getPrivileges());
                 if (((JackrabbitAccessControlEntry) ace).isAllow()) {
@@ -213,17 +213,16 @@
 
     public void testEffect2() throws RepositoryException, NotExecutableException {
         JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
-        pt.addEntry(testPrincipal, privilegesFromName(Privilege.JCR_READ), true, Collections.EMPTY_MAP);
+        pt.addEntry(testPrincipal, privilegesFromName(Privilege.JCR_READ), true, Collections.<String, Value>emptyMap());
 
         // same entry but with revers 'isAllow' flag
-        assertTrue(pt.addEntry(testPrincipal, privilegesFromName(Privilege.JCR_READ), false, Collections.EMPTY_MAP));
+        assertTrue(pt.addEntry(testPrincipal, privilegesFromName(Privilege.JCR_READ), false, Collections.<String, Value>emptyMap()));
 
         // test net-effect
         int allows = PrivilegeRegistry.NO_PRIVILEGE;
         int denies = PrivilegeRegistry.NO_PRIVILEGE;
         AccessControlEntry[] entries = pt.getAccessControlEntries();
-        for (int i = 0; i < entries.length; i++) {
-            AccessControlEntry ace = entries[i];
+        for (AccessControlEntry ace : entries) {
             if (testPrincipal.equals(ace.getPrincipal()) && ace instanceof JackrabbitAccessControlEntry) {
                 int entryBits = PrivilegeRegistry.getBits(ace.getPrivileges());
                 if (((JackrabbitAccessControlEntry) ace).isAllow()) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEntryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEntryTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEntryTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEntryTest.java Tue Sep  8 16:09:28 2009
@@ -19,7 +19,6 @@
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 
 import javax.jcr.RepositoryException;
@@ -117,7 +116,7 @@
     public void testEquals() throws RepositoryException, NotExecutableException  {
 
         JackrabbitAccessControlEntry ace = createEntry(new String[] {Privilege.JCR_ALL}, true);
-        List equalAces = new ArrayList();
+        List<JackrabbitAccessControlEntry> equalAces = new ArrayList<JackrabbitAccessControlEntry>();
         equalAces.add(createEntry(new String[] {Privilege.JCR_ALL}, true));
 
         Privilege[] privs = acMgr.privilegeFromName(Privilege.JCR_ALL).getDeclaredAggregatePrivileges();
@@ -126,14 +125,14 @@
         privs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
         equalAces.add(createEntry(testPrincipal, privs, true));
 
-        for (Iterator it = equalAces.iterator(); it.hasNext();) {
-            assertEquals(ace, it.next());
+        for (JackrabbitAccessControlEntry equalAce : equalAces) {
+            assertEquals(ace, equalAce);
         }
     }
 
     public void testNotEquals() throws RepositoryException, NotExecutableException  {
         JackrabbitAccessControlEntry ace = createEntry(new String[] {Privilege.JCR_ALL}, true);
-        List otherAces = new ArrayList();
+        List<JackrabbitAccessControlEntry> otherAces = new ArrayList<JackrabbitAccessControlEntry>();
 
         try {
             // ACE template with different principal
@@ -191,8 +190,8 @@
         };
         otherAces.add(pe);
 
-        for (Iterator it = otherAces.iterator(); it.hasNext();) {
-            assertFalse(ace.equals(it.next()));
+        for (JackrabbitAccessControlEntry otherAce : otherAces) {
+            assertFalse(ace.equals(otherAce));
         }
     }
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java Tue Sep  8 16:09:28 2009
@@ -22,7 +22,6 @@
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.api.security.AbstractAccessControlTest;
-import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,14 +30,15 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.Privilege;
 import java.security.Principal;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
 /** <code>AbstractEvaluationTest</code>... */
 public abstract class AbstractEvaluationTest extends AbstractAccessControlTest {
@@ -51,7 +51,7 @@
     private Session testSession;
     private AccessControlManager testAccessControlManager;
     private Node trn;
-    private Set toClear = new HashSet();
+    private Set<String> toClear = new HashSet<String>();
 
     protected void setUp() throws Exception {
         super.setUp();
@@ -74,14 +74,13 @@
     }
 
     protected void tearDown() throws Exception {
-        for (Iterator it = toClear.iterator(); it.hasNext();) {
-            String path = it.next().toString();
+        for (String path : toClear) {
             try {
                 AccessControlPolicy[] policies = acMgr.getPolicies(path);
-                for (int i = 0; i < policies.length; i++) {
-                    acMgr.removePolicy(path, policies[i]);
+                for (AccessControlPolicy policy : policies) {
+                    acMgr.removePolicy(path, policy);
                 }
-                superuser.save();                
+                superuser.save();
             } catch (RepositoryException e) {
                 // log error and ignore
                 log.debug(e.getMessage());
@@ -139,13 +138,13 @@
     }
 
     protected abstract JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path, Principal princ) throws RepositoryException, NotExecutableException;
-    protected abstract Map getRestrictions(Session session, String path) throws RepositoryException, NotExecutableException;
+    protected abstract Map<String, Value> getRestrictions(Session session, String path) throws RepositoryException, NotExecutableException;
 
     protected JackrabbitAccessControlList modifyPrivileges(String path, String privilege, boolean isAllow) throws NotExecutableException, RepositoryException {
         return modifyPrivileges(path, testUser.getPrincipal(), privilegesFromName(privilege), isAllow, getRestrictions(superuser, path));
     }
 
-    private JackrabbitAccessControlList modifyPrivileges(String path, Principal principal, Privilege[] privileges, boolean isAllow, Map restrictions) throws NotExecutableException, RepositoryException {
+    private JackrabbitAccessControlList modifyPrivileges(String path, Principal principal, Privilege[] privileges, boolean isAllow, Map<String, Value> restrictions) throws NotExecutableException, RepositoryException {
         JackrabbitAccessControlList tmpl = getPolicy(acMgr, path, principal);
         tmpl.addEntry(principal, privileges, isAllow, restrictions);
         
@@ -158,20 +157,24 @@
     }
 
     protected JackrabbitAccessControlList givePrivileges(String nPath, Privilege[] privileges,
-                                                         Map restrictions) throws NotExecutableException, RepositoryException {
+                                                         Map<String, Value> restrictions)
+            throws NotExecutableException, RepositoryException {
         return modifyPrivileges(nPath, testUser.getPrincipal(), privileges, true, restrictions);
     }
 
     protected JackrabbitAccessControlList givePrivileges(String nPath, Principal principal,
-                                                         Privilege[] privileges, Map restrictions) throws NotExecutableException, RepositoryException {
+                                                         Privilege[] privileges, Map<String, Value> restrictions)
+            throws NotExecutableException, RepositoryException {
         return modifyPrivileges(nPath, principal, privileges, true, restrictions);
     }
 
-    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Privilege[] privileges, Map restrictions) throws NotExecutableException, RepositoryException {
+    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Privilege[] privileges, Map<String, Value> restrictions)
+            throws NotExecutableException, RepositoryException {
         return modifyPrivileges(nPath, testUser.getPrincipal(), privileges, false, restrictions);
     }
 
-    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Principal principal, Privilege[] privileges, Map restrictions) throws NotExecutableException, RepositoryException {
+    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Principal principal, Privilege[] privileges, Map<String, Value> restrictions)
+            throws NotExecutableException, RepositoryException {
         return modifyPrivileges(nPath, principal, privileges, false, restrictions);
     }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractVersionManagementTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractVersionManagementTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractVersionManagementTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractVersionManagementTest.java Tue Sep  8 16:09:28 2009
@@ -169,9 +169,9 @@
         } finally {
             // revert privilege modification (manually remove the ACE added)
             AccessControlEntry[] entries = tmpl.getAccessControlEntries();
-            for (int i = 0; i < entries.length; i++) {
-                if (entries[i].getPrincipal().equals(testUser.getPrincipal())) {
-                    tmpl.removeAccessControlEntry(entries[i]);
+            for (AccessControlEntry entry1 : entries) {
+                if (entry1.getPrincipal().equals(testUser.getPrincipal())) {
+                    tmpl.removeAccessControlEntry(entry1);
                 }
             }
             acMgr.setPolicy(tmpl.getPath(), tmpl);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java Tue Sep  8 16:09:28 2009
@@ -24,7 +24,6 @@
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.api.observation.EventResult;
 import org.apache.jackrabbit.util.Text;
-import org.apache.jackrabbit.uuid.UUID;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Node;
@@ -43,6 +42,7 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.UUID;
 
 /**
  * <code>AbstractEvaluationTest</code>...
@@ -51,7 +51,7 @@
 
     protected static final long DEFAULT_WAIT_TIMEOUT = 5000;
 
-    private Group testGroup;
+    protected Group testGroup;
 
     protected String path;
     protected String childNPath;
@@ -62,7 +62,6 @@
 
     // TODO: test AC for moved node
     // TODO: test AC for moved AC-controlled node
-    // TODO: test if combination of group and user permissions are properly evaluated
 
     protected void setUp() throws Exception {
         super.setUp();
@@ -337,7 +336,7 @@
         Privilege[] dnPrivs = privilegesFromName(Privilege.JCR_READ);
         withdrawPrivileges(path, dnPrivs, getRestrictions(superuser, path));
 
-        // testUser registers a eventlistener for 'path
+        // testUser registers a event listener for 'path
         ObservationManager obsMgr = testSession.getWorkspace().getObservationManager();
         EventResult listener = new EventResult(((JUnitTest) this).log);
         try {
@@ -352,9 +351,9 @@
             // since the testUser does not have read-permission on the removed
             // node, no corresponding event must be generated.
             Event[] evts = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
-            for (int i = 0; i < evts.length; i++) {
-                if (evts[i].getType() == Event.NODE_REMOVED &&
-                        evts[i].getPath().equals(childNPath)) {
+            for (Event evt : evts) {
+                if (evt.getType() == Event.NODE_REMOVED &&
+                        evt.getPath().equals(childNPath)) {
                     fail("TestUser does not have READ permission below " + path + " -> events below must not show up.");
                 }
             }
@@ -446,7 +445,7 @@
 
         Privilege[] rmChildNodes = privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES);
 
-        // add 'remove_child_nodes' privilge at 'path'
+        // add 'remove_child_nodes' privilege at 'path'
         givePrivileges(path, rmChildNodes, getRestrictions(superuser, path));
         /*
          expected result:
@@ -492,7 +491,7 @@
         Privilege[] privs = privilegesFromNames(new String[] {
                 Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_REMOVE_NODE
         });
-        // add 'remove_node' and 'remove_child_nodes' privilge at 'path'
+        // add 'remove_node' and 'remove_child_nodes' privilege at 'path'
         givePrivileges(path, privs, getRestrictions(superuser, path));
         /*
          expected result:
@@ -523,9 +522,9 @@
         Privilege[] rmChildNodes = privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES);
         Privilege[] rmNode = privilegesFromName(Privilege.JCR_REMOVE_NODE);
 
-        // add 'remove_child_nodes' privilge at 'path'...
+        // add 'remove_child_nodes' privilege at 'path'...
         givePrivileges(path, rmChildNodes, getRestrictions(superuser, path));
-        // ... and add 'remove_node' privilge at 'childNPath'
+        // ... and add 'remove_node' privilege at 'childNPath'
         givePrivileges(childNPath, rmNode, getRestrictions(superuser, childNPath));
         /*
          expected result:
@@ -572,7 +571,7 @@
         });
         Privilege[] rmNode = privilegesFromName(Privilege.JCR_REMOVE_NODE);
 
-        // add 'remove_child_nodes' and 'remove_node' privilge at 'path'
+        // add 'remove_child_nodes' and 'remove_node' privilege at 'path'
         givePrivileges(path, privs, getRestrictions(superuser, path));
         // ... but deny 'remove_node' at childNPath
         withdrawPrivileges(childNPath, rmNode, getRestrictions(superuser, childNPath));
@@ -611,7 +610,7 @@
          */
         assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_REMOVE));
 
-        // additionally add remove_child_nodes priv at 'childNPath'
+        // additionally add remove_child_nodes privilege at 'childNPath'
         givePrivileges(childNPath, rmChildNodes, getRestrictions(superuser, childNPath));
         /*
          expected result:
@@ -782,7 +781,7 @@
         */
         checkReadOnly(path);
 
-        /* explicitely withdraw MODIFY_PROPERTIES for the user */
+        /* explicitly withdraw MODIFY_PROPERTIES for the user */
         Privilege[] privileges = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES);
         withdrawPrivileges(path, testUser.getPrincipal(), privileges, getRestrictions(superuser, path));
         /* give MODIFY_PROPERTIES privilege for a Group the test-user is member of */
@@ -795,6 +794,37 @@
         assertFalse(getTestSession().hasPermission(path, actions));
         assertFalse(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES)));
     }
+    
+    public void testInheritanceAndMixedUserGroupPermissions() throws RepositoryException, NotExecutableException {
+        Group testGroup = getTestGroup();
+        AccessControlManager testAcMgr = getTestACManager();
+        /*
+         precondition:
+         testuser must have READ-only permission on test-node and below
+        */
+        checkReadOnly(path);
+
+        Privilege[] privileges = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES);
+
+        /* give MODIFY_PROPERTIES privilege for testGroup at 'path' */
+        givePrivileges(path, testGroup.getPrincipal(), privileges, getRestrictions(superuser, path));
+
+        /* withdraw MODIFY_PROPERTIES for the user at 'path' */
+        withdrawPrivileges(path, testUser.getPrincipal(), privileges, getRestrictions(superuser, path));
+
+        /*
+         since user-permissions overrule the group permissions, testuser must
+         not have set_property action / modify_properties privilege.
+         */
+        assertFalse(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES)));
+
+        /*
+         give MODIFY_PROPERTIES privilege for everyone at 'childNPath'
+         -> user-privileges still overrule group privileges
+         */
+        givePrivileges(childNPath, testGroup.getPrincipal(), privileges, getRestrictions(superuser, path));
+        assertFalse(testAcMgr.hasPrivileges(childNPath, privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES)));
+    }
 
     public void testNewNodes() throws RepositoryException, NotExecutableException {
         AccessControlManager testAcMgr = getTestACManager();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java Tue Sep  8 16:09:28 2009
@@ -27,6 +27,7 @@
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlEntry;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.AccessControlPolicyIterator;
@@ -88,8 +89,8 @@
 
     public void testGetRestrictionType() {
         String[] names = templ.getRestrictionNames();
-        for (int i = 0; i < names.length; i++) {
-            int type = templ.getRestrictionType(names[i]);
+        for (String name : names) {
+            int type = templ.getRestrictionType(name);
             assertTrue(type > PropertyType.UNDEFINED);
         }
     }
@@ -115,14 +116,13 @@
         Privilege[] priv = privilegesFromName(Privilege.JCR_ALL);
 
         List entriesBefore = Arrays.asList(templ.getAccessControlEntries());
-        if (templ.addEntry(princ, priv, true, Collections.EMPTY_MAP)) {
+        if (templ.addEntry(princ, priv, true, Collections.<String, Value>emptyMap())) {
             AccessControlEntry[] entries = templ.getAccessControlEntries();
             if (entries.length == 0) {
                 fail("GrantPrivileges was successful -> at least 1 entry for principal.");
             }
             int allows = 0;
-            for (int i = 0; i < entries.length; i++) {
-                AccessControlEntry en = entries[i];
+            for (AccessControlEntry en : entries) {
                 int bits = PrivilegeRegistry.getBits(en.getPrivileges());
                 if (en instanceof JackrabbitAccessControlEntry && ((JackrabbitAccessControlEntry) en).isAllow()) {
                     allows |= bits;
@@ -140,12 +140,11 @@
         Privilege[] privs = privilegesFromName(PrivilegeRegistry.REP_WRITE);
 
         int allows = 0;
-        templ.addEntry(princ, privs, true, Collections.EMPTY_MAP);
+        templ.addEntry(princ, privs, true, Collections.<String, Value>emptyMap());
         AccessControlEntry[] entries = templ.getAccessControlEntries();
         assertTrue("GrantPrivileges was successful -> at least 1 entry for principal.", entries.length > 0);
 
-        for (int i = 0; i < entries.length; i++) {
-            AccessControlEntry en = entries[i];
+        for (AccessControlEntry en : entries) {
             int bits = PrivilegeRegistry.getBits(en.getPrivileges());
             if (en instanceof JackrabbitAccessControlEntry && ((JackrabbitAccessControlEntry) en).isAllow()) {
                 allows |= bits;
@@ -159,14 +158,13 @@
         Privilege[] grPriv = privilegesFromName(PrivilegeRegistry.REP_WRITE);
         Privilege[] dePriv = privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES);
 
-        templ.addEntry(princ, grPriv, true, Collections.EMPTY_MAP);
-        templ.addEntry(princ, dePriv, false, Collections.EMPTY_MAP);
+        templ.addEntry(princ, grPriv, true, Collections.<String, Value>emptyMap());
+        templ.addEntry(princ, dePriv, false, Collections.<String, Value>emptyMap());
 
         int allows = PrivilegeRegistry.NO_PRIVILEGE;
         int denies = PrivilegeRegistry.NO_PRIVILEGE;
         AccessControlEntry[] entries = templ.getAccessControlEntries();
-        for (int i = 0; i < entries.length; i++) {
-            AccessControlEntry en = entries[i];
+        for (AccessControlEntry en : entries) {
             if (princ.equals(en.getPrincipal()) && en instanceof JackrabbitAccessControlEntry) {
                 JackrabbitAccessControlEntry ace = (JackrabbitAccessControlEntry) en;
                 int entryBits = PrivilegeRegistry.getBits(ace.getPrivileges());
@@ -188,12 +186,12 @@
         Principal princ = getValidPrincipal();
         Privilege[] grPriv = privilegesFromName(PrivilegeRegistry.REP_WRITE);
 
-        templ.addEntry(princ, grPriv, true, Collections.EMPTY_MAP);
+        templ.addEntry(princ, grPriv, true, Collections.<String, Value>emptyMap());
         AccessControlEntry[] entries = templ.getAccessControlEntries();
         int length = entries.length;
         assertTrue("Grant was both successful -> at least 1 entry.", length > 0);
-        for (int i = 0; i < entries.length; i++) {
-            templ.removeAccessControlEntry(entries[i]);
+        for (AccessControlEntry entry : entries) {
+            templ.removeAccessControlEntry(entry);
             length = length - 1;
             assertEquals(length, templ.size());
             assertEquals(length, templ.getAccessControlEntries().length);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java Tue Sep  8 16:09:28 2009
@@ -85,7 +85,7 @@
     public void testRegisteredPrivileges() throws RepositoryException {
         Privilege[] ps = privilegeRegistry.getRegisteredPrivileges();
 
-        List l = new ArrayList(Arrays.asList(ps));
+        List<Privilege> l = new ArrayList<Privilege>(Arrays.asList(ps));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_READ)));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_ADD_CHILD_NODES)));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_REMOVE_CHILD_NODES)));
@@ -110,7 +110,7 @@
         assertTrue(p.isAggregate());
         assertFalse(p.isAbstract());
 
-        List l = new ArrayList(Arrays.asList(p.getAggregatePrivileges()));
+        List<Privilege> l = new ArrayList<Privilege>(Arrays.asList(p.getAggregatePrivileges()));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_READ)));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_ADD_CHILD_NODES)));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_REMOVE_CHILD_NODES)));
@@ -125,7 +125,7 @@
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_VERSION_MANAGEMENT)));
         assertTrue(l.isEmpty());
 
-        l = new ArrayList(Arrays.asList(p.getDeclaredAggregatePrivileges()));
+        l = new ArrayList<Privilege>(Arrays.asList(p.getDeclaredAggregatePrivileges()));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_READ)));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(Privilege.JCR_WRITE)));
         assertTrue(l.remove(privilegeRegistry.getPrivilege(PrivilegeRegistry.REP_WRITE)));

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/ACLTemplateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/ACLTemplateTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/ACLTemplateTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/ACLTemplateTest.java Tue Sep  8 16:09:28 2009
@@ -26,8 +26,8 @@
 import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlEntry;
-import javax.jcr.security.AccessControlException;
 import javax.jcr.security.Privilege;
 import java.security.Principal;
 import java.security.acl.Group;
@@ -52,30 +52,30 @@
     public void testMultipleEntryEffect() throws RepositoryException, NotExecutableException {
         JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
         Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
-        pt.addEntry(testPrincipal, privileges, true, Collections.EMPTY_MAP);
+        pt.addEntry(testPrincipal, privileges, true, Collections.<String, Value>emptyMap());
 
-        // new entry extends privs.
+        // new entry extends privileges.
         privileges = privilegesFromNames(new String[] {
                 Privilege.JCR_READ,
                 Privilege.JCR_ADD_CHILD_NODES});
         assertTrue(pt.addEntry(testPrincipal,
                 privileges,
-                true, Collections.EMPTY_MAP));
+                true, Collections.<String, Value>emptyMap()));
 
         // net-effect: only a single allow-entry with both privileges
         assertTrue(pt.size() == 1);
         assertSamePrivileges(privileges, pt.getAccessControlEntries()[0].getPrivileges());
 
-        // adding just ADD_CHILD_NODES -> must not remove READ priv
+        // adding just ADD_CHILD_NODES -> must not remove READ privilege
         Privilege[] achPrivs = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
-        assertFalse(pt.addEntry(testPrincipal, achPrivs, true, Collections.EMPTY_MAP));
-        // net-effect: only a single allow-entry with add_child_nodes + read priv
+        assertFalse(pt.addEntry(testPrincipal, achPrivs, true, Collections.<String, Value>emptyMap()));
+        // net-effect: only a single allow-entry with add_child_nodes + read privilege
         assertTrue(pt.size() == 1);
         assertSamePrivileges(privileges, pt.getAccessControlEntries()[0].getPrivileges());
 
         // revoke the 'READ' privilege
         privileges = privilegesFromName(Privilege.JCR_READ);
-        assertTrue(pt.addEntry(testPrincipal, privileges, false, Collections.EMPTY_MAP));
+        assertTrue(pt.addEntry(testPrincipal, privileges, false, Collections.<String, Value>emptyMap()));
         // net-effect: 2 entries one allowing ADD_CHILD_NODES, the other denying READ
         assertTrue(pt.size() == 2);
         assertSamePrivileges(privilegesFromName(Privilege.JCR_ADD_CHILD_NODES),
@@ -106,8 +106,8 @@
         // net-effect: 2 entries with the allow entry being adjusted
         assertTrue(pt.size() == 2);
         AccessControlEntry[] entries = pt.getAccessControlEntries();
-        for (int i = 0; i < entries.length; i++) {
-            ACLTemplate.Entry entry = (ACLTemplate.Entry) entries[i];
+        for (AccessControlEntry entry1 : entries) {
+            ACLTemplate.Entry entry = (ACLTemplate.Entry) entry1;
             int privs = entry.getPrivilegeBits();
             if (entry.isAllow()) {
                 int bits = PrivilegeRegistry.getBits(privileges) ^ PrivilegeRegistry.getBits(privileges2);
@@ -138,7 +138,7 @@
         pt.addAccessControlEntry(testPrincipal, privs);
         assertFalse(pt.addAccessControlEntry(testPrincipal, privs));
 
-        // add same privs for another principal -> must modify as well.
+        // add same privileges for another principal -> must modify as well.
         assertTrue(pt.addAccessControlEntry(everyone, privs));
         // .. 2 entries must be present.
         assertTrue(pt.getAccessControlEntries().length == 2);
@@ -153,22 +153,17 @@
         assertTrue(pt.addAccessControlEntry(grPrincipal, privs));
 
         // adding deny-entry must succeed
-        try {
-            pt.addEntry(grPrincipal, privs, false, null);
-            fail("Adding DENY-ace for a group principal should fail.");
-        } catch (AccessControlException e) {
-            // success
-        }
+        pt.addEntry(grPrincipal, privs, false, null);
     }
 
     public void testRevokeEffect() throws RepositoryException, NotExecutableException {
         JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
         Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
 
-        pt.addEntry(testPrincipal, privileges, true, Collections.EMPTY_MAP);
+        pt.addEntry(testPrincipal, privileges, true, Collections.<String, Value>emptyMap());
 
         // same entry but with revers 'isAllow' flag
-        assertTrue(pt.addEntry(testPrincipal, privileges, false, Collections.EMPTY_MAP));
+        assertTrue(pt.addEntry(testPrincipal, privileges, false, Collections.<String, Value>emptyMap()));
 
         // net-effect: only a single deny-read entry
         assertTrue(pt.size() == 1);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java Tue Sep  8 16:09:28 2009
@@ -22,6 +22,7 @@
 import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.AccessControlPolicyIterator;
@@ -41,13 +42,14 @@
                 return true;
             }
         } catch (RepositoryException e) {
+            // ignore
         }
         return false;
     }
 
     static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException,
             AccessDeniedException, NotExecutableException {
-        // try applicable (new) acls first
+        // try applicable (new) ACLs first
         AccessControlPolicyIterator itr = acM.getApplicablePolicies(path);
         while (itr.hasNext()) {
             AccessControlPolicy policy = itr.nextAccessControlPolicy();
@@ -57,8 +59,7 @@
         }
         // try if there is an acl that has been set before:
         AccessControlPolicy[] pcls = acM.getPolicies(path);
-        for (int i = 0; i < pcls.length; i++) {
-            AccessControlPolicy policy = pcls[i];
+        for (AccessControlPolicy policy : pcls) {
             if (policy instanceof ACLTemplate) {
                 return (ACLTemplate) policy;
             }
@@ -67,7 +68,7 @@
         throw new NotExecutableException();
     }
 
-    static Map getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
-        return Collections.EMPTY_MAP;
+    static Map<String, Value> getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
+        return Collections.emptyMap();
     }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java Tue Sep  8 16:09:28 2009
@@ -22,6 +22,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import java.security.Principal;
 import java.util.Map;
@@ -37,7 +38,7 @@
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);
     }
-    protected Map getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
+    protected Map<String, Value> getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
         return EvaluationUtil.getRestrictions(s, path);
     }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java Tue Sep  8 16:09:28 2009
@@ -22,6 +22,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import java.security.Principal;
 import java.util.Map;
@@ -37,7 +38,7 @@
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);
     }
-    protected Map getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
+    protected Map<String, Value> getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
         return EvaluationUtil.getRestrictions(s, path);
     }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java Tue Sep  8 16:09:28 2009
@@ -22,6 +22,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import java.security.Principal;
 import java.util.Map;
@@ -37,7 +38,7 @@
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);
     }
-    protected Map getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
+    protected Map<String, Value> getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
         return EvaluationUtil.getRestrictions(s, path);
     }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java Tue Sep  8 16:09:28 2009
@@ -27,6 +27,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.AccessControlPolicyIterator;
@@ -48,8 +49,8 @@
         return EvaluationUtil.getPolicy(acM, path, principal);
     }
 
-    protected Map getRestrictions(Session s, String path) {
-        return Collections.EMPTY_MAP;
+    protected Map<String, Value> getRestrictions(Session s, String path) {
+        return Collections.emptyMap();
     }
 
     public void testAccessControlModification2() throws RepositoryException, NotExecutableException {
@@ -169,4 +170,48 @@
         it = acMgr.getApplicablePolicies(childNPath);
         assertTrue(it.hasNext());
     }
+
+    public void testInheritance2() throws RepositoryException, NotExecutableException {
+        Session testSession = getTestSession();
+        AccessControlManager testAcMgr = getTestACManager();
+
+        /*
+          precondition:
+          testuser must have READ-only permission on test-node and below
+        */
+        checkReadOnly(path);
+        checkReadOnly(childNPath);
+
+        // give jcr:write privilege on 'path' and withdraw them on 'childNPath'
+        Privilege[] privileges = privilegesFromNames(new String[] {Privilege.JCR_WRITE});
+        givePrivileges(path, privileges, getRestrictions(superuser, path));
+        withdrawPrivileges(childNPath, privileges, getRestrictions(superuser, path));
+
+        /*
+        since evaluation respects inheritance through the node
+        hierarchy, the jcr:write privilege must not be granted at childNPath
+        */
+        assertFalse(testAcMgr.hasPrivileges(childNPath, privileges));
+
+        /*
+         ... same for permissions at 'childNPath'
+         */
+        String actions = Session.ACTION_SET_PROPERTY + "," + Session.ACTION_REMOVE + "," + Session.ACTION_ADD_NODE;
+
+        String nonExistingItemPath = childNPath + "/anyItem";
+        assertFalse(testSession.hasPermission(nonExistingItemPath, actions));
+
+        // yet another level in the hierarchy
+        Node grandChild = superuser.getNode(childNPath).addNode(nodeName3);
+        superuser.save();
+        String gcPath = grandChild.getPath();
+
+        // grant write privilege again
+        givePrivileges(gcPath, privileges, getRestrictions(superuser, path));
+        assertTrue(testAcMgr.hasPrivileges(gcPath, privileges));
+        assertTrue(testSession.hasPermission(gcPath + "/anyProp", Session.ACTION_SET_PROPERTY));
+        // however: removing the grand-child nodes must not be allowed as
+        // remove_child_node privilege is missing on the direct ancestor.
+        assertFalse(testSession.hasPermission(gcPath, Session.ACTION_REMOVE));
+    }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java Tue Sep  8 16:09:28 2009
@@ -29,6 +29,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.Privilege;
@@ -58,10 +59,9 @@
     private JackrabbitAccessControlList getPrincipalBasedPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException {
         if (acM instanceof JackrabbitAccessControlManager) {
             AccessControlPolicy[] tmpls = ((JackrabbitAccessControlManager) acM).getApplicablePolicies(principal);
-            for (int i = 0; i < tmpls.length; i++) {
-                if (tmpls[i] instanceof JackrabbitAccessControlList) {
-                    JackrabbitAccessControlList acl = (JackrabbitAccessControlList) tmpls[i];
-                    return acl;
+            for (AccessControlPolicy tmpl : tmpls) {
+                if (tmpl instanceof JackrabbitAccessControlList) {
+                    return (JackrabbitAccessControlList) tmpl;
                 }
             }
         }
@@ -71,7 +71,7 @@
     private JackrabbitAccessControlList givePrivileges(String nPath,
                                                        Principal principal,
                                                        Privilege[] privileges,
-                                                       Map restrictions,
+                                                       Map<String, Value> restrictions,
                                                        boolean nodeBased) throws NotExecutableException, RepositoryException {
         if (nodeBased) {
             return givePrivileges(nPath, principal, privileges, getRestrictions(superuser, nPath));
@@ -87,7 +87,7 @@
     private JackrabbitAccessControlList withdrawPrivileges(String nPath,
                                                        Principal principal,
                                                        Privilege[] privileges,
-                                                       Map restrictions,
+                                                       Map<String, Value> restrictions,
                                                        boolean nodeBased) throws NotExecutableException, RepositoryException {
         if (nodeBased) {
             return withdrawPrivileges(nPath, principal, privileges, getRestrictions(superuser, nPath));
@@ -100,9 +100,9 @@
         }
     }
 
-    private Map getPrincipalBasedRestrictions(String path) throws RepositoryException, NotExecutableException {
+    private Map<String, Value> getPrincipalBasedRestrictions(String path) throws RepositoryException, NotExecutableException {
         if (superuser instanceof SessionImpl) {
-            Map restr = new HashMap();
+            Map<String, Value> restr = new HashMap<String, Value>();
             restr.put("rep:nodePath", superuser.getValueFactory().createValue(path, PropertyType.PATH));
             return restr;
         } else {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java?rev=812570&r1=812569&r2=812570&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java Tue Sep  8 16:09:28 2009
@@ -33,7 +33,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -42,7 +41,7 @@
  */
 public class EntryTest extends AbstractEntryTest {
 
-    private Map restrictions;
+    private Map<String, Value> restrictions;
     private ACLTemplate acl;
 
     private String nodePath;
@@ -59,7 +58,7 @@
             throw new NotExecutableException();
         }
 
-        restrictions = new HashMap(2);
+        restrictions = new HashMap<String, Value>(2);
         restrictions.put(nodePath, superuser.getValueFactory().createValue("/a/b/c/d", PropertyType.PATH));
         restrictions.put(glob,  superuser.getValueFactory().createValue("*"));
         acl = new ACLTemplate(testPrincipal, testPath, (SessionImpl) superuser, superuser.getValueFactory());
@@ -70,7 +69,7 @@
         return (JackrabbitAccessControlEntry) acl.createEntry(principal, privileges, isAllow, restrictions);
     }
 
-    private JackrabbitAccessControlEntry createEntry(Principal principal, Privilege[] privileges, boolean isAllow, Map restrictions)
+    private JackrabbitAccessControlEntry createEntry(Principal principal, Privilege[] privileges, boolean isAllow, Map<String, Value> restrictions)
             throws RepositoryException {
         return (JackrabbitAccessControlEntry) acl.createEntry(principal, privileges, isAllow, restrictions);
     }
@@ -78,7 +77,7 @@
     public void testNodePathMustNotBeNull() throws RepositoryException, NotExecutableException {
         try {
             Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
-            createEntry(testPrincipal, privs, true, Collections.EMPTY_MAP);
+            createEntry(testPrincipal, privs, true, Collections.<String, Value>emptyMap());
             fail("NodePath cannot not be null");
         } catch (AccessControlException e) {
             // success
@@ -101,19 +100,19 @@
         assertEquals(restrictions.get(glob), pe.getRestriction(glob));
         assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
 
-        Map restr = new HashMap();
+        Map<String, Value> restr = new HashMap<String, Value>();
         restr.put(nodePath,  restrictions.get(nodePath));
         pe = createEntry(testPrincipal, privs, true, restr);
         assertNull(pe.getRestriction(glob));
 
-        restr = new HashMap();
+        restr = new HashMap<String, Value>();
         restr.put(nodePath,  restrictions.get(nodePath));
         restr.put(glob,  new StringValue(""));
 
         pe = createEntry(testPrincipal, privs, true, restr);
         assertEquals("", pe.getRestriction(glob).getString());
 
-        restr = new HashMap();
+        restr = new HashMap<String, Value>();
         restr.put(nodePath,  restrictions.get(nodePath));
         restr.put(glob,  new BooleanValue(true));
         assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
@@ -124,14 +123,14 @@
         // match the required ones.
         Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
 
-        Map restr = new HashMap();
+        Map<String, Value> restr = new HashMap<String, Value>();
         restr.put(nodePath, new StringValue("/a/b/c/d"));
         JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true, restr);
 
         assertEquals("/a/b/c/d", pe.getRestriction(nodePath).getString());
         assertEquals(PropertyType.PATH, pe.getRestriction(nodePath).getType());
 
-        restr = new HashMap();
+        restr = new HashMap<String, Value>();
         restr.put(nodePath,  restrictions.get(nodePath));
         restr.put(glob,  new BooleanValue(true));
         pe = createEntry(testPrincipal, privs, true, restr);
@@ -144,25 +143,22 @@
         Privilege[] privs = new Privilege[] {acMgr.privilegeFromName(Privilege.JCR_ALL)};
         ACLTemplate.Entry ace = (ACLTemplate.Entry) createEntry(testPrincipal, privs, true);
 
-        String nPath = ((Value) restrictions.get(nodePath)).getString();
-        List toMatch = new ArrayList();
+        String nPath = restrictions.get(nodePath).getString();
+        List<String> toMatch = new ArrayList<String>();
         toMatch.add(nPath + "/any");
         toMatch.add(nPath + "/anyother");
         toMatch.add(nPath + "/f/g/h");
         toMatch.add(nPath);
-        for (Iterator it = toMatch.iterator(); it.hasNext();) {
-            String str = it.next().toString();
+        for (String str : toMatch) {
             assertTrue("Restrictions should match " + str, ace.matches(str));
         }
 
-        List notToMatch = new ArrayList();
+        List<String> notToMatch = new ArrayList<String>();
         notToMatch.add(null);
         notToMatch.add("");
         notToMatch.add("/");
         notToMatch.add("/a/b/c/");
-        for (Iterator it = notToMatch.iterator(); it.hasNext();) {
-            Object obj = it.next();
-            String str = (obj == null) ? null : obj.toString();
+        for (String str : notToMatch) {
             assertFalse("Restrictions shouldn't match " + str, ace.matches(str));
         }
     }



Mime
View raw message