Search in sources :

Example 11 with ValueFactory

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);
    }
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) IOException(java.io.IOException)

Example 12 with ValueFactory

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));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session)

Example 13 with ValueFactory

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();
        }
    }
}
Also used : ValueFactory(javax.jcr.ValueFactory) SerialValueFactory(org.apache.jackrabbit.rmi.value.SerialValueFactory) Binary(javax.jcr.Binary)

Example 14 with ValueFactory

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();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with ValueFactory

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));
}
Also used : ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) HashMap(java.util.HashMap) AccessControlEntry(javax.jcr.security.AccessControlEntry) TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) ValueFactory(javax.jcr.ValueFactory) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) Value(javax.jcr.Value) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

ValueFactory (javax.jcr.ValueFactory)105 Value (javax.jcr.Value)51 Node (javax.jcr.Node)50 Session (javax.jcr.Session)40 Test (org.junit.Test)17 RepositoryException (javax.jcr.RepositoryException)16 InputStream (java.io.InputStream)13 AccessControlManager (javax.jcr.security.AccessControlManager)13 HashMap (java.util.HashMap)12 Privilege (javax.jcr.security.Privilege)12 Property (javax.jcr.Property)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Query (javax.jcr.query.Query)8 Calendar (java.util.Calendar)7 QueryManager (javax.jcr.query.QueryManager)7 RowIterator (javax.jcr.query.RowIterator)7 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)7 NodeIterator (javax.jcr.NodeIterator)6 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)6 IOException (java.io.IOException)5