Search in sources :

Example 61 with Session

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

the class AccessManagerTest method testCanAccessNotExistingWorkspace.

public void testCanAccessNotExistingWorkspace() throws RepositoryException, NotExecutableException {
    Session s = getHelper().getReadOnlySession();
    try {
        List<String> all = Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames());
        String testName = "anyWorkspace";
        int i = 0;
        while (all.contains(testName)) {
            testName = "anyWorkspace" + i;
            i++;
        }
        assertFalse(getAccessManager(s).canAccess(testName));
    } catch (NoSuchWorkspaceException e) {
    // fine as well.
    } finally {
        s.logout();
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) Session(javax.jcr.Session)

Example 62 with Session

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

the class AccessManagerTest method testIsGrantedReadOnlySession.

public void testIsGrantedReadOnlySession() throws NotExecutableException, RepositoryException {
    Session s = getHelper().getReadOnlySession();
    try {
        AccessManager acMgr = getAccessManager(s);
        Path p = PathFactoryImpl.getInstance().getRootPath();
        // existing node-path
        assertTrue(acMgr.isGranted(p, Permission.READ));
        // not existing property:
        assertTrue(acMgr.isGranted(p, NameConstants.JCR_CREATED, Permission.READ));
        // existing node-path
        assertFalse(acMgr.isGranted(p, Permission.ALL));
        // not existing property:
        assertFalse(acMgr.isGranted(p, NameConstants.JCR_CREATED, Permission.ALL));
    } finally {
        s.logout();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) Session(javax.jcr.Session)

Example 63 with Session

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

the class RemoveOrphanVersionHistoryTest method testRemoveOrphanVersionHistory.

/**
     * Test orphan version history cleaning in a single workspace.
     * @throws RepositoryException if an error occurs.
     */
public void testRemoveOrphanVersionHistory() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Session session = n.getSession();
    VersionHistory vh = n.getVersionHistory();
    String vhUuid = vh.getUUID();
    assertExists(session, vhUuid);
    // First version
    Version v10 = n.checkin();
    n.checkout();
    // Second version
    Version v11 = n.checkin();
    n.checkout();
    // Remove node
    n.remove();
    testRootNode.save();
    assertExists(session, vhUuid);
    // Remove the first version
    vh.removeVersion(v10.getName());
    assertExists(session, vhUuid);
    // Remove the second and last version
    vh.removeVersion(v11.getName());
    try {
        session.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed");
    } catch (ItemNotFoundException e) {
    // Expected
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 64 with Session

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

the class RemoveOrphanVersionHistoryTest method testEmptyNonOrphanVersionHistory.

/**
     * Test that an emptied version history that is still being referenced
     * from another workspace does not get removed.
     *
     * @throws RepositoryException if an error occurs.
     */
public void testEmptyNonOrphanVersionHistory() throws RepositoryException {
    Session session = testRootNode.getSession();
    // Create versionable test node
    Node node = testRootNode.addNode(nodeName1);
    node.addMixin(mixVersionable);
    session.save();
    VersionHistory history = node.getVersionHistory();
    String uuid = history.getUUID();
    // Create version 1.0
    Version v10 = node.checkin();
    // Remove the test node
    node.checkout();
    node.remove();
    session.save();
    Session otherSession = getHelper().getReadWriteSession(workspaceName);
    try {
        // create a reference to the version history in another workspace
        Node otherRoot = otherSession.getRootNode();
        Property reference = otherRoot.setProperty("RemoveOrphanVersionTest", uuid, PropertyType.REFERENCE);
        otherSession.save();
        // Now remove the contents of the version history
        history.removeVersion(v10.getName());
        // Check that the version history still exists!
        try {
            session.getNodeByUUID(uuid);
        } catch (ItemNotFoundException e) {
            fail("Referenced empty version history must note be removed");
        }
        // Cleanup
        reference.remove();
        otherSession.save();
    } finally {
        otherSession.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 65 with Session

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

the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.

/**
     * Test orphan version history cleaning in multiple workspace.
     * @throws RepositoryException if an error occurs.
     */
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Session session = n.getSession();
    VersionHistory vh = n.getVersionHistory();
    String vhUuid = vh.getUUID();
    assertExists(session, vhUuid);
    // First version
    Version v10 = n.checkin();
    n.checkout();
    Workspace defaultWorkspace = n.getSession().getWorkspace();
    Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
    // Clone the node in another workspace
    otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
    Node otherWsRootNode = otherWsSession.getRootNode();
    Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
    // Ensure that version histories are the same
    assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
    Version v11 = clonedNode.checkin();
    clonedNode.checkout();
    // Remove node
    n.remove();
    testRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the first version
    vh.removeVersion(v10.getName());
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove cloned node
    clonedNode.remove();
    otherWsRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the last version
    vh.removeVersion(v11.getName());
    try {
        session.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the default workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
    try {
        otherWsSession.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the other workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

Session (javax.jcr.Session)1177 Node (javax.jcr.Node)645 Test (org.junit.Test)359 RepositoryException (javax.jcr.RepositoryException)206 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)158 SimpleCredentials (javax.jcr.SimpleCredentials)86 Property (javax.jcr.Property)78 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Privilege (javax.jcr.security.Privilege)76 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)64 Value (javax.jcr.Value)63 Query (javax.jcr.query.Query)58 NodeIterator (javax.jcr.NodeIterator)55 QueryManager (javax.jcr.query.QueryManager)53 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)48 AccessControlManager (javax.jcr.security.AccessControlManager)47 HashMap (java.util.HashMap)44 UserManager (org.apache.jackrabbit.api.security.user.UserManager)43 ArrayList (java.util.ArrayList)41