use of org.exist.xmldb.UserManagementService 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.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method groupMemberChownUidCollection.
/**
* Group member can NOT change the owner uid of a collection
*
* As the user 'test2' attempt to change the
* ownership uid of /db/securityTest1
* to ourselves
*/
@Test(expected = XMLDBException.class)
public void groupMemberChownUidCollection() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test2", "test2");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
// attempt to take uid ownership of /db/securityTest1
final Account test2 = ums.getAccount("test2");
ums.chown(test2);
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method cannotReadXmlResourceWithoutExecutePermissionOnParentCollection.
@Test(expected = XMLDBException.class)
public void cannotReadXmlResourceWithoutExecutePermissionOnParentCollection() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("rw-------");
test.close();
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final Resource resource = test.getResource("test.xml");
assertEquals("<test/>", resource.getContent());
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method cannotUpdateBinaryResourceWithoutExecutePermissionOnParentCollection.
@Test(expected = XMLDBException.class)
public void cannotUpdateBinaryResourceWithoutExecutePermissionOnParentCollection() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("rw-------");
test.close();
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
Resource resource = test.getResource("test.bin");
assertArrayEquals("binary-test".getBytes(), (byte[]) resource.getContent());
// attempt to update the resource
resource.setContent("testing".getBytes());
test.storeResource(resource);
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method copyCollection_doesPreservePermissionsOfSubDocuments.
@Test
public void copyCollection_doesPreservePermissionsOfSubDocuments() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
EXistCollectionManagementService cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
cms.copy(XmldbURI.create("/db/securityTest1"), XmldbURI.create("/db/securityTest3"), XmldbURI.create("copy-of-securityTest1"));
final Collection testCopy = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3/copy-of-securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) testCopy.getService("UserManagementService", "1.0");
final Resource resource = testCopy.getResource("test.xml");
final Permission permissions = ums.getPermissions(resource);
assertEquals("test1", permissions.getOwner().getName());
assertEquals("users", permissions.getGroup().getName());
assertEquals(0770, permissions.getMode());
}
Aggregations