Search in sources :

Example 21 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class XqueryApiTest method executeQuery.

private Sequence executeQuery(final String uid, final String pwd, final String query) throws ApiException {
    try {
        final BrokerPool pool = server.getBrokerPool();
        final XQuery xquery = pool.getXQueryService();
        final Subject user = pool.getSecurityManager().authenticate(uid, pwd);
        try (final DBBroker broker = pool.get(Optional.of(user))) {
            return xquery.execute(broker, query, null);
        }
    } catch (final AuthenticationException | EXistException | PermissionDeniedException | XPathException e) {
        throw new ApiException(e.getMessage(), e);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XPathException(org.exist.xquery.XPathException) XQuery(org.exist.xquery.XQuery) EXistException(org.exist.EXistException) BrokerPool(org.exist.storage.BrokerPool)

Example 22 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class FnCollectionSecurityTest method cannotAccessCollectionInCollectionHierarchyWithDeniedExecute.

@Test(expected = PermissionDeniedException.class)
public void cannotAccessCollectionInCollectionHierarchyWithDeniedExecute() throws EXistException, AuthenticationException, PermissionDeniedException, XPathException {
    // as docTestUser1 user
    final String query = "fn:collection('" + TEST_SUB_COLLECTION_1_1 + "')";
    final BrokerPool pool = server.getBrokerPool();
    final SecurityManager securityManager = pool.getSecurityManager();
    final Subject testUser1 = securityManager.authenticate(TEST_USER_1, TEST_USER_1);
    try (final DBBroker broker = pool.get(Optional.of(testUser1));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final XQuery xqueryService = pool.getXQueryService();
        final Sequence result = xqueryService.execute(broker, query, null);
        fail("Expected PermissionDeniedException via XPathException");
        transaction.commit();
    } catch (final XPathException e) {
        if (e.getCause() != null && e.getCause() instanceof PermissionDeniedException) {
            throw (PermissionDeniedException) e.getCause();
        } else {
            throw e;
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XPathException(org.exist.xquery.XPathException) XQuery(org.exist.xquery.XQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 23 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class FnCollectionSecurityTest method cannotAccessCollectionInCollectionHierarchyWithDeniedReadAndExecuteAce.

@Test(expected = PermissionDeniedException.class)
public void cannotAccessCollectionInCollectionHierarchyWithDeniedReadAndExecuteAce() throws EXistException, AuthenticationException, PermissionDeniedException, XPathException {
    // as docTestUser1 user
    final String query = "fn:collection('" + TEST_SUB_COLLECTION_2_2 + "')";
    final BrokerPool pool = server.getBrokerPool();
    final SecurityManager securityManager = pool.getSecurityManager();
    final Subject testUser1 = securityManager.authenticate(TEST_USER_1, TEST_USER_1);
    try (final DBBroker broker = pool.get(Optional.of(testUser1));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final XQuery xqueryService = pool.getXQueryService();
        final Sequence result = xqueryService.execute(broker, query, null);
        fail("Expected PermissionDeniedException via XPathException");
        transaction.commit();
    } catch (final XPathException e) {
        if (e.getCause() != null && e.getCause() instanceof PermissionDeniedException) {
            throw (PermissionDeniedException) e.getCause();
        } else {
            throw e;
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XPathException(org.exist.xquery.XPathException) XQuery(org.exist.xquery.XQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 24 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class FnDocSecurityTest method cannotAccessRestrictedDocument.

@Test(expected = PermissionDeniedException.class)
public void cannotAccessRestrictedDocument() throws EXistException, AuthenticationException, PermissionDeniedException, XPathException, IOException, SAXException {
    // as docTestUser1 user
    final String query = "fn:doc('" + TEST_DOC_URI_SYSTEM_ONLY + "')";
    final BrokerPool pool = server.getBrokerPool();
    final SecurityManager securityManager = pool.getSecurityManager();
    final Subject testUser1 = securityManager.authenticate(TEST_USER_1, TEST_USER_1);
    try (final DBBroker broker = pool.get(Optional.of(testUser1));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final XQuery xqueryService = pool.getXQueryService();
        final Sequence result = xqueryService.execute(broker, query, null);
        fail("Expected PermissionDeniedException via XPathException");
        transaction.commit();
    } catch (final XPathException e) {
        if (e.getCause() != null && e.getCause() instanceof PermissionDeniedException) {
            throw (PermissionDeniedException) e.getCause();
        } else {
            throw e;
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XPathException(org.exist.xquery.XPathException) XQuery(org.exist.xquery.XQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 25 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class TryCatchTest method xQuery3_1.

@Test
public void xQuery3_1() throws XMLDBException {
    final String query1 = "xquery version '1.0';" + "try { a + 7 } catch * { 1 }";
    try {
        final ResourceSet results = existEmbeddedServer.executeQuery(query1);
        final String r = (String) results.getResource(0).getContent();
        assertEquals("1", r);
        fail("exception expected");
    } catch (final Throwable t) {
        final Throwable cause = t.getCause();
        if (cause instanceof XPathException) {
            final XPathException ex = (XPathException) cause;
            assertEquals("exerr:EXXQDY0003", ex.getErrorCode().getErrorQName().getStringValue());
        } else {
            throw t;
        }
    }
}
Also used : XPathException(org.exist.xquery.XPathException) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Aggregations

XPathException (org.exist.xquery.XPathException)306 Sequence (org.exist.xquery.value.Sequence)86 IOException (java.io.IOException)61 SAXException (org.xml.sax.SAXException)43 StringValue (org.exist.xquery.value.StringValue)40 PermissionDeniedException (org.exist.security.PermissionDeniedException)34 NodeValue (org.exist.xquery.value.NodeValue)34 DBBroker (org.exist.storage.DBBroker)32 IntegerValue (org.exist.xquery.value.IntegerValue)32 ValueSequence (org.exist.xquery.value.ValueSequence)27 Item (org.exist.xquery.value.Item)26 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)24 EXistException (org.exist.EXistException)23 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)22 BrokerPool (org.exist.storage.BrokerPool)21 Txn (org.exist.storage.txn.Txn)21 XQueryContext (org.exist.xquery.XQueryContext)21 Element (org.w3c.dom.Element)21 XQuery (org.exist.xquery.XQuery)20