Search in sources :

Example 66 with XMLDBException

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

the class XmldbApiSecurityTest method createGroup.

@Override
protected void createGroup(String group_uid, String uid, String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + "/db", uid, pwd);
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        Group group = new GroupAider("exist", group_uid);
        ums.addGroup(group);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 67 with XMLDBException

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

the class XmldbApiSecurityTest method createBinResource.

@Override
protected void createBinResource(String resourceUri, byte[] content, String uid, String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
        Resource resource = col.createResource(getResourceName(resourceUri), BinaryResource.RESOURCE_TYPE);
        resource.setContent(content);
        col.storeResource(resource);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
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) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 68 with XMLDBException

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

the class XmldbApiSecurityTest method chmodCol.

@Override
protected void chmodCol(final String collectionUri, final String mode, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + collectionUri, uid, pwd);
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        ums.chmod(mode);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 69 with XMLDBException

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

the class RemoteDatabaseImplTest method testGetCollection.

@Test
public void testGetCollection() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException, SyntaxException, PermissionDeniedException {
    Class<?> cl = Class.forName(DB_DRIVER);
    Database database = (Database) cl.newInstance();
    DatabaseManager.registerDatabase(database);
    Collection rootCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION, "admin", "");
    CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0");
    Collection adminCollection = cms.createCollection(ADMIN_COLLECTION_NAME);
    UserManagementService ums = (UserManagementService) rootCollection.getService("UserManagementService", "1.0");
    if (ums != null) {
        Permission p = ums.getPermissions(adminCollection);
        p.setMode(Permission.USER_STRING + "=+read,+write," + Permission.GROUP_STRING + "=-read,-write," + Permission.OTHER_STRING + "=-read,-write");
        ums.setPermissions(adminCollection, p);
        Collection guestCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION + "/" + ADMIN_COLLECTION_NAME, "guest", "guest");
        Resource resource = guestCollection.createResource("testguest", "BinaryResource");
        resource.setContent("123".getBytes());
        try {
            guestCollection.storeResource(resource);
            fail();
        } catch (XMLDBException e) {
        }
        cms.removeCollection(ADMIN_COLLECTION_NAME);
    }
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Database(org.xmldb.api.base.Database) Permission(org.exist.security.Permission) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) Test(org.junit.Test)

Example 70 with XMLDBException

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

the class XPathUtil method getNode.

/**
 * Converts an XMLResource into a NodeProxy.
 *
 * @param broker The DBBroker to use to access the database
 * @param xres The XMLResource to convert
 * @return A NodeProxy for accessing the content represented by xres
 * @throws XPathException if an XMLDBException is encountered
 */
public static final NodeProxy getNode(DBBroker broker, XMLResource xres) throws XPathException {
    if (xres instanceof LocalXMLResource) {
        final LocalXMLResource lres = (LocalXMLResource) xres;
        try {
            return lres.getNode();
        } catch (final XMLDBException xe) {
            throw new XPathException("Failed to convert LocalXMLResource to node: " + xe.getMessage());
        }
    }
    DocumentImpl document;
    try {
        document = broker.getCollection(XmldbURI.xmldbUriFor(xres.getParentCollection().getName())).getDocument(broker, XmldbURI.xmldbUriFor(xres.getDocumentId()));
    } catch (final URISyntaxException xe) {
        throw new XPathException(xe);
    } catch (final XMLDBException xe) {
        throw new XPathException("Failed to get document for RemoteXMLResource: " + xe.getMessage());
    } catch (final PermissionDeniedException pde) {
        throw new XPathException("Failed to get document: " + pde.getMessage());
    }
    final NodeId nodeId = broker.getBrokerPool().getNodeFactory().createFromString(((RemoteXMLResource) xres).getNodeId());
    return new NodeProxy(document, nodeId);
}
Also used : LocalXMLResource(org.exist.xmldb.LocalXMLResource) NodeId(org.exist.numbering.NodeId) XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException) URISyntaxException(java.net.URISyntaxException) DocumentImpl(org.exist.dom.persistent.DocumentImpl) NodeProxy(org.exist.dom.persistent.NodeProxy)

Aggregations

XMLDBException (org.xmldb.api.base.XMLDBException)174 Collection (org.xmldb.api.base.Collection)66 Resource (org.xmldb.api.base.Resource)34 URISyntaxException (java.net.URISyntaxException)30 XMLResource (org.xmldb.api.modules.XMLResource)30 ResourceSet (org.xmldb.api.base.ResourceSet)23 BuildException (org.apache.tools.ant.BuildException)21 IOException (java.io.IOException)19 XPathException (org.exist.xquery.XPathException)18 PermissionDeniedException (org.exist.security.PermissionDeniedException)16 SAXException (org.xml.sax.SAXException)16 EXistException (org.exist.EXistException)15 UserManagementService (org.exist.xmldb.UserManagementService)15 XPathQueryService (org.xmldb.api.modules.XPathQueryService)13 BinaryResource (org.xmldb.api.modules.BinaryResource)12 ArrayList (java.util.ArrayList)11 Account (org.exist.security.Account)11 EXistResource (org.exist.xmldb.EXistResource)10 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)10 Properties (java.util.Properties)9