use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeRegistryTest method testJcrAll.
public void testJcrAll() throws RepositoryException {
PrivilegeDefinition p = privilegeRegistry.get(NameConstants.JCR_ALL);
assertEquals(p.getName(), NameConstants.JCR_ALL);
assertFalse(p.getDeclaredAggregateNames().isEmpty());
assertFalse(p.isAbstract());
Set<Name> l = new HashSet<Name>(p.getDeclaredAggregateNames());
assertTrue(l.remove(NameConstants.JCR_READ));
assertTrue(l.remove(NameConstants.JCR_WRITE));
assertTrue(l.remove(resolver.getQName(PrivilegeRegistry.REP_WRITE)));
assertTrue(l.remove(NameConstants.JCR_READ_ACCESS_CONTROL));
assertTrue(l.remove(NameConstants.JCR_MODIFY_ACCESS_CONTROL));
assertTrue(l.remove(NameConstants.JCR_LIFECYCLE_MANAGEMENT));
assertTrue(l.remove(NameConstants.JCR_LOCK_MANAGEMENT));
assertTrue(l.remove(NameConstants.JCR_NODE_TYPE_MANAGEMENT));
assertTrue(l.remove(NameConstants.JCR_RETENTION_MANAGEMENT));
assertTrue(l.remove(NameConstants.JCR_VERSION_MANAGEMENT));
// including repo-level operation privileges
assertTrue(l.remove(NameConstants.JCR_NAMESPACE_MANAGEMENT));
assertTrue(l.remove(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT));
assertTrue(l.remove(NameConstants.JCR_WORKSPACE_MANAGEMENT));
assertTrue(l.remove(resolver.getQName(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT)));
assertTrue(l.isEmpty());
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeRegistryTest method testAggregates.
public void testAggregates() throws RepositoryException {
for (PrivilegeDefinition def : privilegeRegistry.getAll()) {
if (def.getDeclaredAggregateNames().isEmpty()) {
// ignore non aggregate
continue;
}
for (Name n : def.getDeclaredAggregateNames()) {
PrivilegeDefinition d = privilegeRegistry.get(n);
assertNotNull(d);
Name[] names = privilegeRegistry.getNames(privilegeRegistry.getBits(d));
assertNotNull(names);
assertEquals(1, names.length);
assertEquals(d.getName(), names[0]);
}
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class AccessControlProviderImpl method getSupportedPrivileges.
@Override
public Map<String, Privilege> getSupportedPrivileges(SessionInfo sessionInfo, NodeId nodeId, NamePathResolver npResolver) throws RepositoryException {
PrivilegeDefinition[] pDefs = service.getSupportedPrivileges(sessionInfo, nodeId);
Map<String, Privilege> privilegeMap = new HashMap<String, Privilege>(pDefs.length);
for (PrivilegeDefinition def : pDefs) {
Privilege p = new PrivilegeImpl(def, pDefs, npResolver);
privilegeMap.put(p.getName(), p);
}
return privilegeMap;
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeXmlHandler method writeDefinitions.
private void writeDefinitions(Result result, PrivilegeDefinition[] definitions, Map<String, String> namespaces) throws IOException {
try {
Map<String, String> uriToPrefix = new HashMap<String, String>(namespaces.size());
DocumentBuilder builder = createDocumentBuilder();
Document doc = builder.newDocument();
doc.appendChild(doc.createComment(LICENSE_HEADER));
Element privileges = (Element) doc.appendChild(doc.createElement(XML_PRIVILEGES));
for (String prefix : namespaces.keySet()) {
String uri = namespaces.get(prefix);
privileges.setAttribute(ATTR_XMLNS + prefix, uri);
uriToPrefix.put(uri, prefix);
}
for (PrivilegeDefinition def : definitions) {
Element priv = (Element) privileges.appendChild(doc.createElement(XML_PRIVILEGE));
priv.setAttribute(ATTR_NAME, getQualifiedName(def.getName(), uriToPrefix));
priv.setAttribute(ATTR_ABSTRACT, Boolean.valueOf(def.isAbstract()).toString());
for (Name aggrName : def.getDeclaredAggregateNames()) {
Element contains = (Element) priv.appendChild(doc.createElement(XML_CONTAINS));
contains.setAttribute(ATTR_NAME, getQualifiedName(aggrName, uriToPrefix));
}
}
Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
transformer.transform(new DOMSource(doc), result);
} catch (Exception e) {
IOException io = new IOException(e.getMessage());
io.initCause(e);
throw io;
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition 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