use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class XMLDBSecurityTest method setGidXQueryCanWriteRestrictedCollection.
@Test
public void setGidXQueryCanWriteRestrictedCollection() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest2", "test1", "test1");
final long timestamp = System.currentTimeMillis();
final String content = "<setgid>" + timestamp + "</setgid>";
// create an XQuery /db/securityTest1/setuid.xquery
final String xquery = "xmldb:store('/db/securityTest2/forSetGidWrite', 'setgid.xml', " + content + ")";
Resource xqueryResource = test.createResource("setgid.xquery", "BinaryResource");
xqueryResource.setContent(xquery);
test.storeResource(xqueryResource);
// set the xquery to be owned by 'test1':'users' and set it 'setgid', and set it 'rx' by ohers, so 'test3' can execute it!
UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
xqueryResource = test.getResource("setgid.xquery");
ums.chown(xqueryResource, ums.getAccount("test1"), "users");
// setgid
ums.chmod(xqueryResource, 02705);
// create a collection for the XQuery to write into
final CollectionManagementService cms = (CollectionManagementService) test.getService("CollectionManagementService", "1.0");
final Collection colForSetUid = cms.createCollection("forSetGidWrite");
// only allow the group 'users' to write into the collection
ums = (UserManagementService) colForSetUid.getService("UserManagementService", "1.0");
ums.chmod(0570);
// execute the XQuery as the 'test3' user... it should become 'setgid' of 'users' and succeed.
final Collection test3 = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest2", "test3", "test3");
final EXistXPathQueryService queryService = (EXistXPathQueryService) test3.getService("XPathQueryService", "1.0");
final ResourceSet result = queryService.executeStoredQuery("/db/securityTest2/setgid.xquery");
assertEquals("/db/securityTest2/forSetGidWrite/setgid.xml", result.getResource(0).getContent());
// check the written content
final Resource writtenXmlResource = colForSetUid.getResource("setgid.xml");
assertEquals(content, writtenXmlResource.getContent());
}
use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class XQueryTriggerTest method storeDocument_invalidTriggerForPrepare.
@Test
public void storeDocument_invalidTriggerForPrepare() throws XMLDBException {
final BinaryResource invalidModule = (BinaryResource) testCollection.createResource(MODULE_NAME, "BinaryResource");
((EXistResource) invalidModule).setMimeType("application/xquery");
invalidModule.setContent(INVALID_MODULE.getBytes());
testCollection.storeResource(invalidModule);
// configure the Collection with the trigger under test
final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
idxConf.configureCollection(COLLECTION_CONFIG);
final int max_store_attempts = 10;
int count_prepare_exceptions = 0;
for (int i = 0; i < max_store_attempts; i++) {
try {
// this will fire the trigger
final XMLResource doc = (XMLResource) testCollection.createResource(DOCUMENT_NAME, "XMLResource");
doc.setContent(DOCUMENT_CONTENT);
testCollection.storeResource(doc);
} catch (XMLDBException xdbe) {
if (xdbe.getCause() instanceof TriggerException) {
if (xdbe.getCause().getMessage().equals(XQueryTrigger.PREPARE_EXCEPTION_MESSAGE)) {
count_prepare_exceptions++;
}
}
}
}
assertEquals(max_store_attempts, count_prepare_exceptions);
}
use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class GetDataTest method afterClass.
@AfterClass
public static void afterClass() throws XMLDBException {
BinaryResource res = (BinaryResource) root.getResource(XQUERY_FILENAME);
root.removeResource(res);
}
use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class GetDataTest method beforeClass.
@BeforeClass
public static void beforeClass() throws XMLDBException {
root = DatabaseManager.getCollection("xmldb:exist://localhost:" + existWebServer.getPort() + "/xmlrpc/db", "admin", "");
BinaryResource res = (BinaryResource) root.createResource(XQUERY_FILENAME, "BinaryResource");
((EXistResource) res).setMimeType("application/xquery");
res.setContent(XQUERY);
root.storeResource(res);
UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");
ums.chmod(res, 0777);
}
use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class VariablesTest method writeModule.
private static void writeModule(final Collection collection, final String modulename, final String module) throws XMLDBException {
final BinaryResource res = (BinaryResource) collection.createResource(modulename, "BinaryResource");
((EXistResource) res).setMimeType("application/xquery");
res.setContent(module.getBytes());
collection.storeResource(res);
collection.close();
}
Aggregations