use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class CustomPrivilegeTest method testInvalidCustomDefinitions.
public void testInvalidCustomDefinitions() throws RepositoryException, FileSystemException, IOException {
// setup the custom privilege file with cyclic references
FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
if (!resource.exists()) {
resource.makeParentDirs();
}
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><privileges><privilege isAbstract=\"false\" name=\"test\"><contains name=\"test2\"/></privilege></privileges>");
Writer writer = new OutputStreamWriter(resource.getOutputStream(), "utf-8");
writer.write(sb.toString());
writer.flush();
writer.close();
try {
new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
fail("Invalid names must be detected upon registry startup.");
} catch (RepositoryException e) {
// success
} finally {
fs.deleteFolder("/privileges");
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class CustomPrivilegeTest method testCustomDefinitionsWithCyclicReferences.
public void testCustomDefinitionsWithCyclicReferences() throws RepositoryException, FileSystemException, IOException {
// setup the custom privilege file with cyclic references
FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
if (!resource.exists()) {
resource.makeParentDirs();
}
NameFactory nf = NameFactoryImpl.getInstance();
Name test = nf.create(Name.NS_DEFAULT_URI, "test");
Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
OutputStream out = resource.getOutputStream();
try {
List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
defs.add(new PrivilegeDefinitionImpl(test, false, Collections.singleton(test2)));
defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.singleton(test5)));
defs.add(new PrivilegeDefinitionImpl(test5, false, Collections.singleton(test3)));
defs.add(new PrivilegeDefinitionImpl(test3, false, Collections.singleton(test)));
defs.add(new PrivilegeDefinitionImpl(test2, false, Collections.singleton(test4)));
PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
fail("Cyclic definitions must be detected upon registry startup.");
} catch (RepositoryException e) {
// success
} finally {
out.close();
fs.deleteFolder("/privileges");
}
}
Aggregations