use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class VersionControlledItemCollection method merge.
/**
* Merge the repository node represented by this resource according to the
* information present in the given {@link MergeInfo} object.
*
* @param mergeInfo
* @return <code>MultiStatus</code> recording all repository items modified
* by this merge call as well as the resources that a client must modify to
* complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
* @see Node#merge(String, boolean)
*/
//TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
if (mergeInfo == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatus ms = new MultiStatus();
try {
// NOTE: RFC requires that all modified resources are reported in the
// multistatus response. this doesn't work however with the remoting
// there is no way to distinguish the 'failedId's from any other
// resources that got modified by this merge operation -> omitted.
// todo: RFC allows multiple href elements inside the DAV:source element
String workspaceName = getLocatorFromHref(mergeInfo.getSourceHrefs()[0]).getWorkspaceName();
String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
boolean isShallow = "0".equals(depth);
NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
// add resources to the multistatus, that failed to be merged
while (failed.hasNext()) {
Node failedNode = failed.nextNode();
DavResourceLocator loc = getLocatorFromItem(failedNode);
DavResource res = createResourceFromLocator(loc);
ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
return ms;
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse 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.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method obtain.
private SessionInfo obtain(CredentialsWrapper credentials, String workspaceName) throws RepositoryException {
// check if the workspace with the given name is accessible
HttpPropfind request = null;
SessionInfoImpl sessionInfo = new SessionInfoImpl(credentials, workspaceName);
try {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
// for backwards compat. -> retrieve DAV:workspace if the newly
// added property (workspaceName) is not supported by the server.
nameSet.add(DeltaVConstants.WORKSPACE);
nameSet.add(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
request = new HttpPropfind(uriResolver.getWorkspaceUri(workspaceName), nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (responses.length != 1) {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
}
DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> prop = props.get(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
if (prop != null) {
String wspName = prop.getValue().toString();
if (workspaceName == null) {
// login with 'null' workspace name -> retrieve the effective
// workspace name from the property and recreate the SessionInfo.
sessionInfo = new SessionInfoImpl(credentials, wspName);
} else if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name '" + workspaceName + "'.");
}
} else if (props.contains(DeltaVConstants.WORKSPACE)) {
String wspHref = new HrefProperty(props.get(DeltaVConstants.WORKSPACE)).getHrefs().get(0);
String wspName = Text.unescape(Text.getName(wspHref, true));
if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name " + workspaceName);
}
} else {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
}
} catch (IOException e) {
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
// mappings.
if (nsCache.prefixToURI.isEmpty()) {
try {
getRegisteredNamespaces(sessionInfo);
} catch (RepositoryException e) {
// ignore
}
}
// return the sessionInfo
return sessionInfo;
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method getPrivilegeNames.
@Override
public Name[] getPrivilegeNames(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
String uri = (nodeId == null) ? uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()) : getItemUri(nodeId, sessionInfo);
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
HttpPropfind propfindRequest = null;
try {
propfindRequest = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = execute(propfindRequest, sessionInfo);
propfindRequest.checkSuccess(response);
MultiStatusResponse[] mresponses = propfindRequest.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.CURRENT_USER_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new Name[0];
} else {
Collection<Privilege> privs = new CurrentUserPrivilegeSetProperty(p).getValue();
Set<Name> privNames = new HashSet<Name>(privs.size());
for (Privilege priv : privs) {
privNames.add(nameFactory.create(priv.getNamespace().getURI(), priv.getName()));
}
return privNames.toArray(new Name[privNames.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (propfindRequest != null) {
propfindRequest.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method getWorkspaceNames.
@Override
public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DeltaVConstants.WORKSPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(uriResolver.getRepositoryUri(), nameSet, DEPTH_1);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
Set<String> wspNames = new HashSet<String>();
for (MultiStatusResponse mresponse : mresponses) {
DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
if (props.contains(DeltaVConstants.WORKSPACE)) {
HrefProperty hp = new HrefProperty(props.get(DeltaVConstants.WORKSPACE));
String wspHref = hp.getHrefs().get(0);
String name = Text.unescape(Text.getName(wspHref, true));
wspNames.add(name);
}
}
return wspNames.toArray(new String[wspNames.size()]);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations