use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractWriteTest method testCancelInheritanceRestriction.
/**
* Test the rep:glob restriction
*
* @throws Exception
*/
public void testCancelInheritanceRestriction() throws Exception {
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
ValueFactory vf = superuser.getValueFactory();
/*
precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
checkReadOnly(childNPath);
Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue(""));
givePrivileges(path, write, restrictions);
assertTrue(testAcMgr.hasPrivileges(path, write));
assertTrue(testSession.hasPermission(path, Session.ACTION_SET_PROPERTY));
assertFalse(testAcMgr.hasPrivileges(childNPath, write));
assertFalse(testSession.hasPermission(childNPath, Session.ACTION_SET_PROPERTY));
assertFalse(testAcMgr.hasPrivileges(childNPath2, write));
assertFalse(testSession.hasPermission(childNPath2, Session.ACTION_SET_PROPERTY));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractWriteTest method testGlobRestriction.
/**
* Test the rep:glob restriction
*
* @throws Exception
*/
public void testGlobRestriction() throws Exception {
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
ValueFactory vf = superuser.getValueFactory();
/*
precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
checkReadOnly(childNPath);
Node child = superuser.getNode(childNPath).addNode(nodeName3);
superuser.save();
String childchildPath = child.getPath();
Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
String writeActions = Session.ACTION_ADD_NODE + "," + Session.ACTION_REMOVE + "," + Session.ACTION_SET_PROPERTY;
// permissions defined @ path
// restriction: grants write priv to all nodeName3 children
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*" + nodeName3));
givePrivileges(path, write, restrictions);
assertFalse(testAcMgr.hasPrivileges(path, write));
assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_SET_PROPERTY));
assertFalse(testAcMgr.hasPrivileges(childNPath, write));
assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_SET_PROPERTY));
assertTrue(testAcMgr.hasPrivileges(childNPath2, write));
assertTrue(testSession.hasPermission(childNPath2, Session.ACTION_SET_PROPERTY));
// removal req. rmchildnode privilege on parent.
assertFalse(testSession.hasPermission(childNPath2, writeActions));
assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractWriteTest method testGlobRestriction2.
/**
* Test the rep:glob restriction
*
* @throws Exception
*/
public void testGlobRestriction2() throws Exception {
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
ValueFactory vf = superuser.getValueFactory();
/*
precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
checkReadOnly(childNPath);
Node child = superuser.getNode(childNPath).addNode(nodeName3);
superuser.save();
String childchildPath = child.getPath();
Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
Privilege[] rmNode = privilegesFromName(Privilege.JCR_REMOVE_NODE);
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
// permissions defined @ path
// restriction: grants write-priv to nodeName3 grand-children but not direct nodeName3 children.
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*/" + nodeName3));
givePrivileges(path, write, restrictions);
assertFalse(testAcMgr.hasPrivileges(path, write));
assertFalse(testAcMgr.hasPrivileges(path, rmNode));
assertFalse(testAcMgr.hasPrivileges(childNPath, addNode));
assertFalse(testAcMgr.hasPrivileges(childNPath2, write));
assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractWriteTest method testGlobRestriction4.
/**
* Test the rep:glob restriction
*
* @throws Exception
*/
public void testGlobRestriction4() throws Exception {
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
ValueFactory vf = superuser.getValueFactory();
/*
precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
checkReadOnly(childNPath);
Node child = superuser.getNode(childNPath).addNode(nodeName3);
superuser.save();
String childchildPath = child.getPath();
Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*" + nodeName3));
givePrivileges(path, write, restrictions);
withdrawPrivileges(childNPath2, addNode, getRestrictions(superuser, childNPath2));
assertFalse(testAcMgr.hasPrivileges(path, write));
assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_REMOVE));
assertFalse(testAcMgr.hasPrivileges(childNPath, write));
assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_REMOVE));
assertFalse(testAcMgr.hasPrivileges(childNPath2, write));
assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractWriteTest method testGlobRestriction3.
/**
* Test the rep:glob restriction
*
* @throws Exception
*/
public void testGlobRestriction3() throws Exception {
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
ValueFactory vf = superuser.getValueFactory();
/*
precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
checkReadOnly(childNPath);
Node child = superuser.getNode(childNPath).addNode(nodeName3);
superuser.save();
String childchildPath = child.getPath();
Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
String writeActions = Session.ACTION_ADD_NODE + "," + Session.ACTION_REMOVE + "," + Session.ACTION_SET_PROPERTY;
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
// permissions defined @ path
// restriction: allows write to nodeName3 children
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*/" + nodeName3));
givePrivileges(path, write, restrictions);
// and grant add-node only at path (no glob restriction)
givePrivileges(path, addNode, getRestrictions(superuser, path));
assertFalse(testAcMgr.hasPrivileges(path, write));
assertTrue(testAcMgr.hasPrivileges(path, addNode));
assertFalse(testAcMgr.hasPrivileges(childNPath, write));
assertTrue(testAcMgr.hasPrivileges(childNPath, addNode));
assertFalse(testAcMgr.hasPrivileges(childNPath2, write));
assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
}
Aggregations