Search in sources :

Example 51 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class XMLDBSecurityTest method groupRemoveCollection_canWriteParent.

@Test
public void groupRemoveCollection_canWriteParent() throws XMLDBException {
    final Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", "admin", "");
    final CollectionManagementService cms = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
    cms.removeCollection("securityTest1");
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) Test(org.junit.Test)

Example 52 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class XMLDBSecurityTest method cannotCreateBinaryResourceWithoutWritePermissionOnParentCollection.

@Test(expected = XMLDBException.class)
public void cannotCreateBinaryResourceWithoutWritePermissionOnParentCollection() 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.createResource("other.bin", BinaryResource.RESOURCE_TYPE);
    resource.setContent("binary".getBytes());
    test.storeResource(resource);
}
Also used : 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 53 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class XMLDBSecurityTest method ownerChownUidResource.

/**
 * Owner can NOT change the owner uid of a resource
 *
 * As the user 'test1' attempt to change the
 * ownership uid of /db/securityTest1/test.xml
 * to 'test2' user
 */
@Test(expected = XMLDBException.class)
public void ownerChownUidResource() throws XMLDBException {
    final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
    final Resource resource = test.getResource("test.xml");
    final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
    // attempt to change uid ownership of /db/securityTest1/test.xml to the test2 user
    final Account test2 = ums.getAccount("test2");
    ums.chown(resource, test2);
}
Also used : 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 54 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class XMLDBSecurityTest method groupCreateResource.

@Test
public void groupCreateResource() throws XMLDBException {
    final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test2", "test2");
    Resource resource = test.createResource("createdByTest2.xml", XMLResource.RESOURCE_TYPE);
    resource.setContent("<testMe/>");
    test.storeResource(resource);
    resource = test.getResource("createdByTest2.xml");
    assertNotNull(resource);
    assertEquals("<testMe/>", resource.getContent().toString());
}
Also used : 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 55 with Collection

use of org.xmldb.api.base.Collection in project exist by eXist-db.

the class XMLDBSecurityTest method groupNonMemberChownGidResource.

/**
 * Group Member can NOT change owner gid of a resource
 * to a group of which we are NOT a member
 *
 * As the user 'test2' (who is in the group users)
 * attempt to change ownership gid of /db/securityTest1/test.xml
 * to the group 'guest' (of which they are NOT a member)
 */
@Test(expected = XMLDBException.class)
public void groupNonMemberChownGidResource() throws XMLDBException {
    final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test2", "test2");
    final Resource resource = test.getResource("test.xml");
    final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
    // attempt to take gid ownership of /db/securityTest1/test.xml
    ums.chgrp(resource, "guest");
}
Also used : 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

Collection (org.xmldb.api.base.Collection)352 XMLResource (org.xmldb.api.modules.XMLResource)140 Test (org.junit.Test)115 Resource (org.xmldb.api.base.Resource)114 UserManagementService (org.exist.xmldb.UserManagementService)91 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)85 BinaryResource (org.xmldb.api.modules.BinaryResource)80 XMLDBException (org.xmldb.api.base.XMLDBException)73 ResourceSet (org.xmldb.api.base.ResourceSet)55 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)48 XPathQueryService (org.xmldb.api.modules.XPathQueryService)31 EXistResource (org.exist.xmldb.EXistResource)28 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)20 Before (org.junit.Before)20 URISyntaxException (java.net.URISyntaxException)18 Path (java.nio.file.Path)18 InputStream (java.io.InputStream)17 BuildException (org.apache.tools.ant.BuildException)14 XmldbURI (org.exist.xmldb.XmldbURI)13 Account (org.exist.security.Account)10