use of org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty in project jackrabbit by apache.
the class JcrUserPrivilegesProperty method asDavProperty.
public CurrentUserPrivilegeSetProperty asDavProperty() throws RepositoryException {
List<Privilege> davPrivs = new ArrayList<Privilege>();
for (javax.jcr.security.Privilege privilege : session.getAccessControlManager().getPrivileges(absPath)) {
String privilegeName = privilege.getName();
String prefix = Text.getNamespacePrefix(privilegeName);
Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, session.getNamespaceURI(prefix));
davPrivs.add(Privilege.getPrivilege(Text.getLocalName(privilegeName), ns));
}
return new CurrentUserPrivilegeSetProperty(davPrivs.toArray(new Privilege[davPrivs.size()]));
}
use of org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty in project jackrabbit by apache.
the class JcrPrivilegeReport method addResponses.
private void addResponses(DavResourceLocator locator) {
String repositoryPath = locator.getRepositoryPath();
MultiStatusResponse resp = new MultiStatusResponse(locator.getHref(false), null);
List<Privilege> currentPrivs = new ArrayList<Privilege>();
for (Privilege priv : PRIVS) {
try {
if (getRepositorySession().hasPermission(repositoryPath, priv.getName())) {
currentPrivs.add(priv);
}
} catch (RepositoryException e) {
// ignore
log.debug(e.toString());
}
}
resp.add(new CurrentUserPrivilegeSetProperty(currentPrivs.toArray(new Privilege[currentPrivs.size()])));
ms.addResponse(resp);
}
use of org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty 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.security.CurrentUserPrivilegeSetProperty 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