use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method worldCreateCollection.
// fails since guest has no write permissions
@Test(expected = XMLDBException.class)
public void worldCreateCollection() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "guest", "guest");
final CollectionManagementService cms = (CollectionManagementService) test.getService("CollectionManagementService", "1.0");
cms.createCollection("createdByGuest");
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method noSetGid_createSubCollection_subCollectionGroupIsUsersPrimaryGroup.
@Test
public void noSetGid_createSubCollection_subCollectionGroupIsUsersPrimaryGroup() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest2", "test1", "test1");
CollectionManagementService cms = (CollectionManagementService) test.getService("CollectionManagementService", "1.0");
// create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxr--rwx"
Collection parentCollection = cms.createCollection("parentCollection");
UserManagementService ums = (UserManagementService) parentCollection.getService("UserManagementService", "1.0");
ums.chmod("rwxr--rwx");
// now create the sub-collection /db/securityTest2/parentCollection/subCollection1
// as "user3:guest", it should have it's group set to the primary group of user3 i.e. 'guest'
// as the collection is NOT setUid and it should NOT have the setGid bit set
parentCollection = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest2/parentCollection", "test3", "test3");
ums = (UserManagementService) parentCollection.getService("UserManagementService", "1.0");
cms = (CollectionManagementService) parentCollection.getService("CollectionManagementService", "1.0");
final Collection subCollection = cms.createCollection("subCollection1");
final Permission permissions = ums.getPermissions(subCollection);
assertEquals("guest", permissions.getGroup().getName());
assertFalse(permissions.isSetGid());
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method nonSetUidXQueryCannotWriteRestrictedCollection.
@Test(expected = XMLDBException.class)
public void nonSetUidXQueryCannotWriteRestrictedCollection() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final long timestamp = System.currentTimeMillis();
final String content = "<not_setuid>" + timestamp + "</not_setuid>";
// create an XQuery /db/securityTest1/not_setuid.xquery
final String xquery = "xmldb:store('/db/securityTest1/forSetUidWrite', 'not_setuid.xml', " + content + ")";
Resource xqueryResource = test.createResource("not_setuid.xquery", "BinaryResource");
xqueryResource.setContent(xquery);
test.storeResource(xqueryResource);
// set the xquery to be owned by 'test1' and do NOT set it 'setuid', and do set it 'rx' by 'users' group so 'test2' can execute it!
UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
xqueryResource = test.getResource("not_setuid.xquery");
// NOT SETUID
ums.chmod(xqueryResource, 00750);
// create a collection for the XQuery to write into
final CollectionManagementService cms = (CollectionManagementService) test.getService("CollectionManagementService", "1.0");
final Collection colForSetUid = cms.createCollection("forSetUidWrite");
// only allow the user 'test1' to write into the collection
ums = (UserManagementService) colForSetUid.getService("UserManagementService", "1.0");
ums.chmod(0700);
// execute the XQuery as the 'test2' user... it should become 'setuid' of 'test1' and succeed.
final Collection test2 = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test2", "test2");
final EXistXPathQueryService queryService = (EXistXPathQueryService) test2.getService("XPathQueryService", "1.0");
final ResourceSet result = queryService.executeStoredQuery("/db/securityTest1/not_setuid.xquery");
assertFalse("/db/securityTest1/forSetUidWrite/not_setuid.xml".equals(result.getResource(0).getContent()));
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class CollectionConfigurationTest method createCollection.
private void createCollection(String collection) throws XMLDBException {
final CollectionManagementService cmservice = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
Collection testCollection = cmservice.createCollection(collection);
assertNotNull(testCollection);
testCollection = cmservice.createCollection("/db/system/config" + collection);
assertNotNull(testCollection);
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class DatabaseCollectionTest method createCollections.
@Test
public void createCollections() throws XMLDBException {
final Collection testCollection = DatabaseManager.getCollection(ROOT_URI + "/" + TEST_COLLECTION);
final CollectionManagementService service = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
Collection validationCollection = service.createCollection(TestTools.VALIDATION_HOME_COLLECTION);
assertNotNull(validationCollection);
validationCollection = service.createCollection(TestTools.VALIDATION_HOME_COLLECTION + "/" + TestTools.VALIDATION_TMP_COLLECTION);
assertNotNull(validationCollection);
validationCollection = service.createCollection(TestTools.VALIDATION_HOME_COLLECTION + "/" + TestTools.VALIDATION_XSD_COLLECTION);
assertNotNull(validationCollection);
validationCollection = service.createCollection(TestTools.VALIDATION_HOME_COLLECTION + "/" + TestTools.VALIDATION_DTD_COLLECTION);
assertNotNull(validationCollection);
}
Aggregations