use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter in project jackrabbit by apache.
the class AbstractRecord method writePrivilegeDef.
/**
* {@inheritDoc}
*/
public void writePrivilegeDef(PrivilegeDefinition privilegeDefinition) throws JournalException {
try {
Map<String, String> nsMapping = new HashMap<String, String>();
String uri = privilegeDefinition.getName().getNamespaceURI();
nsMapping.put(nsResolver.getPrefix(uri), uri);
for (Name n : privilegeDefinition.getDeclaredAggregateNames()) {
nsMapping.put(nsResolver.getPrefix(n.getNamespaceURI()), n.getNamespaceURI());
}
StringWriter sw = new StringWriter();
PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter("text/xml");
writer.writeDefinitions(sw, new PrivilegeDefinition[] { privilegeDefinition }, nsMapping);
sw.close();
writeString(sw.toString());
} catch (IOException e) {
String msg = "I/O error while writing privilege definition.";
throw new JournalException(msg, e);
} catch (NamespaceException e) {
String msg = "NamespaceException error while writing privilege definition.";
throw new JournalException(msg, e);
}
}
use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter in project jackrabbit by apache.
the class CustomPrivilegeTest method testCustomEquivalentDefinitions.
public void testCustomEquivalentDefinitions() 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");
Name test6 = nf.create(Name.NS_DEFAULT_URI, "test6");
OutputStream out = resource.getOutputStream();
try {
List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
defs.add(new PrivilegeDefinitionImpl(test, false, createNameSet(test2, test3)));
defs.add(new PrivilegeDefinitionImpl(test2, true, Collections.singleton(test4)));
defs.add(new PrivilegeDefinitionImpl(test3, true, Collections.singleton(test5)));
defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.<Name>emptySet()));
defs.add(new PrivilegeDefinitionImpl(test5, true, Collections.<Name>emptySet()));
// the equivalent definition to 'test'
defs.add(new PrivilegeDefinitionImpl(test6, false, createNameSet(test2, test5)));
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("Equivalent definitions must be detected upon registry startup.");
} catch (RepositoryException e) {
// success
} finally {
out.close();
fs.deleteFolder("/privileges");
}
}
use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter 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