Package org.exist.xmldb

Examples of org.exist.xmldb.CollectionManagementServiceImpl


     *      -> /db/securityTest3/copy-of-source
     */
    @Test
    public void copyCollectionWithResource_doesNotPreservePermissions() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl) 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
        final Resource resSource = source.createResource("source.xml", XMLResource.RESOURCE_TYPE);
        resSource.setContent("<test/>");
        source.storeResource(resSource);

        //as the 'test3' user copy the collection
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test3", "test3");
        cms = (CollectionManagementServiceImpl) test.getService("CollectionManagementService", "1.0");
        cms.copy("/db/securityTest3/source", "/db/securityTest3", "copy-of-source");


        UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
        final Collection copyOfSource = test.getChildCollection("copy-of-source");
        Permission permissions = ums.getPermissions(copyOfSource);
View Full Code Here


     *      -> /db/securityTest3/copy-of-source
     */
    @Test
    public void copyCollectionWithResources_withSubCollectionWithResource_doesNotPreservePermissions() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl) 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);
       
        //create sub-collection "sub" owned by "test1", and group "users" in /db/securityTest3/source
        CollectionManagementService cms1 = (CollectionManagementServiceImpl)source.getService("CollectionManagementService", "1.0");
        Collection sub = cms1.createCollection("sub");
       
        //create resource owned by "test1", and group "users" in /db/securityTest3/source/sub1
        Resource resSub = sub.createResource("sub1.xml", XMLResource.RESOURCE_TYPE);
        resSub.setContent("<test-sub/>");
        sub.storeResource(resSub);

        //as the 'test3' user copy the collection
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test3", "test3");
        cms = (CollectionManagementServiceImpl) 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);
       
View Full Code Here

     * resource will be preserved
     */
    @Test
    public void copyCollectionWithResources_destResourceExists_destResourceIsWritable_preservePermissions() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl) 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("<test1/>");
        source.storeResource(resSource);

        resSource = source.createResource("source2.xml", XMLResource.RESOURCE_TYPE);
        resSource.setContent("<test2/>");
        source.storeResource(resSource);
       
        //pre-create the destination and set writable by all
        final Collection dest = cms.createCollection("copy-of-source");
        UserManagementService ums = (UserManagementService) dest.getService("UserManagementService", "1.0");
        ums.chmod(0777);
       
        //pre-create a destination resource and set access for all
        Resource resDestSource1 = dest.createResource("source1.xml", XMLResource.RESOURCE_TYPE);
        resDestSource1.setContent("<old/>");
        dest.storeResource(resDestSource1);
        ums.chmod(resDestSource1, 0777);
       
        //as the 'test3' user copy the collection
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest3", "test3", "test3");
        cms = (CollectionManagementServiceImpl) 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);
        ums = (UserManagementService) copyOfSource.getService("UserManagementService", "1.0");
View Full Code Here

    }

    @Test
    public void noSetGid_copyCollection_collectionGroupIsUsersPrimaryGroup() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");

        //create the /db/securityTest2/src collection
        Collection srcCollection = cms.createCollection("src");

        //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 copy /db/securityTest2/src to /db/securityTest2/parentCollection/src
        //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 and it should NOT have it's setGid bit set
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copy("src", "/db/securityTest2/parentCollection", "src");
        parentCollection = DatabaseManager.getCollection(baseUri + "/db/securityTest2/parentCollection", "test3", "test3");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        srcCollection = test.getChildCollection("src");
        final Collection destCollection = parentCollection.getChildCollection("src");
View Full Code Here

    }
   
    @Test
    public void setGid_copyCollection_collectionGroupInheritedFromParent() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        UserManagementService ums = (UserManagementService)test.getService("UserManagementService", "1.0");

        //create the /db/securityTest2/src collection with owner "test1:extusers" and default mode
        Collection srcCollection = cms.createCollection("src");
        ums = (UserManagementService)srcCollection.getService("UserManagementService", "1.0");
        ums.chgrp("extusers");

        //create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxrwsrwx"
        Collection parentCollection = cms.createCollection("parentCollection");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");
        ums.chmod("rwxrwsrwx");

        //now copy /db/securityTest2/src to /db/securityTest2/parentCollection/src
        //as "user3:guest", it should inherit the group ownership 'users' from the parent
        //collection which is setGid and it should have its setGid bit set
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copy("src", "/db/securityTest2/parentCollection", "src");
        parentCollection = DatabaseManager.getCollection(baseUri + "/db/securityTest2/parentCollection", "test3", "test3");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        final Collection destCollection = parentCollection.getChildCollection("src");
View Full Code Here


    @Test
    public void noSetGid_copyResource_resourceGroupIsUsersPrimaryGroup() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");

        //create the /db/securityTest2/test.xml resource
        Resource resource = test.createResource("test.xml", XMLResource.RESOURCE_TYPE);
        resource.setContent("<test/>");
        test.storeResource(resource);

        //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 copy /db/securityTest2/test.xml to /db/securityTest2/parentCollection/test.xml
        //as user3, it should have it's group set to the primary group of user3 i.e. 'guest'
        //as the collection is NOT setGid and it should not have the setGid bit
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copyResource("test.xml", "/db/securityTest2/parentCollection", "test.xml");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        parentCollection = test.getChildCollection("parentCollection");
        resource = parentCollection.getResource("test.xml");
View Full Code Here

    }

    @Test
    public void setGid_copyResource_resourceGroupInheritedFromParent() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");       
        UserManagementService ums = (UserManagementService)test.getService("UserManagementService", "1.0");

        //create the /db/securityTest2/test.xml resource
        Resource resource = test.createResource("test.xml", XMLResource.RESOURCE_TYPE);
        resource.setContent("<test/>");
        test.storeResource(resource);
        ums.chgrp(resource, "extusers");

        //create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxrwsrwx"
        Collection parentCollection = cms.createCollection("parentCollection");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");
        ums.chmod("rwxrwsrwx");

        //now copy /db/securityTest2/test.xml to /db/securityTest2/parentCollection/test.xml
        //as "user3:guest", it should inherit the group ownership 'users' from the parent collection which is setGid
        //and it should NOT have its setGid bit set as it is a resource
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copyResource("test.xml", "/db/securityTest2/parentCollection", "test.xml");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        parentCollection = test.getChildCollection("parentCollection");
        resource = parentCollection.getResource("test.xml");
View Full Code Here

                    log( msg, Project.MSG_ERR );
                }

            } else {
                log( "Create collection management service for collection " + base.getName(), Project.MSG_DEBUG );
                final CollectionManagementServiceImpl service = (CollectionManagementServiceImpl)base.getService( "CollectionManagementService", "1.0" );

                if( resource != null ) {
                    log( "Copying resource: " + resource, Project.MSG_INFO );
                    final Resource res = base.getResource( resource );

                    if( res == null ) {
                        final String msg = "Resource " + resource + " not found.";

                        if( failonerror ) {
                            throw( new BuildException( msg ) );
                        } else {
                            log( msg, Project.MSG_ERR );
                        }
                    } else {

                        //XmldbURI resource = XmldbURI.create(resource);
                        service.copyResource( XmldbURI.xmldbUriFor( resource ), XmldbURI.xmldbUriFor( destination ), XmldbURI.xmldbUriFor( name ) );
                    }

                } else {
                    log( "Copying collection: " + collection, Project.MSG_INFO );
                    service.copy( XmldbURI.xmldbUriFor( collection ), XmldbURI.xmldbUriFor( destination ), XmldbURI.xmldbUriFor( name ) );
                }
            }
        }
        catch( final XMLDBException e ) {
            final String msg = "XMLDB exception during copy: " + e.getMessage();
View Full Code Here

                final Resource resource = collection.getResource(doc.toString());
                if (resource == null) {
                    logger.error( "Resource " + doc + " not found");
                    throw new XPathException(this, "Resource " + doc + " not found");
                }
                final CollectionManagementServiceImpl service = (CollectionManagementServiceImpl) collection.getService("CollectionManagementService", "1.0");
                service.moveResource(doc, destination, null);
            } catch (final XMLDBException e) {
                logger.error(e.getMessage());
                throw new XPathException(this, "XMLDB exception caught: " + e.getMessage(), e);
            }
        } else {
            try {
                final CollectionManagementServiceImpl service = (CollectionManagementServiceImpl) collection.getService("CollectionManagementService", "1.0");
                service.move(XmldbURI.xmldbUriFor(collection.getName()),
                        destination, null);

            } catch (final XMLDBException e) {
                logger.error(e.getMessage());
                throw new XPathException(this, "Cannot move collection: " + e.getMessage(), e);
View Full Code Here

                final Resource resource = collection.getResource(doc.toString());
                if (resource == null) {
        logger.error("Resource " + doc + " not found");
                    throw new XPathException(this, "Resource " + doc + " not found");
                }
                final CollectionManagementServiceImpl service = (CollectionManagementServiceImpl) collection.getService("CollectionManagementService", "1.0");
                service.copyResource(doc, destination, null);
            } catch (final XMLDBException e) {
    logger.error("XMLDB exception caught: ", e);
                throw new XPathException(this, "XMLDB exception caught: " + e.getMessage(), e);
            }
           
        } else {
            try {
                final CollectionManagementServiceImpl service = (CollectionManagementServiceImpl) collection.getService("CollectionManagementService", "1.0");
                // DWES to check not sure about XmldbURI.xmldbUriFor() here.
                service.copy(XmldbURI.xmldbUriFor(collection.getName()), destination, null);

            } catch (final XMLDBException e) {
    logger.error("Cannot copy collection: ", e);
                throw new XPathException(this, "Cannot copy collection: " + e.getMessage(), e);
View Full Code Here

TOP

Related Classes of org.exist.xmldb.CollectionManagementServiceImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.