use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method cannotExecuteXQueryWithoutExecutePermission.
@Test(expected = XMLDBException.class)
public void cannotExecuteXQueryWithoutExecutePermission() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
final String xquery = "<xquery>{ 1 + 2 }</xquery>";
Resource xqueryResource = test.createResource("test.xquery", BinaryResource.RESOURCE_TYPE);
xqueryResource.setContent(xquery);
test.storeResource(xqueryResource);
// execute only on xquery
ums.chmod(xqueryResource, "rw-------");
test.close();
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
xqueryResource = test.getResource("test.xquery");
assertEquals(xquery, new String((byte[]) xqueryResource.getContent()));
// execute the stored XQuery
final EXistXPathQueryService queryService = (EXistXPathQueryService) test.getService("XPathQueryService", "1.0");
final ResourceSet result = queryService.executeStoredQuery("/db/securityTest1/test.xquery");
assertEquals("<xquery>3</xquery>", result.getResource(0).getContent());
}
use of org.exist.xmldb.UserManagementService 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());
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method canReadXmlResourceWithOnlyExecutePermissionOnParentCollection.
@Test
public void canReadXmlResourceWithOnlyExecutePermissionOnParentCollection() 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");
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 copyCollection_doesNotPreservePermissions.
@Test
public void copyCollection_doesNotPreservePermissions() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3", "test1", "test1");
EXistCollectionManagementService cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
// create collection owned by "test1", and group "users" in /db/securityTest3
Collection source = cms.createCollection("source");
// as the 'test3' user copy the collection
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3", "test3", "test3");
cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
cms.copy("/db/securityTest3/source", "/db/securityTest3", "copy-of-source");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
final Permission permissions = ums.getPermissions(test.getChildCollection("copy-of-source"));
// collection should be owned by test3:guest, i.e. permissions were not preserved from the test1 users collection /db/securityTest3/source
assertEquals("test3", permissions.getOwner().getName());
assertEquals("guest", permissions.getGroup().getName());
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method canCreateBinaryResourceWithOnlyExecuteAndWritePermissionOnParentCollection.
@Test
public void canCreateBinaryResourceWithOnlyExecuteAndWritePermissionOnParentCollection() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("-wx------");
test.close();
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final Resource resource = test.createResource("other.bin", BinaryResource.RESOURCE_TYPE);
resource.setContent("binary".getBytes());
test.storeResource(resource);
}
Aggregations