use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AccessControlImporterTest method testImportWithDefaultImporter.
/**
* With the default importer that isn't able to deal with ACEs the
* policy will be created but any ACEs will be ignored.
*
* @throws Exception
*/
public void testImportWithDefaultImporter() throws Exception {
NodeImpl target = (NodeImpl) testRootNode;
try {
InputStream in = new ByteArrayInputStream(XML_POLICY_TREE.getBytes("UTF-8"));
SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, null);
ImportHandler ih = new ImportHandler(importer, sImpl);
new ParsingContentHandler(ih).parse(in);
assertTrue(target.hasNode("test"));
String path = target.getNode("test").getPath();
AccessControlManager acMgr = sImpl.getAccessControlManager();
AccessControlPolicy[] policies = acMgr.getPolicies(path);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof JackrabbitAccessControlList);
AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
assertEquals(0, entries.length);
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class ConcurrentReadSinglePolicyTreeTest method visitingNode.
@Override
protected void visitingNode(Node node, int i) throws RepositoryException {
super.visitingNode(node, i);
String path = node.getPath();
AccessControlManager acMgr = node.getSession().getAccessControlManager();
if (testRoot.getPath().equals(path)) {
JackrabbitAccessControlList policy = AccessControlUtils.getAccessControlList(acMgr, path);
if (policy != null) {
policy.addEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ), true);
}
acMgr.setPolicy(path, policy);
} else if (!path.contains("rep:policy")) {
for (AccessControlPolicy policy : acMgr.getPolicies(path)) {
if (policy instanceof JackrabbitAccessControlList) {
acMgr.removePolicy(path, policy);
}
}
}
node.getSession().save();
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class ReadPolicyTest method testGetEffectivePolicies.
@Test
public void testGetEffectivePolicies() throws Exception {
for (String path : readPaths) {
AccessControlPolicy[] policies = getAccessControlManager(root).getEffectivePolicies(path);
assertTrue(policies.length > 0);
boolean found = false;
for (AccessControlPolicy policy : policies) {
if ("org.apache.jackrabbit.oak.security.authorization.accesscontrol.AccessControlManagerImpl$ReadPolicy".equals(policy.getClass().getName())) {
found = true;
break;
}
}
assertTrue(found);
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class ReadPolicyTest method testGetPolicies.
@Test
public void testGetPolicies() throws Exception {
for (String path : readPaths) {
AccessControlPolicy[] policies = getAccessControlManager(root).getPolicies(path);
assertTrue(policies.length > 0);
boolean found = false;
for (AccessControlPolicy policy : policies) {
if ("org.apache.jackrabbit.oak.security.authorization.accesscontrol.AccessControlManagerImpl$ReadPolicy".equals(policy.getClass().getName())) {
found = true;
break;
}
}
assertTrue(found);
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit by apache.
the class AcReadWriteTest method testSetNewPolicy.
/**
* Test if a new applicable policy can be applied within a individual
* subtree where AC-modification is allowed.
*
* @throws RepositoryException
* @throws NotExecutableException
* @see <a href="https://issues.apache.org/jira/browse/JCR-2869">JCR-2869</a>
*/
public void testSetNewPolicy() throws RepositoryException, NotExecutableException {
/* precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
/* grant 'testUser' rep:write, rep:readAccessControl and
rep:modifyAccessControl privileges at 'path' */
Privilege[] privileges = privilegesFromNames(new String[] { PrivilegeRegistry.REP_WRITE, Privilege.JCR_READ_ACCESS_CONTROL, Privilege.JCR_MODIFY_ACCESS_CONTROL });
JackrabbitAccessControlList tmpl = givePrivileges(path, privileges, getRestrictions(superuser, path));
AccessControlManager testAcMgr = getTestACManager();
/*
testuser must be allowed to set a new policy at a child node.
*/
AccessControlPolicyIterator it = testAcMgr.getApplicablePolicies(childNPath);
while (it.hasNext()) {
AccessControlPolicy plc = it.nextAccessControlPolicy();
testAcMgr.setPolicy(childNPath, plc);
testAcMgr.removePolicy(childNPath, plc);
}
}
Aggregations