}
private void contentWithCustomOwnerAndPrivilege(boolean isSystemViewExport) throws Exception
{
// prepare content
NodeImpl testRoot = (NodeImpl)root.addNode("restricted", "nt:unstructured");
testRoot.addMixin("exo:privilegeable");
HashMap<String, String[]> perm = new HashMap<String, String[]>();
perm.put("john", new String[]{"read", "add_node", "set_property", "remove"});
perm.put("*:/platform/administrators", new String[]{"read", "add_node", "set_property", "remove"});
((ExtendedNode)testRoot).setPermissions(perm);
session.save();
testRoot.addMixin("exo:owneable");
assertEquals("admin", testRoot.getProperty("exo:owner").getString());
assertEquals("admin", testRoot.getACL().getOwner());
Session sessJohn = repository.login(new CredentialsImpl("john", "exo".toCharArray()), "ws");
Node file = sessJohn.getRootNode().getNode("restricted").addNode("accept.gif", "nt:file");
file.addMixin("exo:privilegeable");
perm = new HashMap<String, String[]>();
perm.put("*:/platform/administrators", new String[]{"read", "add_node", "set_property", "remove"});
perm.put("root", new String[]{"read", "add_node", "set_property", "remove"});
perm.put("*:/organization/management/executive-board", new String[]{"read", "add_node", "set_property", "remove"});
perm.put("/platform/administrators", new String[]{"read", "add_node", "set_property", "remove"});
perm.put("any", new String[]{"read"});
((ExtendedNode)file).setPermissions(perm);
file.addMixin("exo:owneable");
assertEquals("john", file.getProperty("exo:owner").getString());
assertEquals("john", ((ExtendedNode)file).getACL().getOwner());
Node cont = (NodeImpl)file.addNode("jcr:content", "nt:resource");
cont.setProperty("jcr:mimeType", "text/plain");
cont.setProperty("jcr:lastModified", Calendar.getInstance());
cont.setProperty("jcr:data", new FileInputStream(createBLOBTempFile(1)));
sessJohn.save();
assertEquals("john", ((ExtendedNode)cont).getACL().getOwner());
Credentials cred = new CredentialsImpl("demo", "exo".toCharArray());
Session sess = repository.login(cred, "ws");
assertNotNull(sess.getItem("/restricted/accept.gif"));
assertNotNull(sess.getItem("/restricted/accept.gif/jcr:content"));
sess.logout();
// export
File exportFile = isSystemViewExport ? File.createTempFile("sys-export", ".xml") : File.createTempFile("doc-export", ".xml");
exportFile.deleteOnExit();
if (isSystemViewExport)
{
sess.exportSystemView(file.getPath(), new FileOutputStream(exportFile), false, false);
}
else
{
sess.exportDocumentView(file.getPath(), new FileOutputStream(exportFile), false, false);
}
// remove existed node
file.remove();
sessJohn.save();
try
{
testRoot.getNode("accept.gif");
fail();
}
catch (PathNotFoundException e) {
//ok
}