use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeHandlerTest method testReadInputStream.
public void testReadInputStream() throws Exception {
InputStream in = getClass().getResourceAsStream("readtest.xml");
PrivilegeDefinitionReader reader = new PrivilegeDefinitionReader(in, CONTENT_TYPE);
Map<Name, PrivilegeDefinition> defs = new HashMap<Name, PrivilegeDefinition>();
for (PrivilegeDefinition def : reader.getPrivilegeDefinitions()) {
defs.put(def.getName(), def);
}
for (PrivilegeDefinition def : DEF_EXPECTED) {
PrivilegeDefinition e = defs.remove(def.getName());
assertNotNull("Definition " + def.getName() + " missing");
assertEquals("Definition mismatch.", def, e);
}
assertTrue("Not all definitions present", defs.isEmpty());
// check for namespace
String fooUri = reader.getNamespaces().get(TEST_PREFIX);
assertEquals("Namespace included", TEST_URI, fooUri);
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition 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");
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class CustomPrivilegeTest method testRegister100CustomPrivileges.
public void testRegister100CustomPrivileges() throws RepositoryException, FileSystemException {
PrivilegeBits previous = privilegeRegistry.getBits(privilegeRegistry.get(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME)).unmodifiable();
for (int i = 0; i < 100; i++) {
boolean isAbstract = true;
Name name = ((SessionImpl) superuser).getQName("test" + i);
privilegeRegistry.registerDefinition(name, isAbstract, Collections.<Name>emptySet());
PrivilegeDefinition definition = privilegeRegistry.get(name);
assertNotNull(definition);
assertEquals(name, definition.getName());
PrivilegeBits modifiable = privilegeRegistry.getBits(definition);
PrivilegeBits bits = modifiable.unmodifiable();
assertNotNull(bits);
assertFalse(bits.isEmpty());
assertEquals(modifiable, bits);
assertFalse(previous.equals(bits));
assertEquals(previous.nextBits(), bits);
PrivilegeDefinition all = privilegeRegistry.get(NameConstants.JCR_ALL);
assertTrue(all.getDeclaredAggregateNames().contains(name));
assertTrue(privilegeRegistry.getBits(all).includes(bits));
previous = bits;
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeRegistryTest method testRepWrite.
public void testRepWrite() throws RepositoryException {
PrivilegeDefinition p = privilegeRegistry.get(NameConstants.JCR_WRITE);
assertEquals(p.getName(), NameConstants.JCR_WRITE);
assertFalse(p.getDeclaredAggregateNames().isEmpty());
assertFalse(p.isAbstract());
Set<Name> l = new HashSet<Name>(p.getDeclaredAggregateNames());
assertTrue(l.remove(NameConstants.JCR_MODIFY_PROPERTIES));
assertTrue(l.remove(NameConstants.JCR_ADD_CHILD_NODES));
assertTrue(l.remove(NameConstants.JCR_REMOVE_CHILD_NODES));
assertTrue(l.remove(NameConstants.JCR_REMOVE_NODE));
assertTrue(l.isEmpty());
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeRegistryTest method testJcrWrite.
public void testJcrWrite() throws RepositoryException {
Name rw = resolver.getQName(PrivilegeRegistry.REP_WRITE);
PrivilegeDefinition p = privilegeRegistry.get(rw);
assertEquals(p.getName(), rw);
assertFalse(p.getDeclaredAggregateNames().isEmpty());
assertFalse(p.isAbstract());
Set<Name> l = new HashSet<Name>(p.getDeclaredAggregateNames());
assertTrue(l.remove(NameConstants.JCR_WRITE));
assertTrue(l.remove(NameConstants.JCR_NODE_TYPE_MANAGEMENT));
assertTrue(l.isEmpty());
}
Aggregations