use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class AccessControlManagerImplTest method testAddingFourAccessControlEntries.
/**
* Add an AccessControlList with four entries. This will result in having the result in:
* Transient-space: An ACL node that has four child-nodes.
* Persistent-state: An ACL node that has one child-node.
* NOTE: That Jackrabbit-core tries to internally merge the entries that belongs to the same
* principal, which is not the case for the client-side ACM implementation.
*/
public void testAddingFourAccessControlEntries() throws Exception {
try {
AccessControlList acl = (AccessControlList) getACL(testRoot);
// check precondition,see JCR-3995
if (testRootNode.hasNode("rep:policy")) {
assertEquals("should not have any ace nodes at this point", 0, testRootNode.getNode("rep:policy").getNodes().getSize());
}
acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
acl.addAccessControlEntry(getUnknownPrincipal(), privilegesFromName(Privilege.JCR_READ));
acMgr.setPolicy(testRoot, acl);
// Transient-space: Must contain FOUR ace nodes.
assertEquals(4, testRootNode.getNode("rep:policy").getNodes().getSize());
superuser.save();
// Persistent-state: Must contain a single ace node -> entries were
// merged
assertEquals(1, testRootNode.getNode("rep:policy").getNodes().getSize());
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlList in project jackrabbit by apache.
the class ConcurrentReadAccessControlledTreeTest method beforeSuite.
@Override
protected void beforeSuite() throws Exception {
super.beforeSuite();
ItemVisitor visitor = new TraversingItemVisitor.Default() {
int counter = 0;
@Override
protected void entering(Node node, int level) throws RepositoryException {
if (++counter == 10) {
addPolicy(node);
counter = 0;
}
super.entering(node, level);
}
private void addPolicy(Node node) throws RepositoryException {
AccessControlManager acMgr = node.getSession().getAccessControlManager();
String path = node.getPath();
AccessControlPolicyIterator acIterator = acMgr.getApplicablePolicies(path);
if (acIterator.hasNext()) {
AccessControlPolicy policy = acIterator.nextAccessControlPolicy();
if (policy instanceof AccessControlList) {
AccessControlList acl = (AccessControlList) policy;
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
acMgr.setPolicy(path, acl);
node.getSession().save();
}
}
}
}
};
visitor.visit(testRoot);
for (int i = 0; i < bgReaders; i++) {
addBackgroundJob(new RandomRead(loginReader(), false));
}
}
use of javax.jcr.security.AccessControlList in project kylo by Teradata.
the class JcrAccessControlUtil method getAccessControlList.
private static AccessControlList getAccessControlList(String path, AccessControlManager acm) throws PathNotFoundException, AccessDeniedException, RepositoryException {
AccessControlList acl = null;
AccessControlPolicyIterator it = acm.getApplicablePolicies(path);
if (it.hasNext()) {
acl = (AccessControlList) it.nextAccessControlPolicy();
} else {
acl = (AccessControlList) acm.getPolicies(path)[0];
}
return acl;
}
use of javax.jcr.security.AccessControlList in project kylo by Teradata.
the class JcrAccessControlUtil method getPrivileges.
public static Set<Privilege> getPrivileges(Session session, Principal principal, String path) {
try {
AccessControlManager acm = session.getAccessControlManager();
AccessControlList acl = getAccessControlList(path, acm);
for (AccessControlEntry entry : acl.getAccessControlEntries()) {
if (matchesPrincipal(principal, entry)) {
return new HashSet<>(Arrays.asList(entry.getPrivileges()));
}
}
return Collections.emptySet();
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to get the privileges for node " + path, e);
}
}
use of javax.jcr.security.AccessControlList in project kylo by Teradata.
the class JcrAccessControlUtil method updatePermissions.
private static boolean updatePermissions(Session session, String path, Principal principal, boolean replace, Privilege... privileges) {
try {
AccessControlManager acm = session.getAccessControlManager();
AccessControlList acl = getAccessControlList(path, acm);
boolean changed = false;
if (replace) {
changed |= removeEntry(acl, principal);
}
if (privileges.length > 0) {
changed |= addEntry(session, acl, principal, privileges);
}
acm.setPolicy(path, acl);
return changed;
} catch (AccessDeniedException e) {
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to add permission(s) to node " + path + ": " + Arrays.toString(privileges), e);
}
}
Aggregations