Search in sources :

Example 36 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class VersionTest method testReadVersionInfo2.

public void testReadVersionInfo2() throws RepositoryException, NotExecutableException {
    Node n = createVersionableNode(testRootNode);
    modifyPrivileges(VERSION_STORAGE_PATH, Privilege.JCR_READ, true);
    Node n2 = (Node) getTestSession().getItem(n.getPath());
    n2.getVersionHistory();
    n2.getBaseVersion();
}
Also used : Node(javax.jcr.Node)

Example 37 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class WriteTest method testEditor2.

public void testEditor2() throws NotExecutableException, RepositoryException {
    UserManager uMgr = getUserManager(superuser);
    User u = null;
    User u2 = null;
    try {
        u = uMgr.createUser("t", "t");
        u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt");
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Principal p = u.getPrincipal();
        Principal p2 = u2.getPrincipal();
        if (p instanceof ItemBasedPrincipal && p2 instanceof ItemBasedPrincipal && Text.isDescendant(((ItemBasedPrincipal) p).getPath(), ((ItemBasedPrincipal) p2).getPath())) {
            JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
            JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p2);
            acMgr.setPolicy(acls[0].getPath(), acls[0]);
            acls = acMgr.getApplicablePolicies(p);
            String path = acls[0].getPath();
            Node n = superuser.getNode(path);
            assertEquals("rep:PrincipalAccessControl", n.getPrimaryNodeType().getName());
        } else {
            throw new NotExecutableException();
        }
    } finally {
        superuser.refresh(false);
        if (u2 != null)
            u2.remove();
        if (u != null)
            u.remove();
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) User(org.apache.jackrabbit.api.security.user.User) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 38 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class WriteTest method testAutocreatedProperties.

public void testAutocreatedProperties() throws RepositoryException, NotExecutableException {
    givePrivileges(path, testUser.getPrincipal(), privilegesFromName(PrivilegeRegistry.REP_WRITE), getRestrictions(superuser, path));
    // test user is not allowed to READ the protected property jcr:created.
    Map<String, Value> restr = getRestrictions(superuser, path);
    restr.put(((SessionImpl) superuser).getJCRName(ACLTemplate.P_GLOB), superuser.getValueFactory().createValue("/afolder/jcr:created"));
    withdrawPrivileges(path, testUser.getPrincipal(), privilegesFromName(Privilege.JCR_READ), restr);
    // still: adding a nt:folder node should be possible
    Node n = getTestSession().getNode(path);
    Node folder = n.addNode("afolder", "nt:folder");
    assertFalse(folder.hasProperty("jcr:created"));
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value)

Example 39 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class WriteTest method testRemoveNodeWithInvisibleChild.

public void testRemoveNodeWithInvisibleChild() throws Exception {
    Privilege[] privileges = privilegesFromNames(new String[] { Privilege.JCR_READ, Privilege.JCR_WRITE });
    Node invisible = superuser.getNode(childNPath).addNode(nodeName3);
    superuser.save();
    /* allow READ/WRITE privilege for testUser at 'path' */
    givePrivileges(path, testUser.getPrincipal(), privileges, getRestrictions(superuser, path));
    /* deny READ privilege at invisible node. (removal is still granted) */
    withdrawPrivileges(invisible.getPath(), testUser.getPrincipal(), privilegesFromNames(new String[] { Privilege.JCR_READ }), getRestrictions(superuser, path));
    Session testSession = getTestSession();
    assertTrue(testSession.nodeExists(childNPath));
    assertTrue(testSession.hasPermission(childNPath, Session.ACTION_REMOVE));
    Node n = testSession.getNode(childNPath);
    // removing the child node must succeed as both remove-node and
    // remove-child-nodes are granted to testsession.
    // the policy node underneath childNPath should silently be removed
    // as the editing session has no knowledge about it's existence.
    n.remove();
    testSession.save();
}
Also used : Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session)

Example 40 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class WriteTest method testRemoveNodeWithInvisibleNonRemovableChild.

public void testRemoveNodeWithInvisibleNonRemovableChild() throws Exception {
    Privilege[] privileges = privilegesFromNames(new String[] { Privilege.JCR_READ, Privilege.JCR_WRITE });
    Node invisible = superuser.getNode(childNPath).addNode(nodeName3);
    superuser.save();
    /* allow READ/WRITE privilege for testUser at 'path' */
    givePrivileges(path, testUser.getPrincipal(), privileges, getRestrictions(superuser, path));
    /* deny READ privilege at invisible node. (removal is still granted) */
    withdrawPrivileges(invisible.getPath(), testUser.getPrincipal(), privileges, getRestrictions(superuser, path));
    Session testSession = getTestSession();
    assertTrue(testSession.nodeExists(childNPath));
    assertTrue(testSession.hasPermission(childNPath, Session.ACTION_REMOVE));
    Node n = testSession.getNode(childNPath);
    // be removed.
    try {
        n.remove();
        testSession.save();
        fail();
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81