Search in sources :

Example 86 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class XUpdateTest method startup.

@Before
public void startup() throws XMLDBException, IOException, URISyntaxException {
    col = existXmldbEmbeddedServer.getRoot().getChildCollection(XUPDATE_COLLECTION);
    if (col == null) {
        final CollectionManagementService collectionManagementService = (CollectionManagementService) existXmldbEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
        col = collectionManagementService.createCollection(XUPDATE_COLLECTION);
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        // change ownership to guest
        final Account guest = ums.getAccount("guest");
        ums.chown(guest, guest.getPrimaryGroup());
        ums.chmod(Permission.DEFAULT_COLLECTION_PERM);
    }
    addDocument(sourceFile);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) UserManagementService(org.exist.xmldb.UserManagementService)

Example 87 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class ExistXmldbEmbeddedServer method createCollection.

public Collection createCollection(final Collection collection, final String collectionName) throws XMLDBException {
    final CollectionManagementService collectionManagementService = (CollectionManagementService) collection.getService("CollectionManagementService", "1.0");
    Collection newCollection = collection.getChildCollection(collectionName);
    if (newCollection == null) {
        collectionManagementService.createCollection(collectionName);
    }
    final XmldbURI uri = XmldbURI.LOCAL_DB_URI.resolveCollectionPath(((EXistCollection) collection).getPathURI().append(collectionName));
    if (asGuest) {
        newCollection = DatabaseManager.getCollection(uri.toString(), TestUtils.GUEST_DB_USER, TestUtils.GUEST_DB_PWD);
    } else {
        newCollection = DatabaseManager.getCollection(uri.toString(), TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
    }
    return newCollection;
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) EXistCollection(org.exist.xmldb.EXistCollection) EXistCollection(org.exist.xmldb.EXistCollection) XmldbURI(org.exist.xmldb.XmldbURI)

Example 88 with CollectionManagementService

use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.

the class XMLDBSecurityTest method cleanup.

@After
public void cleanup() throws XMLDBException {
    final Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", "admin", "");
    final CollectionManagementService cms = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
    final Collection secTest1 = root.getChildCollection("securityTest1");
    if (secTest1 != null) {
        secTest1.close();
        cms.removeCollection("securityTest1");
    }
    final Collection secTest2 = root.getChildCollection("securityTest2");
    if (secTest2 != null) {
        secTest2.close();
        cms.removeCollection("securityTest2");
    }
    final Collection secTest3 = root.getChildCollection("securityTest3");
    if (secTest3 != null) {
        secTest3.close();
        cms.removeCollection("securityTest3");
    }
    final UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");
    // remove accounts 'test1', 'test2' and 'test3'
    removeAccounts(ums, new String[] { "test1", "test2", "test3" });
    // remove group 'users', 'extusers', 'test2-only'
    removeGroups(ums, new String[] { "users", "extusers", "test2-only" });
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) UserManagementService(org.exist.xmldb.UserManagementService) After(org.junit.After)

Example 89 with CollectionManagementService

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

Example 90 with CollectionManagementService

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

Aggregations

CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)148 Collection (org.xmldb.api.base.Collection)84 XMLResource (org.xmldb.api.modules.XMLResource)33 Resource (org.xmldb.api.base.Resource)25 Before (org.junit.Before)23 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)21 After (org.junit.After)21 Test (org.junit.Test)19 UserManagementService (org.exist.xmldb.UserManagementService)14 ResourceSet (org.xmldb.api.base.ResourceSet)14 BinaryResource (org.xmldb.api.modules.BinaryResource)13 XPathQueryService (org.xmldb.api.modules.XPathQueryService)9 Account (org.exist.security.Account)7 IndexQueryService (org.exist.xmldb.IndexQueryService)6 AfterClass (org.junit.AfterClass)6 Database (org.xmldb.api.base.Database)6 XMLDBException (org.xmldb.api.base.XMLDBException)6 Path (java.nio.file.Path)5 BeforeClass (org.junit.BeforeClass)5 InputStream (java.io.InputStream)4