public void testUserCanRemoveParentButCanNotRemoveChild() throws Exception
{
// login as Mary and create subNode
Session sessMary = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
Node testRoot = sessMary.getRootNode().getNode("testRoot");
NodeImpl subNode = (NodeImpl)testRoot.addNode("subNode");
subNode.addMixin("exo:privilegeable");
sessMary.save();
subNode.setPermission("mary", PermissionType.ALL);
subNode.removePermission("john");
subNode.removePermission(SystemIdentity.ANY);
sessMary.save();
sessMary.logout();
// login as John and try remove subnode
Session sessJohn = repository.login(new CredentialsImpl("john", "exo".toCharArray()));
try
{
subNode = (NodeImpl)sessJohn.getRootNode().getNode("testRoot").getNode("subNode");
subNode.remove();
sessJohn.save();
fail("There must be AccessDeniedException");
}
catch (AccessDeniedException e)
{
//Ok
}
// try to remove parent node node
sessJohn.refresh(false);
try
{
testRoot = sessJohn.getRootNode().getNode("testRoot");
testRoot.remove();
sessJohn.save();
fail("There must be AccessDeniedException");
}
catch (AccessDeniedException e)
{
//Ok
}
finally
{
sessJohn.logout();
}
// now try with all permissions
sessMary = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
testRoot = sessMary.getRootNode().getNode("testRoot");
subNode = (NodeImpl)testRoot.getNode("subNode");
subNode.setPermission(SystemIdentity.ANY, PermissionType.ALL);
sessMary.save();
sessMary.logout();
sessJohn = repository.login(new CredentialsImpl("john", "exo".toCharArray()));
testRoot = sessJohn.getRootNode().getNode("testRoot");