Search in sources :

Example 51 with ValueFactory

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

Example 52 with ValueFactory

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));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) HashMap(java.util.HashMap) Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 53 with ValueFactory

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);
}
Also used : Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory)

Example 54 with ValueFactory

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);
}
Also used : Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory)

Example 55 with ValueFactory

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);
}
Also used : Value(javax.jcr.Value) ValueFactory(javax.jcr.ValueFactory)

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