Search in sources :

Example 16 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class AbstractLockManagementTest method testLock4.

public void testLock4() throws RepositoryException, NotExecutableException {
    Node n = createLockableNode(testRootNode);
    Node trn = getTestNode();
    modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true);
    modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
    Node n2 = trn.getNode(n.getName());
    n2.lock(true, true);
    Lock l = n2.getLock();
    String lt = l.getLockToken();
    // withdraw lock-mgmt -> logout of session must still remove the lock
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, false);
    getTestSession().logout();
    boolean isLocked = n.isLocked();
    assertFalse(isLocked);
}
Also used : Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Example 17 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class AbstractLockManagementTest method testLock3.

public void testLock3() throws RepositoryException, NotExecutableException {
    Node n = createLockableNode(testRootNode);
    Node trn = getTestNode();
    modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true);
    modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
    Node n2 = trn.getNode(n.getName());
    n2.lock(true, true);
    Lock l = n2.getLock();
    // withdraw lock-mgmt -> must not be able to refresh the lock or
    // unlock the node
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, false);
    try {
        l.refresh();
        fail("TestUser doesn't have permission to refresh the lock.");
    } catch (AccessDeniedException e) {
    // success
    }
    try {
        n2.unlock();
        fail("TestUser doesn't have permission to unlock the node.");
    } catch (AccessDeniedException e) {
    // success
    }
    // make sure the lock can be removed upon session.logout.
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Example 18 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockTimeOutFormatTest method testfmt.

private void testfmt(long jcrtimeout, String expectedString) throws RepositoryException, URISyntaxException, ParserConfigurationException {
    Lock l = new TestLock(jcrtimeout);
    JcrActiveLock al = new JcrActiveLock(l);
    Document d = DomUtil.createDocument();
    Element activeLock = al.toXml(d);
    assertEquals("activelock", activeLock.getLocalName());
    NodeList nl = activeLock.getElementsByTagNameNS("DAV:", "timeout");
    if (expectedString == null) {
        assertEquals(0, nl.getLength());
    } else {
        assertEquals(1, nl.getLength());
        Element timeout = (Element) nl.item(0);
        String t = DomUtil.getText(timeout);
        assertEquals(expectedString, t);
    }
}
Also used : JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)

Example 19 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockTokenMappingTest method testRoundtrip.

private void testRoundtrip(String token) throws RepositoryException, URISyntaxException {
    Lock l = new TestLock(token);
    String davtoken = LockTokenMapper.getDavLocktoken(l);
    // valid URI?
    URI u = new URI(davtoken);
    assertTrue("lock token must be absolute URI", u.isAbsolute());
    assertEquals("lock token URI must be all-ASCII", u.toASCIIString(), u.toString());
    String jcrtoken = LockTokenMapper.getJcrLockToken(davtoken);
    assertEquals(jcrtoken, l.getLockToken());
}
Also used : URI(java.net.URI) Lock(javax.jcr.lock.Lock)

Example 20 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class XATest method testLockProperties3.

/**
     * Test visibility of lock properties by another session.
     *
     * @throws Exception
     */
public void testLockProperties3() throws Exception {
    // add node that is both lockable and referenceable, save
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixLockable);
    n.addMixin(mixReferenceable);
    testRootNode.save();
    Lock lock = n.lock(false, true);
    // get user transaction object, start
    UserTransaction utx = new UserTransactionImpl(superuser);
    utx.begin();
    // unlock
    n.unlock();
    Node n2 = (Node) otherSuperuser.getItem(n.getPath());
    assertTrue(n2.isLocked());
    assertTrue(n2.hasProperty(jcrLockOwner));
    assertTrue(n2.hasProperty(jcrlockIsDeep));
    Lock lock2 = n2.getLock();
    // complete transaction
    utx.commit();
    // unlock must now be visible to other session
    n2.refresh(false);
    assertFalse(lock2.isLive());
    assertFalse(n2.isLocked());
    assertFalse(n2.hasProperty(jcrLockOwner));
    assertFalse(n2.hasProperty(jcrlockIsDeep));
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Aggregations

Lock (javax.jcr.lock.Lock)67 Node (javax.jcr.Node)41 Session (javax.jcr.Session)20 LockException (javax.jcr.lock.LockException)13 UserTransaction (javax.transaction.UserTransaction)12 RepositoryException (javax.jcr.RepositoryException)8 LockManager (javax.jcr.lock.LockManager)7 JcrActiveLock (org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)5 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)4 UserTransactionImpl (org.apache.jackrabbit.core.UserTransactionImpl)3 DavException (org.apache.jackrabbit.webdav.DavException)3 EventIterator (javax.jcr.observation.EventIterator)2 EventListener (javax.jcr.observation.EventListener)2 ObservationManager (javax.jcr.observation.ObservationManager)2 StaleItemStateException (org.apache.jackrabbit.core.state.StaleItemStateException)2 LockInfo (org.apache.jackrabbit.spi.LockInfo)2 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1