SessionImpl johnSession = (SessionImpl)repositoryService.getRepository("db2").login(johnCredentials, "ws1");
Credentials anonCredentials = new CredentialsImpl(SystemIdentity.ANONIM, "".toCharArray());
SessionImpl anonSession = (SessionImpl)repositoryService.getRepository("db2").login(anonCredentials, "ws1");
NodeImpl node = (NodeImpl)sessionWS1.getRootNode().addNode(TESTNODE_NAME);
node.addMixin("exo:privilegeable");
node.addMixin("exo:owneable");
node.addMixin("mix:versionable");
node.setPermission("*:/platform/administrators", PermissionType.ALL);
node.setPermission("mary",
new String[]{PermissionType.READ, PermissionType.SET_PROPERTY, PermissionType.ADD_NODE});
node.removePermission(SystemIdentity.ANY);
sessionWS1.save();
// child node exo:privilegeable & exo:owneable
NodeImpl childNode1 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME1);
childNode1.addMixin("exo:privilegeable");
childNode1.addMixin("exo:owneable");
childNode1.setPermission("*:/platform/administrators", PermissionType.ALL);
childNode1.setPermission("mary", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY});
childNode1.removePermission(SystemIdentity.ANY);
sessionWS1.save();
// child node all inherited from parent
NodeImpl childNode2 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME2);
sessionWS1.save();
// child node exo:owneable
node = (NodeImpl)johnSession.getRootNode().getNode(TESTNODE_NAME);
NodeImpl childNode3 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME3);
childNode3.addMixin("exo:owneable");
johnSession.save();
node = (NodeImpl)sessionWS1.getRootNode().getNode(TESTNODE_NAME);
// child node exo:privilegeable
NodeImpl childNode4 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME4);
childNode4.addMixin("exo:privilegeable");
childNode4.setPermission("*:/platform/administrators", PermissionType.ALL);
childNode4.setPermission("mary", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY});
childNode4.removePermission(SystemIdentity.ANY);
sessionWS1.save();
// check what we have
NodeImpl marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
assertTrue(marysNode.hasPermission(PermissionType.READ));
assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
assertFalse(marysNode.hasPermission(PermissionType.REMOVE));
assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), "admin");
NodeImpl marysChildNode1 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME1);
assertTrue(marysChildNode1.hasPermission(PermissionType.READ));
assertTrue(marysChildNode1.hasPermission(PermissionType.SET_PROPERTY));
assertFalse(marysChildNode1.hasPermission(PermissionType.ADD_NODE));
assertEquals(((NodeData)marysChildNode1.getData()).getACL().getOwner(), "admin");
NodeImpl marysChildNode2 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME2);
assertTrue(marysNode.hasPermission(PermissionType.READ));
assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
assertFalse(marysNode.hasPermission(PermissionType.REMOVE));;
assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");
NodeImpl marysChildNode3 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME3);
assertTrue(marysChildNode3.hasPermission(PermissionType.READ));
assertTrue(marysChildNode3.hasPermission(PermissionType.SET_PROPERTY));
assertTrue(marysChildNode3.hasPermission(PermissionType.ADD_NODE));
assertFalse(marysChildNode3.hasPermission(PermissionType.REMOVE));
assertEquals(((NodeData)marysChildNode3.getData()).getACL().getOwner(), "john");
NodeImpl marysChildNode4 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME4);
assertTrue(marysChildNode4.hasPermission(PermissionType.READ));
assertTrue(marysChildNode4.hasPermission(PermissionType.SET_PROPERTY));
assertFalse(marysChildNode4.hasPermission(PermissionType.REMOVE));;
assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");
// for __anonim
try
{
anonSession.getRootNode().getNode(TESTNODE_NAME);
}
catch (AccessDeniedException e)
{
// ok
}
// v1
VersionImpl version = (VersionImpl)node.checkin();
node.checkout();
// check frozen node and its children nodes
NodeImpl frozenNode =
(NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME).getVersionHistory().getVersion("1")
.getNode("jcr:frozenNode");
assertTrue(frozenNode.hasPermission(PermissionType.READ));
assertTrue(frozenNode.hasPermission(PermissionType.SET_PROPERTY));
assertTrue(frozenNode.hasPermission(PermissionType.ADD_NODE));
assertFalse(frozenNode.hasPermission(PermissionType.REMOVE));
assertEquals(((NodeData)frozenNode.getData()).getACL().getOwner(), "admin");
marysChildNode1 = (NodeImpl)frozenNode.getNode(CHILD_TESTNODE_NAME1);
assertTrue(marysChildNode1.hasPermission(PermissionType.READ));
assertTrue(marysChildNode1.hasPermission(PermissionType.SET_PROPERTY));
assertFalse(marysChildNode1.hasPermission(PermissionType.ADD_NODE));
assertEquals(((NodeData)marysChildNode1.getData()).getACL().getOwner(), "admin");
marysChildNode2 = (NodeImpl)frozenNode.getNode(CHILD_TESTNODE_NAME2);
assertTrue(marysNode.hasPermission(PermissionType.READ));
assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
assertFalse(marysNode.hasPermission(PermissionType.REMOVE));;
assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");
marysChildNode3 = (NodeImpl)frozenNode.getNode(CHILD_TESTNODE_NAME3);
assertTrue(marysChildNode3.hasPermission(PermissionType.READ));
assertTrue(marysChildNode3.hasPermission(PermissionType.SET_PROPERTY));
assertTrue(marysChildNode3.hasPermission(PermissionType.ADD_NODE));
assertFalse(marysChildNode3.hasPermission(PermissionType.REMOVE));
assertEquals(((NodeData)marysChildNode3.getData()).getACL().getOwner(), "john");
marysChildNode4 = (NodeImpl)frozenNode.getNode(CHILD_TESTNODE_NAME4);
assertTrue(marysChildNode4.hasPermission(PermissionType.READ));
assertTrue(marysChildNode4.hasPermission(PermissionType.SET_PROPERTY));
assertFalse(marysChildNode4.hasPermission(PermissionType.REMOVE));;
assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");