Search in sources :

Example 31 with PermissionDeniedException

use of org.exist.security.PermissionDeniedException in project exist by eXist-db.

the class FunUnparsedText method getSource.

private Source getSource(final String uriParam) throws XPathException {
    try {
        final URI uri = new URI(uriParam);
        if (uri.getFragment() != null) {
            throw new XPathException(this, ErrorCodes.FOUT1170, "href argument may not contain fragment identifier");
        }
        final Source source = SourceFactory.getSource(context.getBroker(), "", uri.toASCIIString(), false);
        if (source == null) {
            throw new XPathException(this, ErrorCodes.FOUT1170, "Could not find source for: " + uriParam);
        }
        if (source instanceof FileSource && !context.getBroker().getCurrentSubject().hasDbaRole()) {
            throw new PermissionDeniedException("non-dba user not allowed to read from file system");
        }
        return source;
    } catch (final IOException | PermissionDeniedException | URISyntaxException e) {
        throw new XPathException(this, ErrorCodes.FOUT1170, e.getMessage());
    }
}
Also used : FileSource(org.exist.source.FileSource) PermissionDeniedException(org.exist.security.PermissionDeniedException) URISyntaxException(java.net.URISyntaxException) XmldbURI(org.exist.xmldb.XmldbURI) URI(java.net.URI) FileSource(org.exist.source.FileSource) Source(org.exist.source.Source)

Example 32 with PermissionDeniedException

use of org.exist.security.PermissionDeniedException in project exist by eXist-db.

the class JSON method parseResource.

private Sequence parseResource(Sequence href, String handleDuplicates, JsonFactory factory) throws XPathException {
    if (href.isEmpty()) {
        return Sequence.EMPTY_SEQUENCE;
    }
    try {
        String url = href.getStringValue();
        if (url.indexOf(':') == Constants.STRING_NOT_FOUND) {
            url = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + url;
        }
        final Source source = SourceFactory.getSource(context.getBroker(), "", url, false);
        if (source == null) {
            throw new XPathException(this, ErrorCodes.FOUT1170, "failed to load json doc from URI " + url);
        }
        try (final InputStream is = source.getInputStream();
            final JsonParser parser = factory.createParser(is)) {
            final Item result = readValue(context, parser, handleDuplicates);
            return result == null ? Sequence.EMPTY_SEQUENCE : result.toSequence();
        }
    } catch (IOException | PermissionDeniedException e) {
        throw new XPathException(this, ErrorCodes.FOUT1170, e.getMessage());
    }
}
Also used : InputStream(java.io.InputStream) PermissionDeniedException(org.exist.security.PermissionDeniedException) IOException(java.io.IOException) Source(org.exist.source.Source) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 33 with PermissionDeniedException

use of org.exist.security.PermissionDeniedException in project exist by eXist-db.

the class TestDataGenerator method generate.

public Path[] generate(final DBBroker broker, final Collection collection, final String xqueryContent) throws SAXException {
    try {
        final DocumentSet docs = collection.allDocs(broker, new DefaultDocumentSet(), true);
        final XQuery service = broker.getBrokerPool().getXQueryService();
        final XQueryContext context = new XQueryContext(broker.getBrokerPool());
        context.declareVariable("filename", "");
        context.declareVariable("count", "0");
        context.setStaticallyKnownDocuments(docs);
        final String query = IMPORT + xqueryContent;
        final CompiledXQuery compiled = service.compile(context, query);
        for (int i = 0; i < count; i++) {
            generatedFiles[i] = Files.createTempFile(prefix, ".xml");
            context.declareVariable("filename", generatedFiles[i].getFileName().toString());
            context.declareVariable("count", new Integer(i));
            final Sequence results = service.execute(broker, compiled, Sequence.EMPTY_SEQUENCE);
            final Serializer serializer = broker.borrowSerializer();
            try (final Writer out = Files.newBufferedWriter(generatedFiles[i], StandardCharsets.UTF_8)) {
                final SAXSerializer sax = new SAXSerializer(out, outputProps);
                serializer.setSAXHandlers(sax, sax);
                for (final SequenceIterator iter = results.iterate(); iter.hasNext(); ) {
                    final Item item = iter.nextItem();
                    if (!Type.subTypeOf(item.getType(), Type.NODE)) {
                        continue;
                    }
                    serializer.toSAX((NodeValue) item);
                }
            } finally {
                broker.returnSerializer(serializer);
            }
        }
    } catch (final XPathException | PermissionDeniedException | LockException | IOException e) {
        LOG.error(e.getMessage(), e);
        throw new SAXException(e.getMessage(), e);
    }
    return generatedFiles;
}
Also used : DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) XPathException(org.exist.xquery.XPathException) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQueryContext(org.exist.xquery.XQueryContext) SAXException(org.xml.sax.SAXException) LockException(org.exist.util.LockException) PermissionDeniedException(org.exist.security.PermissionDeniedException) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) DocumentSet(org.exist.dom.persistent.DocumentSet) SAXSerializer(org.exist.util.serializer.SAXSerializer) SAXSerializer(org.exist.util.serializer.SAXSerializer) Serializer(org.exist.storage.serializers.Serializer)

Example 34 with PermissionDeniedException

use of org.exist.security.PermissionDeniedException in project exist by eXist-db.

the class Append method process.

@Override
public long process(Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException, TriggerException {
    final NodeList children = content;
    if (children.getLength() == 0) {
        return 0;
    }
    try {
        final StoredNode[] ql = selectAndLock(transaction);
        final NotificationService notifier = broker.getBrokerPool().getNotificationService();
        for (final StoredNode node : ql) {
            final DocumentImpl doc = node.getOwnerDocument();
            if (!doc.getPermissions().validate(broker.getCurrentSubject(), Permission.WRITE)) {
                throw new PermissionDeniedException("User '" + broker.getCurrentSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
            }
            node.appendChildren(transaction, children, child);
            doc.setLastModified(System.currentTimeMillis());
            modifiedDocuments.add(doc);
            broker.storeXMLResource(transaction, doc);
            notifier.notifyUpdate(doc, UpdateListener.UPDATE);
        }
        checkFragmentation(transaction, modifiedDocuments);
        return ql.length;
    } finally {
        // release all acquired locks
        unlockDocuments(transaction);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) NotificationService(org.exist.storage.NotificationService) PermissionDeniedException(org.exist.security.PermissionDeniedException) DocumentImpl(org.exist.dom.persistent.DocumentImpl) StoredNode(org.exist.dom.persistent.StoredNode)

Example 35 with PermissionDeniedException

use of org.exist.security.PermissionDeniedException in project exist by eXist-db.

the class Insert method process.

@Override
public long process(Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException, TriggerException {
    final NodeList children = content;
    if (children.getLength() == 0) {
        return 0;
    }
    try {
        final StoredNode[] ql = selectAndLock(transaction);
        final NotificationService notifier = broker.getBrokerPool().getNotificationService();
        final int len = children.getLength();
        if (LOG.isDebugEnabled()) {
            LOG.debug("found {} nodes to insert", len);
        }
        for (final StoredNode node : ql) {
            final DocumentImpl doc = node.getOwnerDocument();
            if (!doc.getPermissions().validate(broker.getCurrentSubject(), Permission.WRITE)) {
                throw new PermissionDeniedException("permission to update document denied");
            }
            final NodeImpl parent = (NodeImpl) getParent(node);
            switch(mode) {
                case INSERT_BEFORE:
                    parent.insertBefore(transaction, children, node);
                    break;
                case INSERT_AFTER:
                    parent.insertAfter(transaction, children, node);
                    break;
            }
            doc.setLastModified(System.currentTimeMillis());
            modifiedDocuments.add(doc);
            broker.storeXMLResource(transaction, doc);
            notifier.notifyUpdate(doc, UpdateListener.UPDATE);
        }
        checkFragmentation(transaction, modifiedDocuments);
        return ql.length;
    } finally {
        unlockDocuments(transaction);
    }
}
Also used : NodeImpl(org.exist.dom.persistent.NodeImpl) NodeList(org.w3c.dom.NodeList) NotificationService(org.exist.storage.NotificationService) PermissionDeniedException(org.exist.security.PermissionDeniedException) DocumentImpl(org.exist.dom.persistent.DocumentImpl) StoredNode(org.exist.dom.persistent.StoredNode)

Aggregations

PermissionDeniedException (org.exist.security.PermissionDeniedException)182 EXistException (org.exist.EXistException)82 XmldbURI (org.exist.xmldb.XmldbURI)70 IOException (java.io.IOException)58 DocumentImpl (org.exist.dom.persistent.DocumentImpl)48 Collection (org.exist.collections.Collection)44 DBBroker (org.exist.storage.DBBroker)41 Txn (org.exist.storage.txn.Txn)38 LockException (org.exist.util.LockException)35 SAXException (org.xml.sax.SAXException)35 LockedDocument (org.exist.dom.persistent.LockedDocument)31 XPathException (org.exist.xquery.XPathException)31 Permission (org.exist.security.Permission)23 URISyntaxException (java.net.URISyntaxException)22 TriggerException (org.exist.collections.triggers.TriggerException)22 Source (org.exist.source.Source)20 Path (java.nio.file.Path)19 Account (org.exist.security.Account)18 InputSource (org.xml.sax.InputSource)18 Sequence (org.exist.xquery.value.Sequence)17