use of org.apache.jackrabbit.webdav.client.methods.HttpPropfind 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();
}
}
}
use of org.apache.jackrabbit.webdav.client.methods.HttpPropfind in project jackrabbit by apache.
the class RepositoryServiceImpl method getChildInfos.
@Override
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(DavPropertyName.RESOURCETYPE);
HttpPropfind request = null;
try {
String uri = getItemUri(parentId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_1);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
List<ChildInfo> childEntries;
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(parentId, sessionInfo));
} else if (mresponses.length == 1) {
// no child nodes nor properties
childEntries = Collections.emptyList();
return childEntries.iterator();
}
childEntries = new ArrayList<ChildInfo>();
for (MultiStatusResponse mresponse : mresponses) {
if (!isSameResource(uri, mresponse)) {
DavPropertySet childProps = mresponse.getProperties(DavServletResponse.SC_OK);
if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
childEntries.add(buildChildInfo(childProps, sessionInfo));
}
// else: property -> ignore
}
// else: ignore the response related to the parent
}
return childEntries.iterator();
} 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.client.methods.HttpPropfind in project jackrabbit by apache.
the class RepositoryServiceImpl method loadType.
private int loadType(String propertyURI, HttpClient client, PropertyId propertyId, SessionInfo sessionInfo, NamePathResolver resolver) throws IOException, DavException, RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(propertyURI, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length == 1) {
DavPropertySet props = mresponses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
if (type != null) {
return PropertyType.valueFromName(type.getValue().toString());
} else {
throw new RepositoryException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} else {
throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.client.methods.HttpPropfind in project jackrabbit by apache.
the class RepositoryServiceImpl method getLockInfo.
@Override
public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
// set of Dav-properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DavPropertyName.LOCKDISCOVERY);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_0);
initMethod(request, sessionInfo, false);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length != 1) {
throw new ItemNotFoundException("Unable to retrieve the LockInfo. No such node " + saveGetIdString(nodeId, sessionInfo));
}
DavPropertySet ps = mresponses[0].getProperties(DavServletResponse.SC_OK);
if (ps.contains(DavPropertyName.LOCKDISCOVERY)) {
DavProperty<?> p = ps.get(DavPropertyName.LOCKDISCOVERY);
LockDiscovery ld = LockDiscovery.createFromXml(p.toXml(DomUtil.createDocument()));
NodeId parentId = getParentId(uri, ps, sessionInfo);
return retrieveLockInfo(ld, sessionInfo, nodeId, parentId);
} else {
// no lock present
log.debug("No Lock present on node with id " + saveGetIdString(nodeId, sessionInfo));
return null;
}
} 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.client.methods.HttpPropfind 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;
}
Aggregations