use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class MoveTest method testMoveNodeWithGlobRestriction2.
public void testMoveNodeWithGlobRestriction2() 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 node3 = superuser.getNode(childNPath).addNode(nodeName3);
superuser.save();
Privilege[] privileges = privilegesFromName(NameConstants.JCR_READ.toString());
// permissions defined @ path
// restriction: remove read priv to nodeName3 node
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, childNPath));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/" + nodeName3));
withdrawPrivileges(childNPath, privileges, restrictions);
// don't fill the per-session read-cache by calling Session.nodeExists
assertFalse(testAcMgr.hasPrivileges(node3.getPath(), privileges));
String movedChildNPath = path + "/movedNode";
String movedNode3Path = movedChildNPath + "/" + node3.getName();
superuser.move(childNPath, movedChildNPath);
superuser.save();
assertFalse(testSession.nodeExists(movedNode3Path));
assertFalse(testAcMgr.hasPrivileges(movedNode3Path, privileges));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class ReadTest method testGlobRestriction.
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);
Privilege[] read = privilegesFromName(Privilege.JCR_READ);
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("*/" + jcrPrimaryType));
withdrawPrivileges(path, read, restrictions);
assertTrue(testAcMgr.hasPrivileges(path, read));
assertTrue(testSession.hasPermission(path, javax.jcr.Session.ACTION_READ));
testSession.getNode(path);
assertTrue(testAcMgr.hasPrivileges(childNPath, read));
assertTrue(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_READ));
testSession.getNode(childNPath);
String propPath = path + "/" + jcrPrimaryType;
assertFalse(testSession.hasPermission(propPath, javax.jcr.Session.ACTION_READ));
assertFalse(testSession.propertyExists(propPath));
propPath = childNPath + "/" + jcrPrimaryType;
assertFalse(testSession.hasPermission(propPath, javax.jcr.Session.ACTION_READ));
assertFalse(testSession.propertyExists(propPath));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractNode method setProperty.
/**
* Sets the value of the named property.
* <p>
* The default implementation uses the {@link ValueFactory} of the
* current {@link Session} to create a {@link Value} instances from
* the given string values and forwards the call to the
* {@link Node#setProperty(String, Value[])} method.
*
* @param name property name
* @param strings string values
* @return modified property
* @throws RepositoryException if an error occurs
*/
public Property setProperty(String name, String[] strings) throws RepositoryException {
ValueFactory factory = getSession().getValueFactory();
Value[] values = new Value[strings.length];
for (int i = 0; i < strings.length; i++) {
values[i] = factory.createValue(strings[i]);
}
return setProperty(name, values);
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractNode method setProperty.
/**
* Sets the value of the named property.
* <p>
* The default implementation uses the {@link ValueFactory} of the
* current {@link Session} to convert the given values to the given
* type and forwards the call to the
* {@link Node#setProperty(String, Value[])} method.
*
* @param name property name
* @param values property values
* @param type property type
* @return modified property
* @throws RepositoryException if an error occurs
*/
public Property setProperty(String name, Value[] values, int type) throws RepositoryException {
ValueFactory factory = getSession().getValueFactory();
Value[] converted = new Value[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i].getType() != type) {
converted[i] = factory.createValue(values[i].getString(), type);
} else {
converted[i] = values[i];
}
}
return setProperty(name, converted);
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class AbstractNode method setProperty.
/**
* Sets the value of the named property.
* <p>
* The default implementation uses the {@link ValueFactory} of the
* current {@link Session} to create {@link Value} instances of the
* given type from the given string values and forwards the call to the
* {@link Node#setProperty(String, Value[])} method.
*
* @param name property name
* @param strings string values
* @param type property type
* @return modified property
* @throws RepositoryException if an error occurs
*/
public Property setProperty(String name, String[] strings, int type) throws RepositoryException {
ValueFactory factory = getSession().getValueFactory();
Value[] values = new Value[strings.length];
for (int i = 0; i < strings.length; i++) {
values[i] = factory.createValue(strings[i], type);
}
return setProperty(name, values);
}
Aggregations