use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class TestTwoGetStreams method testTwoStreamsConcurrently.
/**
* Tests reading concurrently from two different streams.
*/
public void testTwoStreamsConcurrently() throws Exception {
Node root = superuser.getRootNode();
ValueFactory vf = superuser.getValueFactory();
root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
root.setProperty("p2", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
superuser.save();
InputStream i1 = root.getProperty("p1").getBinary().getStream();
InputStream i2 = root.getProperty("p2").getBinary().getStream();
assertEquals("Streams are different", i1, i2);
try {
i1.close();
} catch (IOException e) {
log.info("Could not close first input stream: ", e);
}
try {
i2.close();
} catch (IOException e) {
log.info("Could not close second input stream: ", e);
}
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class MoveTest method testMoveWithDifferentEffectiveAc.
public void testMoveWithDifferentEffectiveAc() 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();
String node3Path = node3.getPath();
Privilege[] privileges = privilegesFromName(NameConstants.JCR_READ.toString());
// @path read is denied, @childNode its allowed again
withdrawPrivileges(path, privileges, getRestrictions(superuser, path));
givePrivileges(childNPath, privileges, getRestrictions(superuser, childNPath));
assertTrue(testSession.nodeExists(node3Path));
assertTrue(testAcMgr.hasPrivileges(node3Path, privileges));
// move the ancestor node
String movedPath = path + "/movedNode";
superuser.move(node3Path, movedPath);
superuser.save();
// expected behavior:
// due to move node3 should not e visible any more
assertFalse(testSession.nodeExists(movedPath));
assertFalse(testAcMgr.hasPrivileges(movedPath, privileges));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class ClientProperty method setValue.
/**
* Sets the binary value of this property. Implemented as
* setValue(new BinaryValue(value)).
*
* {@inheritDoc}
*/
public void setValue(InputStream value) throws RepositoryException {
if (value == null) {
setValue((Value) null);
} else {
ValueFactory factory = getSession().getValueFactory();
Binary binary = factory.createBinary(value);
try {
setValue(factory.createValue(binary));
} finally {
binary.dispose();
}
}
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class AccessControlValidatorTest method testAceDifferentByRestrictionValue.
@Test
public void testAceDifferentByRestrictionValue() throws Exception {
ValueFactory vf = getValueFactory(root);
AccessControlManager acMgr = getAccessControlManager(root);
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testPath);
acl.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.JCR_ADD_CHILD_NODES), true, ImmutableMap.<String, Value>of(), ImmutableMap.of(AccessControlConstants.REP_NT_NAMES, new Value[] { vf.createValue(NodeTypeConstants.NT_OAK_UNSTRUCTURED, PropertyType.NAME) }));
// add ac-entry that only differs by the value of the restriction
acl.addEntry(testPrincipal, privilegesFromNames(PrivilegeConstants.JCR_ADD_CHILD_NODES), true, ImmutableMap.<String, Value>of(), ImmutableMap.of(AccessControlConstants.REP_NT_NAMES, new Value[] { vf.createValue(NodeTypeConstants.NT_UNSTRUCTURED, PropertyType.NAME) }));
assertEquals(2, acl.getAccessControlEntries().length);
acMgr.setPolicy(testPath, acl);
// persisting changes must succeed; the 2 ac-entries must not be treated as equal.
root.commit();
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testSetPrincipalPolicyWithNewMvRestriction.
@Test
public void testSetPrincipalPolicyWithNewMvRestriction() throws Exception {
setupPolicy(testPath);
root.commit();
JackrabbitAccessControlPolicy[] policies = acMgr.getPolicies(testPrincipal);
ACL acl = (ACL) policies[0];
Map<String, Value> restrictions = new HashMap();
restrictions.put(REP_NODE_PATH, getValueFactory().createValue(testPath, PropertyType.PATH));
Map<String, Value[]> mvRestrictions = new HashMap();
ValueFactory vf = getValueFactory(root);
Value[] restrValues = new Value[] { vf.createValue("itemname", PropertyType.NAME), vf.createValue("propName", PropertyType.NAME) };
mvRestrictions.put(REP_ITEM_NAMES, restrValues);
assertTrue(acl.addEntry(testPrincipal, testPrivileges, true, restrictions, mvRestrictions));
acMgr.setPolicy(acl.getPath(), acl);
AccessControlEntry[] entries = ((ACL) acMgr.getPolicies(testPath)[0]).getAccessControlEntries();
assertEquals(2, entries.length);
ACE newEntry = (ACE) entries[1];
assertEquals(1, newEntry.getRestrictions().size());
assertArrayEquals(restrValues, newEntry.getRestrictions(REP_ITEM_NAMES));
}
Aggregations