use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XUpdateTest method startup.
@Before
public void startup() throws XMLDBException, IOException, URISyntaxException {
col = existXmldbEmbeddedServer.getRoot().getChildCollection(XUPDATE_COLLECTION);
if (col == null) {
final CollectionManagementService collectionManagementService = (CollectionManagementService) existXmldbEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
col = collectionManagementService.createCollection(XUPDATE_COLLECTION);
final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
// change ownership to guest
final Account guest = ums.getAccount("guest");
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod(Permission.DEFAULT_COLLECTION_PERM);
}
addDocument(sourceFile);
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class ExistXmldbEmbeddedServer method createCollection.
public Collection createCollection(final Collection collection, final String collectionName) throws XMLDBException {
final CollectionManagementService collectionManagementService = (CollectionManagementService) collection.getService("CollectionManagementService", "1.0");
Collection newCollection = collection.getChildCollection(collectionName);
if (newCollection == null) {
collectionManagementService.createCollection(collectionName);
}
final XmldbURI uri = XmldbURI.LOCAL_DB_URI.resolveCollectionPath(((EXistCollection) collection).getPathURI().append(collectionName));
if (asGuest) {
newCollection = DatabaseManager.getCollection(uri.toString(), TestUtils.GUEST_DB_USER, TestUtils.GUEST_DB_PWD);
} else {
newCollection = DatabaseManager.getCollection(uri.toString(), TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
}
return newCollection;
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method cleanup.
@After
public void cleanup() throws XMLDBException {
final Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", "admin", "");
final CollectionManagementService cms = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
final Collection secTest1 = root.getChildCollection("securityTest1");
if (secTest1 != null) {
secTest1.close();
cms.removeCollection("securityTest1");
}
final Collection secTest2 = root.getChildCollection("securityTest2");
if (secTest2 != null) {
secTest2.close();
cms.removeCollection("securityTest2");
}
final Collection secTest3 = root.getChildCollection("securityTest3");
if (secTest3 != null) {
secTest3.close();
cms.removeCollection("securityTest3");
}
final UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");
// remove accounts 'test1', 'test2' and 'test3'
removeAccounts(ums, new String[] { "test1", "test2", "test3" });
// remove group 'users', 'extusers', 'test2-only'
removeGroups(ums, new String[] { "users", "extusers", "test2-only" });
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method setGid_createSubCollection_subCollectionGroupInheritedFromParent.
@Test
public void setGid_createSubCollection_subCollectionGroupInheritedFromParent() 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 "rwxrwsrwx"
Collection parentCollection = cms.createCollection("parentCollection");
UserManagementService ums = (UserManagementService) parentCollection.getService("UserManagementService", "1.0");
ums.chmod("rwxrwsrwx");
// now create the sub-collection /db/securityTest2/parentCollection/subCollection1
// it should inherit the group ownership 'users' from the parent collection which is setGid
// and it should inherit the setGid bit
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("users", permissions.getGroup().getName());
assertTrue(permissions.isSetGid());
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method setUidXQueryCanWriteRestrictedCollection.
@Test
public void setUidXQueryCanWriteRestrictedCollection() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final long timestamp = System.currentTimeMillis();
final String content = "<setuid>" + timestamp + "</setuid>";
// create an XQuery /db/securityTest1/setuid.xquery
final String xquery = "xmldb:store('/db/securityTest1/forSetUidWrite', 'setuid.xml', " + content + ")";
Resource xqueryResource = test.createResource("setuid.xquery", "BinaryResource");
xqueryResource.setContent(xquery);
test.storeResource(xqueryResource);
// set the xquery to be owned by 'test1' and set it 'setuid', and set it 'rx' by 'users' group so 'test2' can execute it!
UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
xqueryResource = test.getResource("setuid.xquery");
ums.chmod(xqueryResource, 04750);
// 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/setuid.xquery");
assertEquals("/db/securityTest1/forSetUidWrite/setuid.xml", result.getResource(0).getContent());
// check the written content
final Resource writtenXmlResource = colForSetUid.getResource("setuid.xml");
assertEquals(content, writtenXmlResource.getContent());
}
Aggregations