Author: rhauch
Date: 2009-06-17 13:19:33 -0400 (Wed, 17 Jun 2009)
New Revision: 1052
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
Log:
DNA-399 Need to Add Session.checkPermission Calls to Guard Read, Add Node, Set Property,
and Remove Item Access
DNA-453 Implement Workspace.copy(String, String, String)
Corrected JavaDoc and changed private method to protected to eliminate performance
warning.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-06-15 14:54:13
UTC (rev 1051)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-06-17 17:19:33
UTC (rev 1052)
@@ -233,13 +233,13 @@
/**
* Checks whether the current session has the appropriate permissions to perform the
given action.
*
- * @param the node on which the action will be performed
+ * @param node the node on which the action will be performed
* @param action the name of the action to perform, should be "add_node",
"remove", or "set_property"
* @throws AccessDeniedException if the current session does not have the requisite
privileges to perform this task
* @throws RepositoryException if any other error occurs
*/
- private void checkPermission( NodeInfo node,
- String action ) throws AccessDeniedException,
RepositoryException {
+ protected void checkPermission( NodeInfo node,
+ String action ) throws AccessDeniedException,
RepositoryException {
try {
this.session.checkPermission(SessionCache.this.getPathFor(node), action);
} catch (AccessControlException ace) {
@@ -1462,8 +1462,8 @@
if (!definition.getId().equals(node.getDefinitionId())) {
// The node definition changed, so try to set the property ...
try {
- JcrValue value = new JcrValue(factories(), SessionCache.this,
PropertyType.STRING,
- definition.getId().getString());
+ JcrValue value = new JcrValue(factories(), SessionCache.this,
PropertyType.STRING, definition.getId()
+
.getString());
setProperty(DnaIntLexicon.NODE_DEFINITON, value);
} catch (ConstraintViolationException e) {
// We can't set this property on the node (according to the node
definition).
@@ -1859,6 +1859,7 @@
*
* @param uuid the UUID for the node; may not be null
* @return the information for the node with the supplied UUID, or null if the
information is not in the cache
+ * @throws AccessDeniedException if the node cannot be accessed
* @throws ItemNotFoundException if there is no node with the supplied UUID
* @throws InvalidItemStateException if the node with the UUID has been deleted in
this session
* @throws RepositoryException if any other error occurs while reading information
from the repository
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java 2009-06-15 14:54:13 UTC
(rev 1051)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java 2009-06-17 17:19:33 UTC
(rev 1052)
@@ -12,19 +12,19 @@
/**
* Additional DNA tests that check for JCR compliance.
- *
*/
public class DnaTckTest extends AbstractJCRTest {
Session session;
+ @Override
protected void tearDown() throws Exception {
try {
superuser.getRootNode().getNode(this.nodeName1).remove();
superuser.save();
+ } catch (PathNotFoundException ignore) {
}
- catch (PathNotFoundException ignore) { }
-
+
if (session != null) {
session.logout();
session = null;
@@ -32,22 +32,22 @@
super.tearDown();
}
- private void testRead(Session session) throws Exception {
+ private void testRead( Session session ) throws Exception {
Node rootNode = session.getRootNode();
-
- for (NodeIterator iter = rootNode.getNodes(); iter.hasNext(); ) {
+
+ for (NodeIterator iter = rootNode.getNodes(); iter.hasNext();) {
iter.nextNode();
}
}
-
- private void testAddNode(Session session) throws Exception {
+
+ private void testAddNode( Session session ) throws Exception {
session.refresh(false);
Node root = session.getRootNode();
root.addNode(nodeName1, testNodeType);
session.save();
}
-
- private void testRemoveNode(Session session) throws Exception {
+
+ private void testRemoveNode( Session session ) throws Exception {
session.refresh(false);
Node root = session.getRootNode();
Node node = root.getNode(nodeName1);
@@ -55,31 +55,30 @@
session.save();
}
- private void testSetProperty(Session session) throws Exception {
+ private void testSetProperty( Session session ) throws Exception {
session.refresh(false);
Node root = session.getRootNode();
root.setProperty(this.propertyName1, "test value");
session.save();
-
+
}
-
- private void testRemoveProperty(Session session) throws Exception {
+
+ private void testRemoveProperty( Session session ) throws Exception {
Session localAdmin =
helper.getRepository().login(helper.getSuperuserCredentials(),
session.getWorkspace().getName());
assertEquals(session.getWorkspace().getName(),
superuser.getWorkspace().getName());
-
+
Node superRoot = localAdmin.getRootNode();
Node superNode;
try {
superNode = superRoot.getNode(this.nodeName1);
- }
- catch (PathNotFoundException pnfe) {
+ } catch (PathNotFoundException pnfe) {
superNode = superRoot.addNode(nodeName1, testNodeType);
}
superNode.setProperty(this.propertyName1, "test value");
localAdmin.save();
localAdmin.logout();
-
+
session.refresh(false);
Node root = session.getRootNode();
Node node = root.getNode(nodeName1);
@@ -87,8 +86,8 @@
property.remove();
session.save();
}
-
- private void testWrite(Session session) throws Exception {
+
+ private void testWrite( Session session ) throws Exception {
testAddNode(session);
testSetProperty(session);
testRemoveProperty(session);
@@ -97,6 +96,7 @@
/**
* Tests that read-only sessions can read nodes by loading all of the children of the
root node
+ *
* @throws Exception
*/
public void testShouldAllowReadOnlySessionToRead() throws Exception {
@@ -106,6 +106,7 @@
/**
* Tests that read-only sessions cannot add nodes, remove nodes, set nodes, or set
properties.
+ *
* @throws Exception
*/
public void testShouldNotAllowReadOnlySessionToWrite() throws Exception {
@@ -113,31 +114,28 @@
try {
testAddNode(session);
fail("Read-only sessions should not be able to add nodes");
+ } catch (AccessDeniedException expected) {
}
- catch (AccessDeniedException expected) {
- }
try {
testSetProperty(session);
fail("Read-only sessions should not be able to set properties");
+ } catch (AccessDeniedException expected) {
}
- catch (AccessDeniedException expected) {
- }
try {
testRemoveProperty(session);
fail("Read-only sessions should not be able to remove
properties");
+ } catch (AccessDeniedException expected) {
}
- catch (AccessDeniedException expected) {
- }
try {
testRemoveNode(session);
fail("Read-only sessions should not be able to remove nodes");
+ } catch (AccessDeniedException expected) {
}
- catch (AccessDeniedException expected) {
- }
}
-
+
/**
* Tests that read-write sessions can read nodes by loading all of the children of
the root node
+ *
* @throws Exception
*/
public void testShouldAllowReadWriteSessionToRead() throws Exception {
@@ -147,6 +145,7 @@
/**
* Tests that read-write sessions can add nodes, remove nodes, set nodes, and set
properties.
+ *
* @throws Exception
*/
public void testShouldAllowReadWriteSessionToWrite() throws Exception {
@@ -155,8 +154,9 @@
}
/**
- * User defaultuser is configured to have readwrite in "otherWorkspace" and
readonly in the default
- * workspace. This test makes sure both work.
+ * User defaultuser is configured to have readwrite in "otherWorkspace" and
readonly in the default workspace. This test makes
+ * sure both work.
+ *
* @throws Exception
*/
public void testShouldMapRolesToWorkspacesWhenSpecified() throws Exception {
@@ -165,21 +165,19 @@
testRead(session);
testWrite(session);
-
+
session.logout();
-
+
session = helper.getRepository().login(creds, "otherWorkspace");
testRead(session);
try {
testWrite(session);
fail("User 'defaultuser' should not have write access to
'otherWorkspace'");
+ } catch (AccessDeniedException expected) {
}
- catch (AccessDeniedException expected) {
- }
session.logout();
}
-
public void testShouldCopyFromAnotherWorkspace() throws Exception {
session = helper.getSuperuserSession("otherWorkspace");
String nodetype1 = this.getProperty("nodetype");
@@ -187,16 +185,16 @@
node1.addNode(nodeName2, nodetype1);
session.save();
session.logout();
-
+
superuser.getRootNode().addNode(nodeName4, nodetype1);
superuser.save();
-
+
superuser.getWorkspace().copy("otherWorkspace", "/" +
nodeName1, "/" + nodeName4 + "/" + nodeName1);
-
+
Node node4 = superuser.getRootNode().getNode(nodeName4);
Node node4node1 = node4.getNode(nodeName1);
Node node4node1node2 = node4node1.getNode(nodeName2);
-
+
assertNotNull(node4node1node2);
}
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-06-15
14:54:13 UTC (rev 1051)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-06-17
17:19:33 UTC (rev 1052)
@@ -184,7 +184,6 @@
repository.login();
}
- @SuppressWarnings("cast")
@Test
public void shouldAllowLoginWithNoCredentialsInPrivilegedBlock() throws Exception {
LoginContext login = new LoginContext("dna-jcr", new
UserPasswordCallbackHandler("superuser", "superuser".toCharArray()));