use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeXmlHandler method readDefinitions.
private PrivilegeDefinition[] readDefinitions(InputSource input, Map<String, String> namespaces) throws ParseException {
try {
List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
DocumentBuilder builder = createDocumentBuilder();
Document doc = builder.parse(input);
Element root = doc.getDocumentElement();
if (!XML_PRIVILEGES.equals(root.getNodeName())) {
throw new IllegalArgumentException("root element must be named 'privileges'");
}
updateNamespaceMapping(root, namespaces);
NodeList nl = root.getElementsByTagName(XML_PRIVILEGE);
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
PrivilegeDefinition def = parseDefinition(n, namespaces);
if (def != null) {
defs.add(def);
}
}
return defs.toArray(new PrivilegeDefinition[defs.size()]);
} catch (SAXException e) {
throw new ParseException(e);
} catch (IOException e) {
throw new ParseException(e);
} catch (ParserConfigurationException e) {
throw new ParseException(e);
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class AbstractRecord method readPrivilegeDef.
/**
* {@inheritDoc}
*/
public PrivilegeDefinition readPrivilegeDef() throws JournalException {
try {
StringReader sr = new StringReader(readString());
PrivilegeDefinitionReader reader = new PrivilegeDefinitionReader(sr, "text/xml");
PrivilegeDefinition[] defs = reader.getPrivilegeDefinitions();
if (defs.length != 1) {
throw new JournalException("Expected one privilege definition: got " + defs.length);
}
return defs[0];
} catch (org.apache.jackrabbit.spi.commons.privilege.ParseException e) {
String msg = "Parse error while reading privilege definition.";
throw new JournalException(msg, e);
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeRegistryTest method testGet.
public void testGet() throws RepositoryException {
for (PrivilegeDefinition def : privilegeRegistry.getAll()) {
PrivilegeDefinition d = privilegeRegistry.get(def.getName());
assertEquals(def, d);
assertNotNull(d.getName());
assertEquals(def.getName(), d.getName());
assertFalse(d.isAbstract());
assertEquals(def.isAbstract(), d.isAbstract());
assertNotNull(d.getDeclaredAggregateNames());
assertTrue(def.getDeclaredAggregateNames().containsAll(d.getDeclaredAggregateNames()));
assertTrue(d.getDeclaredAggregateNames().containsAll(def.getDeclaredAggregateNames()));
assertFalse(privilegeRegistry.getBits(d).isEmpty());
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class PrivilegeRegistryTest method testPrivilegeDefinition.
public void testPrivilegeDefinition() throws RepositoryException {
for (PrivilegeDefinition def : privilegeRegistry.getAll()) {
assertNotNull(def.getName());
assertFalse(def.isAbstract());
assertNotNull(def.getDeclaredAggregateNames());
assertFalse(privilegeRegistry.getBits(def).isEmpty());
}
}
use of org.apache.jackrabbit.spi.PrivilegeDefinition in project jackrabbit by apache.
the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.
private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new PrivilegeDefinition[0];
} else {
// build PrivilegeDefinition(s) from the supported-privileges dav property
Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
for (Name privilegeName : spMap.keySet()) {
SupportedPrivilege sp = spMap.get(privilegeName);
Set<Name> aggrnames = null;
SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
if (aggregates != null && aggregates.length > 0) {
aggrnames = new HashSet<Name>();
for (SupportedPrivilege aggregate : aggregates) {
Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
aggrnames.add(aggregateName);
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
pDefs.add(def);
}
return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations