use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AbstractWriteTest method testAccessControlRead.
public void testAccessControlRead() throws NotExecutableException, RepositoryException {
AccessControlManager testAcMgr = getTestACManager();
checkReadOnly(path);
// re-grant READ in order to have an ACL-node
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
JackrabbitAccessControlList tmpl = givePrivileges(path, privileges, getRestrictions(superuser, path));
// make sure the 'rep:policy' node has been created.
assertTrue(superuser.itemExists(tmpl.getPath() + "/rep:policy"));
Session testSession = getTestSession();
/*
Testuser must still have READ-only access only and must not be
allowed to view the acl-node that has been created.
*/
assertFalse(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_READ_ACCESS_CONTROL)));
assertFalse(testSession.itemExists(path + "/rep:policy"));
Node n = testSession.getNode(tmpl.getPath());
assertFalse(n.hasNode("rep:policy"));
try {
n.getNode("rep:policy");
fail("Accessing the rep:policy node must throw PathNotFoundException.");
} catch (PathNotFoundException e) {
// ok.
}
/* Finally the test user must not be allowed to remove the policy. */
try {
testAcMgr.removePolicy(path, new AccessControlPolicy() {
});
fail("Test user must not be allowed to remove the access control policy.");
} catch (AccessDeniedException e) {
// success
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AbstractWriteTest method testAccessControlModification.
public void testAccessControlModification() throws RepositoryException, NotExecutableException {
AccessControlManager testAcMgr = getTestACManager();
/* precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
Session testSession = getTestSession();
// give 'testUser' ADD_CHILD_NODES|MODIFY_PROPERTIES| REMOVE_CHILD_NODES privileges at 'path'
Privilege[] privileges = privilegesFromNames(new String[] { Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_REMOVE_CHILD_NODES, Privilege.JCR_MODIFY_PROPERTIES });
JackrabbitAccessControlList tmpl = givePrivileges(path, privileges, getRestrictions(superuser, path));
/*
testuser must not have
- permission to view AC items
- permission to modify AC items
*/
// make sure the 'rep:policy' node has been created.
assertTrue(superuser.itemExists(tmpl.getPath() + "/rep:policy"));
// the policy node however must not be visible to the test-user
assertFalse(testSession.itemExists(tmpl.getPath() + "/rep:policy"));
try {
testAcMgr.getPolicies(tmpl.getPath());
fail("test user must not have READ_AC privilege.");
} catch (AccessDeniedException e) {
// success
}
try {
testAcMgr.getEffectivePolicies(tmpl.getPath());
fail("test user must not have READ_AC privilege.");
} catch (AccessDeniedException e) {
// success
}
try {
testAcMgr.getEffectivePolicies(path);
fail("test user must not have READ_AC privilege.");
} catch (AccessDeniedException e) {
// success
}
try {
testAcMgr.removePolicy(tmpl.getPath(), new AccessControlPolicy() {
});
fail("test user must not have MODIFY_AC privilege.");
} catch (AccessDeniedException e) {
// success
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class JsonDiffHandlerImportTest method assertPolicy.
private static void assertPolicy(AccessControlManager acMgr, Node targetNode, int noACEs) throws RepositoryException {
AccessControlPolicy[] policies = acMgr.getPolicies(targetNode.getPath());
assertEquals(policies.length, 1);
AccessControlPolicy acl = policies[0];
assertTrue(acl instanceof JackrabbitAccessControlList);
AccessControlEntry[] entries = ((JackrabbitAccessControlList) acl).getAccessControlEntries();
assertEquals(noACEs, entries.length);
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AccessControlManagerImpl method getApplicable.
//--------------------------------------------------< private >---
private AccessControlPolicy[] getApplicable(String absPath) throws RepositoryException {
NodeState controlledState;
if (absPath == null) {
controlledState = getRootNodeState();
} else {
controlledState = getNodeState(absPath);
}
AccessControlPolicy acl = null;
NodeState aclNode = getAclNode(controlledState, absPath);
if (aclNode == null) {
acl = new AccessControlListImpl(absPath, npResolver, qvf);
}
return (acl == null) ? new AccessControlPolicy[0] : new AccessControlPolicy[] { acl };
}
use of javax.jcr.security.AccessControlPolicy 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));
}
}
Aggregations