Search in sources :

Example 91 with ValueFactory

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));
}
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)

Example 92 with ValueFactory

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

Example 93 with ValueFactory

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

Example 94 with ValueFactory

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

Example 95 with ValueFactory

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

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