use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl 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.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.
the class RepositoryServiceImpl method getPrivilegeDefinitions.
@Override
public PrivilegeDefinition[] getPrivilegeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Session session = sInfo.getSession();
Workspace wsp = session.getWorkspace();
Collection<Privilege> privs;
if (wsp instanceof JackrabbitWorkspace) {
privs = Arrays.asList(((JackrabbitWorkspace) wsp).getPrivilegeManager().getRegisteredPrivileges());
} else {
Privilege jcrAll = session.getAccessControlManager().privilegeFromName(Privilege.JCR_ALL);
privs = new HashSet<Privilege>();
privs.add(jcrAll);
for (Privilege p : jcrAll.getAggregatePrivileges()) {
privs.add(p);
}
}
PrivilegeDefinition[] pDefs = new PrivilegeDefinition[privs.size()];
NamePathResolver npResolver = sInfo.getNamePathResolver();
int i = 0;
for (Privilege p : privs) {
Set<Name> aggrnames = null;
if (p.isAggregate()) {
aggrnames = new HashSet<Name>();
for (Privilege dap : p.getDeclaredAggregatePrivileges()) {
aggrnames.add(npResolver.getQName(dap.getName()));
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(npResolver.getQName(p.getName()), p.isAbstract(), aggrnames);
pDefs[i++] = def;
}
return pDefs;
}
Aggregations