use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class URIResolverImpl method getItemUri.
String getItemUri(ItemId itemId, String workspaceName, SessionInfo sessionInfo) throws RepositoryException {
IdURICache cache = getCache(workspaceName);
// check if uri is available from cache
if (cache.containsItemId(itemId)) {
return cache.getUri(itemId);
} else {
StringBuffer uriBuffer = new StringBuffer();
Path path = itemId.getPath();
String uniqueID = itemId.getUniqueID();
// resolver uuid part
if (uniqueID != null) {
ItemId uuidId = (path == null) ? itemId : service.getIdFactory().createNodeId(uniqueID);
if (path != null && cache.containsItemId(uuidId)) {
// append uri of parent node, that is already cached
uriBuffer.append(cache.getUri(uuidId));
} else {
// try to request locate-by-uuid report to build the uri
ReportInfo rInfo = new ReportInfo(JcrRemotingConstants.REPORT_LOCATE_BY_UUID, ItemResourceConstants.NAMESPACE);
rInfo.setContentElement(DomUtil.hrefToXml(uniqueID, domFactory));
HttpReport request = null;
try {
String wspUri = getWorkspaceUri(workspaceName);
request = new HttpReport(wspUri, rInfo);
HttpResponse response = service.executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatus ms = request.getResponseBodyAsMultiStatus(response);
if (ms.getResponses().length == 1) {
String absoluteUri = resolve(wspUri, ms.getResponses()[0].getHref());
uriBuffer.append(absoluteUri);
cache.add(absoluteUri, uuidId);
} else {
throw new ItemNotFoundException("Cannot identify item with uniqueID " + uniqueID);
}
} catch (IOException e) {
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
} else {
// start build uri from root-item
uriBuffer.append(getRootItemUri(workspaceName));
}
// resolve relative-path part unless it denotes the root-item
if (path != null && !path.denotesRoot()) {
String jcrPath = service.getNamePathResolver(sessionInfo).getJCRPath(path);
if (!path.isAbsolute() && !uriBuffer.toString().endsWith("/")) {
uriBuffer.append("/");
}
uriBuffer.append(Text.escapePath(jcrPath));
}
String itemUri = uriBuffer.toString();
if (!cache.containsItemId(itemId)) {
cache.add(itemUri, itemId);
}
return itemUri;
}
}
use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method getRegisteredNamespaces.
@Override
public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REGISTERED_NAMESPACES, ItemResourceConstants.NAMESPACE);
HttpReport request = null;
try {
request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), info);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
Document doc = request.getResponseBodyAsDocument(response.getEntity());
Map<String, String> namespaces = new HashMap<String, String>();
if (doc != null) {
Element rootElement = doc.getDocumentElement();
ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_NAMESPACE, ItemResourceConstants.NAMESPACE);
while (nsElems.hasNext()) {
Element elem = nsElems.nextElement();
String prefix = DomUtil.getChildText(elem, JcrRemotingConstants.XML_PREFIX, ItemResourceConstants.NAMESPACE);
String uri = DomUtil.getChildText(elem, JcrRemotingConstants.XML_URI, ItemResourceConstants.NAMESPACE);
// default namespace
if (prefix == null && uri == null) {
prefix = uri = "";
}
// any other uri must not be null
if (uri != null) {
namespaces.put(prefix, uri);
// TODO: not correct since nsRegistry is retrieved from each session
nsCache.add(prefix, uri);
} else {
log.error("Invalid prefix / uri pair: " + prefix + " -> " + uri);
}
}
}
return namespaces;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class WebdavRequestImpl method getReportInfo.
/**
* @see org.apache.jackrabbit.webdav.version.DeltaVServletRequest#getReportInfo()
*/
public ReportInfo getReportInfo() throws DavException {
ReportInfo rInfo = null;
Document requestDocument = getRequestDocument();
if (requestDocument != null) {
rInfo = new ReportInfo(requestDocument.getDocumentElement(), getDepth(DEPTH_0));
}
return rInfo;
}
use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method isGranted.
@Override
public boolean isGranted(SessionInfo sessionInfo, ItemId itemId, String[] actions) throws RepositoryException {
HttpReport request = null;
try {
String uri = obtainAbsolutePathFromUri(getItemUri(itemId, sessionInfo));
ReportInfo reportInfo = new ReportInfo(JcrRemotingConstants.REPORT_PRIVILEGES, ItemResourceConstants.NAMESPACE);
reportInfo.setContentElement(DomUtil.hrefToXml(uri, DomUtil.createDocument()));
request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), reportInfo);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (responses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve permissions for item " + saveGetIdString(itemId, sessionInfo));
}
DavProperty<?> p = responses[0].getProperties(DavServletResponse.SC_OK).get(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
if (p == null) {
return false;
}
// build set of privileges from given actions. NOTE: since the actions
// have no qualifying namespace, the {@link ItemResourceConstants#NAMESPACE}
// is used.
Set<Privilege> requiredPrivileges = new HashSet<Privilege>();
for (String action : actions) {
requiredPrivileges.add(Privilege.getPrivilege(action, ItemResourceConstants.NAMESPACE));
}
// build set of privileges granted to the current user.
CurrentUserPrivilegeSetProperty privSet = new CurrentUserPrivilegeSetProperty(p);
Collection<Privilege> privileges = privSet.getValue();
// check privileges present against required privileges.
return privileges.containsAll(requiredPrivileges);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (ParserConfigurationException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method getRepositoryDescriptors.
@Override
public Map<String, QValue[]> getRepositoryDescriptors() throws RepositoryException {
if (descriptors.isEmpty()) {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REPOSITORY_DESCRIPTORS, ItemResourceConstants.NAMESPACE);
HttpReport request = null;
try {
request = new HttpReport(uriResolver.getRepositoryUri(), info);
HttpResponse response = executeRequest(null, request);
int sc = response.getStatusLine().getStatusCode();
if (sc == HttpStatus.SC_UNAUTHORIZED || sc == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
// JCR-3076: Mandatory authentication prevents us from
// accessing the descriptors on the server, so instead
// of failing with an exception we simply return an empty
// set of descriptors
log.warn("Authentication required to access repository descriptors");
return descriptors;
}
request.checkSuccess(response);
Document doc = request.getResponseBodyAsDocument(response.getEntity());
if (doc != null) {
Element rootElement = doc.getDocumentElement();
ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_DESCRIPTOR, ItemResourceConstants.NAMESPACE);
while (nsElems.hasNext()) {
Element elem = nsElems.nextElement();
String key = DomUtil.getChildText(elem, JcrRemotingConstants.XML_DESCRIPTORKEY, ItemResourceConstants.NAMESPACE);
ElementIterator it = DomUtil.getChildren(elem, JcrRemotingConstants.XML_DESCRIPTORVALUE, ItemResourceConstants.NAMESPACE);
List<QValue> vs = new ArrayList<QValue>();
while (it.hasNext()) {
Element dv = it.nextElement();
String descriptor = DomUtil.getText(dv);
if (key != null && descriptor != null) {
String typeStr = (DomUtil.getAttribute(dv, JcrRemotingConstants.ATTR_VALUE_TYPE, null));
int type = (typeStr == null) ? PropertyType.STRING : PropertyType.valueFromName(typeStr);
vs.add(getQValueFactory().create(descriptor, type));
} else {
log.error("Invalid descriptor key / value pair: " + key + " -> " + descriptor);
}
}
descriptors.put(key, vs.toArray(new QValue[vs.size()]));
}
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
return descriptors;
}
Aggregations