use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class ConflictExceptionTest method type.
@Test
public void type() {
ConflictException e = new ConflictException("conflict");
CommitFailedException cfe = e.asCommitFailedException();
assertEquals(CommitFailedException.MERGE, cfe.getType());
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class ConcurrentReadAndAddTest method addNode.
private void addNode(int i) {
try {
NodeBuilder builder = ns.getRoot().builder();
builder.child("test").child("node-" + i);
merge(builder);
} catch (CommitFailedException e) {
exceptions.add(e);
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class PermissionTest method testHasPermission.
@Test
public void testHasPermission() throws Exception {
// create permissions
// allow rep:write /testroot
// allow jcr:removeNode /testroot/a/b
// deny jcr:removeNode /testroot/a/b/c
addEntry(TEST_ROOT_PATH, true, "", PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_WRITE);
addEntry(TEST_B_PATH, true, "", PrivilegeConstants.JCR_REMOVE_NODE);
addEntry(TEST_C_PATH, false, "", PrivilegeConstants.JCR_REMOVE_NODE);
ContentSession testSession = createTestSession();
try {
Root testRoot = testSession.getLatestRoot();
PermissionProvider pp = getPermissionProvider(testSession);
assertIsGranted(pp, testRoot, true, TEST_A_PATH, Permissions.REMOVE_NODE);
assertIsGranted(pp, testRoot, true, TEST_B_PATH, Permissions.REMOVE_NODE);
assertIsGranted(pp, testRoot, false, TEST_C_PATH, Permissions.REMOVE_NODE);
try {
testRoot.getTree(TEST_C_PATH).remove();
testRoot.commit();
fail("removing node on /a/b/c should fail");
} catch (CommitFailedException e) {
// all ok
}
} finally {
testSession.close();
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class ItemNameRestrictionTest method testRemoveTree2.
@Test
public void testRemoveTree2() throws Exception {
AccessControlManager acMgr = getAccessControlManager(root);
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/a");
acl.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_REMOVE_CHILD_NODES), true);
acMgr.setPolicy(acl.getPath(), acl);
root.commit();
Root testRoot = testSession.getLatestRoot();
List<String> paths = ImmutableList.of("/a/d/b/e/c", "/a/d/b");
for (String p : paths) {
testRoot.getTree(p).remove();
testRoot.commit();
}
try {
testRoot.getTree("/a").remove();
testRoot.commit();
fail();
} catch (CommitFailedException e) {
// success
assertTrue(e.isAccessViolation());
} finally {
testRoot.refresh();
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class PermissionTest method testHasPermissionWithRestrictions2.
/**
* Tests if the restrictions are properly inherited.
* the restriction enable/disable the ACE where it is defined.
* since the 'deny' on /a/b is after the 'allow' on a/b/c, the deny wins.
*/
@Test
public void testHasPermissionWithRestrictions2() throws Exception {
// create permissions
// allow rep:write /testroot
// allow jcr:removeNode /testroot/a glob=*/b
// deny jcr:removeNode /testroot/a glob=*/c
addEntry(TEST_ROOT_PATH, true, "", PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_WRITE);
addEntry(TEST_A_PATH, true, "*/b", PrivilegeConstants.JCR_REMOVE_NODE);
addEntry(TEST_A_PATH, false, "*/c", PrivilegeConstants.JCR_REMOVE_NODE);
ContentSession testSession = createTestSession();
try {
Root testRoot = testSession.getLatestRoot();
PermissionProvider pp = getPermissionProvider(testSession);
assertIsGranted(pp, testRoot, true, TEST_A_PATH, Permissions.REMOVE_NODE);
assertIsGranted(pp, testRoot, true, TEST_B_PATH, Permissions.REMOVE_NODE);
assertIsGranted(pp, testRoot, false, TEST_C_PATH, Permissions.REMOVE_NODE);
assertIsGranted(pp, testRoot, true, TEST_D_PATH, Permissions.REMOVE_NODE);
testRoot.getTree(TEST_D_PATH).remove();
testRoot.commit();
try {
// should not be able to remove /a/b/c
testRoot.getTree(TEST_C_PATH).remove();
testRoot.commit();
fail("should not be able to delete " + TEST_C_PATH);
} catch (CommitFailedException e) {
// ok
testRoot.refresh();
}
} finally {
testSession.close();
}
}
Aggregations