use of org.exist.xquery.XQuery 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.XQuery 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.XQuery in project exist by eXist-db.
the class PermissionsFunctionChownTest method changeOwner.
private void changeOwner(final Subject execAsUser, final boolean restricted, final XmldbURI uri, final String newOwnerGroup, final String expectedOwnerGroup) throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existWebServer.getBrokerPool();
final boolean prevRestricted = setPosixChownRestricted(restricted);
final String query = "import module namespace sm = 'http://exist-db.org/xquery/securitymanager';\n" + "sm:chown(xs:anyURI('" + uri.getRawCollectionPath() + "'), '" + newOwnerGroup + "'),\n" + "sm:get-permissions(xs:anyURI('" + uri.getRawCollectionPath() + "'))/sm:permission/(string(@owner), string(@group))";
try (final DBBroker broker = pool.get(Optional.of(execAsUser))) {
final XQuery xquery = existWebServer.getBrokerPool().getXQueryService();
final Sequence result = xquery.execute(broker, query, null);
assertEquals(2, result.getItemCount());
final String[] expectedOwnerGroupParts = expectedOwnerGroup.split(":");
assertEquals(expectedOwnerGroupParts[0], result.itemAt(0).getStringValue());
if (expectedOwnerGroupParts.length == 2) {
assertEquals(expectedOwnerGroupParts[1], result.itemAt(1).getStringValue());
}
} finally {
setPosixChownRestricted(prevRestricted);
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class TransformTest method transform1.
private static void transform1(final XmldbURI collectionUri) throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xquery = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Sequence sequence = xquery.execute(broker, getCountDescendantsXquery(collectionUri), null);
assertNotNull(sequence);
assertTrue(sequence.hasOne());
final Source expected = Input.fromString("<count-descendants>1</count-descendants>").build();
final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Node.class).getOwnerDocument()).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
}
use of org.exist.xquery.XQuery in project exist by eXist-db.
the class TransformTest method transform_twoNodesCountDescendants.
private static void transform_twoNodesCountDescendants() throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xquery = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Sequence sequence = xquery.execute(broker, COUNT_DESCENDANTS_TWO_NODES_QUERY, null);
assertNotNull(sequence);
assertTrue(sequence.hasOne());
final Source expected = Input.fromString("<counts><count1>2</count1><count2>1</count2></counts>").build();
final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Node.class).getOwnerDocument()).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
}
Aggregations