use of org.apache.jackrabbit.webdav.security.Privilege in project jackrabbit by apache.
the class RepositoryServiceImpl method fillSupportedPrivilegeMap.
private static void fillSupportedPrivilegeMap(List<SupportedPrivilege> sps, Map<Name, SupportedPrivilege> spMap, NameFactory nameFactory) throws NamespaceException, IllegalNameException {
for (SupportedPrivilege sp : sps) {
Privilege p = sp.getPrivilege();
Name privName = nameFactory.create(p.getNamespace().getURI(), p.getName());
spMap.put(privName, sp);
List<SupportedPrivilege> agg = Arrays.asList(sp.getSupportedPrivileges());
if (!agg.isEmpty()) {
fillSupportedPrivilegeMap(agg, spMap, nameFactory);
}
}
}
use of org.apache.jackrabbit.webdav.security.Privilege 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();
}
}
}
Aggregations