use of org.apache.jackrabbit.webdav.security.Privilege in project jackrabbit by apache.
the class JcrUserPrivilegesPropertyTest method testReadOnlyPrivileges.
public void testReadOnlyPrivileges() throws RepositoryException {
Session readOnly = getHelper().getReadOnlySession();
try {
Set<Privilege> expected = getExpected(readOnly.getAccessControlManager(), readOnly);
JcrUserPrivilegesProperty upp = new JcrUserPrivilegesProperty(readOnly, testRoot);
Collection<Privilege> davPrivs = upp.asDavProperty().getValue();
assertEquals(expected.size(), davPrivs.size());
assertTrue(davPrivs.containsAll(expected));
} finally {
if (readOnly != null) {
readOnly.logout();
}
}
}
use of org.apache.jackrabbit.webdav.security.Privilege in project jackrabbit by apache.
the class JcrUserPrivilegesPropertyTest method getExpected.
private Set<Privilege> getExpected(AccessControlManager acMgr, Session s) throws RepositoryException {
Set<Privilege> expected = new HashSet<Privilege>();
for (javax.jcr.security.Privilege p : acMgr.getPrivileges(testRoot)) {
String localName = Text.getLocalName(p.getName());
String prefix = Text.getNamespacePrefix(p.getName());
Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, s.getNamespaceURI(prefix));
expected.add(Privilege.getPrivilege(localName, ns));
}
return expected;
}
use of org.apache.jackrabbit.webdav.security.Privilege 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.Privilege 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.Privilege 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();
}
}
}
Aggregations