use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method worldChmodCollection.
// fails since guest has no write permissions
@Test(expected = XMLDBException.class)
public void worldChmodCollection() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "guest", "guest");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
// grant myself all rights ;-)
ums.chmod(0777);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method onlyReadAndExecuteRequiredToListCollectionSubCollections.
@Test
public void onlyReadAndExecuteRequiredToListCollectionSubCollections() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("r-x------");
test.listChildCollections();
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method cannotOpenRootCollectionWithoutExecute.
@Test(expected = XMLDBException.class)
public void cannotOpenRootCollectionWithoutExecute() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db", "admin", "");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("rw-rw-rw-");
test.close();
DatabaseManager.getCollection(getBaseUri() + "/db", "test1", "test1");
}
use of org.xmldb.api.base.Collection 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.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method canUpdateXmlResourceWithOnlyExecutePermissionOnParentCollection.
@Test
public void canUpdateXmlResourceWithOnlyExecutePermissionOnParentCollection() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("--x------");
test.close();
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
Resource resource = test.getResource("test.xml");
assertEquals("<test/>", resource.getContent());
// update the resource
resource.setContent("<testing/>");
test.storeResource(resource);
resource = test.getResource("test.xml");
assertEquals("<testing/>", resource.getContent());
}
Aggregations