Search in sources :

Example 31 with Resource

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

the class XMLDBSecurityTest method worldAddResource.

// fails since guest has no write permissions
@Test(expected = XMLDBException.class)
public void worldAddResource() throws XMLDBException {
    final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "guest", "guest");
    final Resource resource = test.createResource("createdByGuest", XMLResource.RESOURCE_TYPE);
    resource.setContent("<testMe/>");
    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) Test(org.junit.Test)

Example 32 with Resource

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

the class XMLDBSecurityTest method noSetGid_createResource_resourceGroupIsUsersPrimaryGroup.

@Test
public void noSetGid_createResource_resourceGroupIsUsersPrimaryGroup() 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 "rwxrwxrwx"
    Collection parentCollection = cms.createCollection("parentCollection");
    UserManagementService ums = (UserManagementService) parentCollection.getService("UserManagementService", "1.0");
    ums.chmod("rwxrwxrwx");
    // now create the sub-resource /db/securityTest2/parentCollection/test.xml
    // as "user3:guest", it should have it's group set to the primary group of user3 i.e. 'guest'
    // as the collection is NOT setGid, the file should NOT have the setGid bit set
    parentCollection = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest2/parentCollection", "test3", "test3");
    ums = (UserManagementService) parentCollection.getService("UserManagementService", "1.0");
    Resource resource = parentCollection.createResource("test.xml", XMLResource.RESOURCE_TYPE);
    resource.setContent("<test/>");
    parentCollection.storeResource(resource);
    final Permission permissions = ums.getPermissions(resource);
    assertEquals("guest", permissions.getGroup().getName());
    assertFalse(permissions.isSetGid());
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) 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 33 with Resource

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

the class XMLDBSecurityTest method dbaChownUidResource.

/**
 * DBA can change the owner uid of a resource
 *
 * As the user 'admin' (who is a DBA) attempt to change the
 * ownership uid of /db/securityTest1/test.xml
 * to 'test2' user
 */
@Test
public void dbaChownUidResource() throws XMLDBException {
    final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "admin", "");
    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 34 with Resource

use of org.xmldb.api.base.Resource 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());
}
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 35 with Resource

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

the class XMLDBSecurityTest method groupMemberChownGidResource.

/**
 * Group Member can NOT change the owner gid of a resource
 * to a group of which they are a member
 *
 * As the user 'test2' (who is in the group users)
 * attempt to change ownership gid of /db/securityTest1/test.xml (which has uid 'test1' and gid 'users')
 * to the group 'test2-only' (of which they are a member)
 */
@Test(expected = XMLDBException.class)
public void groupMemberChownGidResource() 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 have user 'test2' take gid ownership of /db/securityTest1/test.xml (which is owned by test1:users)
    ums.chgrp(resource, "test2-only");
}
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

Resource (org.xmldb.api.base.Resource)173 XMLResource (org.xmldb.api.modules.XMLResource)126 Collection (org.xmldb.api.base.Collection)111 BinaryResource (org.xmldb.api.modules.BinaryResource)86 Test (org.junit.Test)77 UserManagementService (org.exist.xmldb.UserManagementService)52 ResourceSet (org.xmldb.api.base.ResourceSet)46 XMLDBException (org.xmldb.api.base.XMLDBException)38 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)32 EXistResource (org.exist.xmldb.EXistResource)27 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)25 XPathQueryService (org.xmldb.api.modules.XPathQueryService)18 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)16 Path (java.nio.file.Path)11 Database (org.xmldb.api.base.Database)11 XPathException (org.exist.xquery.XPathException)10 InputStream (java.io.InputStream)9 Source (javax.xml.transform.Source)9 BuildException (org.apache.tools.ant.BuildException)9 Diff (org.xmlunit.diff.Diff)9