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