Search in sources :

Example 26 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class XMLDBSecurityTest method copyDocument_doesNotPreservePermissions.

@Test
public void copyDocument_doesNotPreservePermissions() throws XMLDBException {
    Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3", "test1", "test1");
    EXistCollectionManagementService cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
    // create resource owned by "test1", and group "users" in /db/securityTest3
    final Resource resSource = test.createResource("source.xml", XMLResource.RESOURCE_TYPE);
    resSource.setContent("<test/>");
    test.storeResource(resSource);
    // as the 'test3' user copy the resource
    test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3", "test3", "test3");
    cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
    cms.copyResource("/db/securityTest3/source.xml", "/db/securityTest3", "copy-of-source.xml");
    final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
    final Permission permissions = ums.getPermissions(test.getResource("copy-of-source.xml"));
    // resource should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source.xml
    assertEquals("test3", permissions.getOwner().getName());
    assertEquals("guest", permissions.getGroup().getName());
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) UserManagementService(org.exist.xmldb.UserManagementService) Test(org.junit.Test)

Example 27 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class XMLDBSecurityTest method copyCollectionWithResources_destExists_destIsNotWritable.

/**
 * As the 'test1' user, creates the collection and resource:
 *
 *  test1:users /db/securityTest3/source
 *  test1:users /db/securityTest3/source/source1.xml
 *  test1:users /db/securityTest3/source/source2.xml
 *
 * We then also create the Collection
 *  test1:users /db/securityTest3/copy-of-source (0755)
 * so that the destination (for the copy we are about
 * to do) already exists and is NOT writable...
 *
 * As the 'test3' user, copy the collection:
 *
 *  /db/securityTest3/source
 *      -> /db/securityTest3/copy-of-source
 */
@Test(expected = XMLDBException.class)
public void copyCollectionWithResources_destExists_destIsNotWritable() 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");
    // create resource owned by "test1", and group "users" in /db/securityTest3/source
    Resource resSource = source.createResource("source1.xml", XMLResource.RESOURCE_TYPE);
    resSource.setContent("<test/>");
    source.storeResource(resSource);
    resSource = source.createResource("source2.xml", XMLResource.RESOURCE_TYPE);
    resSource.setContent("<test/>");
    source.storeResource(resSource);
    // pre-create the destination with default mode (0755)
    // so that it is not writable by 'test3' user
    final Collection dest = cms.createCollection("copy-of-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");
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) Test(org.junit.Test)

Example 28 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService 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());
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) UserManagementService(org.exist.xmldb.UserManagementService) Test(org.junit.Test)

Example 29 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService 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());
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Collection(org.xmldb.api.base.Collection) UserManagementService(org.exist.xmldb.UserManagementService) Test(org.junit.Test)

Example 30 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class XMLDBSecurityTest method copyCollectionWithResources_destExists_destIsWritable.

/**
 * As the 'test1' user, creates the collection and resource:
 *
 *  test1:users /db/securityTest3/source
 *  test1:users /db/securityTest3/source/source1.xml
 *  test1:users /db/securityTest3/source/source2.xml
 *
 * We then also create the Collection
 *  test1:users /db/securityTest3/copy-of-source (0777)
 * so that the destination (for the copy we are about
 * to do) already exists and is writable...
 *
 * As the 'test3' user, copy the collection:
 *
 *  /db/securityTest3/source
 *      -> /db/securityTest3/copy-of-source
 */
@Test
public void copyCollectionWithResources_destExists_destIsWritable() 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");
    // create resource owned by "test1", and group "users" in /db/securityTest3/source
    Resource resSource = source.createResource("source1.xml", XMLResource.RESOURCE_TYPE);
    resSource.setContent("<test/>");
    source.storeResource(resSource);
    resSource = source.createResource("source2.xml", XMLResource.RESOURCE_TYPE);
    resSource.setContent("<test/>");
    source.storeResource(resSource);
    // pre-create the destination and set writable by all
    final Collection dest = cms.createCollection("copy-of-source");
    final UserManagementService ums = (UserManagementService) dest.getService("UserManagementService", "1.0");
    ums.chmod(0777);
    // 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 Collection copyOfSource = test.getChildCollection("copy-of-source");
    assertNotNull(copyOfSource);
    assertEquals(2, copyOfSource.listResources().length);
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) UserManagementService(org.exist.xmldb.UserManagementService) Test(org.junit.Test)

Aggregations

EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)42 Collection (org.xmldb.api.base.Collection)31 Resource (org.xmldb.api.base.Resource)25 BinaryResource (org.xmldb.api.modules.BinaryResource)19 Test (org.junit.Test)18 UserManagementService (org.exist.xmldb.UserManagementService)16 XMLResource (org.xmldb.api.modules.XMLResource)13 XmldbURI (org.exist.xmldb.XmldbURI)12 URISyntaxException (java.net.URISyntaxException)11 Database (org.xmldb.api.base.Database)7 EXistResource (org.exist.xmldb.EXistResource)6 ExtendedResource (org.exist.xmldb.ExtendedResource)6 XMLDBException (org.xmldb.api.base.XMLDBException)5 Path (java.nio.file.Path)3 IndexQueryService (org.exist.xmldb.IndexQueryService)3 XPathException (org.exist.xquery.XPathException)3 InputStream (java.io.InputStream)2 BuildException (org.apache.tools.ant.BuildException)2 AnyURIValue (org.exist.xquery.value.AnyURIValue)2 ResourceSet (org.xmldb.api.base.ResourceSet)2