Search in sources :

Example 81 with PermissionDeniedException

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

the class GMLHSQLIndexWorker method getGeometriesForNodes.

@Override
protected Geometry[] getGeometriesForNodes(DBBroker broker, NodeSet contextSet, boolean getEPSG4326, Connection conn) throws SQLException {
    // TODO : generate it in AbstractGMLJDBCIndexWorker
    String docConstraint = "";
    boolean refine_query_on_doc = false;
    if (contextSet != null) {
        if (contextSet.getDocumentSet().getDocumentCount() <= index.getMaxDocsInContextToRefineQuery()) {
            DocumentImpl doc;
            Iterator<DocumentImpl> it = contextSet.getDocumentSet().getDocumentIterator();
            doc = it.next();
            docConstraint = "(DOCUMENT_URI = '" + doc.getURI().toString() + "')";
            while (it.hasNext()) {
                doc = it.next();
                docConstraint = docConstraint + " OR (DOCUMENT_URI = '" + doc.getURI().toString() + "')";
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Refine query on documents is {}", refine_query_on_doc ? "enabled." : "disabled.");
    }
    PreparedStatement ps = conn.prepareStatement("SELECT " + (getEPSG4326 ? "EPSG4326_WKB" : "WKB") + ", DOCUMENT_URI, NODE_ID_UNITS, NODE_ID" + " FROM " + GMLHSQLIndex.TABLE_NAME + (refine_query_on_doc ? " WHERE " + docConstraint : ""));
    ResultSet rs = null;
    try {
        rs = ps.executeQuery();
        Geometry[] result = new Geometry[contextSet.getLength()];
        int index = 0;
        while (rs.next()) {
            DocumentImpl doc = null;
            try {
                doc = (DocumentImpl) broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));
            } catch (PermissionDeniedException e) {
                LOG.debug(e);
                result[index++] = null;
                // Ignore since the broker has no right on the document
                continue;
            }
            if (contextSet == null || refine_query_on_doc || contextSet.getDocumentSet().contains(doc.getDocId())) {
                NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
                NodeProxy p = new NodeProxy(doc, nodeId);
                // VirtualNodeSet when on the DESCENDANT_OR_SELF axis
                if (contextSet.get(p) != null) {
                    Geometry geometry = wkbReader.read(rs.getBytes(1));
                    result[index++] = geometry;
                }
            }
        }
        return result;
    } catch (ParseException e) {
        // Transforms the exception into an SQLException.
        // Very unlikely to happen though...
        SQLException ee = new SQLException(e.getMessage());
        ee.initCause(e);
        throw ee;
    } finally {
        if (rs != null)
            rs.close();
        if (ps != null)
            ps.close();
    }
}
Also used : DLN(org.exist.numbering.DLN) Geometry(com.vividsolutions.jts.geom.Geometry) NodeId(org.exist.numbering.NodeId) PermissionDeniedException(org.exist.security.PermissionDeniedException) ParseException(com.vividsolutions.jts.io.ParseException)

Example 82 with PermissionDeniedException

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

the class RangeIndexWorker method removeCollection.

@Override
public void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException {
    if (LOG.isDebugEnabled())
        LOG.debug("Removing collection {}", collection.getURI());
    IndexWriter writer = null;
    try {
        writer = index.getWriter();
        for (Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
            DocumentImpl doc = i.next();
            final BytesRefBuilder bytes = new BytesRefBuilder();
            NumericUtils.intToPrefixCoded(doc.getDocId(), 0, bytes);
            Term dt = new Term(FIELD_DOC_ID, bytes.toBytesRef());
            writer.deleteDocuments(dt);
        }
    } catch (IOException | PermissionDeniedException | LockException e) {
        LOG.error("Error while removing lucene index: {}", e.getMessage(), e);
    } finally {
        index.releaseWriter(writer);
        if (reindex) {
            try {
                index.sync();
            } catch (DBException e) {
                LOG.warn("Exception during reindex: {}", e.getMessage(), e);
            }
        }
        mode = ReindexMode.STORE;
    }
    if (LOG.isDebugEnabled())
        LOG.debug("Collection removed.");
}
Also used : DBException(org.exist.storage.btree.DBException) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) LockException(org.exist.util.LockException) PermissionDeniedException(org.exist.security.PermissionDeniedException) IOException(java.io.IOException) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 83 with PermissionDeniedException

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

the class RewriteConfig method configure.

private void configure(final String controllerConfig) throws ServletException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Loading XQueryURLRewrite configuration from {}", controllerConfig);
    }
    if (controllerConfig.startsWith(XmldbURI.XMLDB_URI_PREFIX)) {
        try (final DBBroker broker = urlRewrite.getBrokerPool().get(Optional.ofNullable(urlRewrite.getDefaultUser()))) {
            try (final LockedDocument lockedDocument = broker.getXMLResource(XmldbURI.create(controllerConfig), LockMode.READ_LOCK)) {
                final DocumentImpl doc = lockedDocument == null ? null : lockedDocument.getDocument();
                if (doc != null) {
                    parse(doc);
                }
            }
        } catch (final EXistException | PermissionDeniedException e) {
            throw new ServletException("Failed to parse controller.xml: " + e.getMessage(), e);
        }
    } else {
        try {
            final Path d = Paths.get(urlRewrite.getConfig().getServletContext().getRealPath("/")).normalize();
            final Path configFile = d.resolve(controllerConfig);
            if (Files.isReadable(configFile)) {
                final Document doc = parseConfig(configFile);
                parse(doc);
            }
        } catch (final ParserConfigurationException | IOException | SAXException e) {
            throw new ServletException("Failed to parse controller.xml: " + e.getMessage(), e);
        }
    }
    urlRewrite.clearCaches();
}
Also used : Path(java.nio.file.Path) EXistException(org.exist.EXistException) IOException(java.io.IOException) Document(org.w3c.dom.Document) LockedDocument(org.exist.dom.persistent.LockedDocument) DocumentImpl(org.exist.dom.persistent.DocumentImpl) SAXException(org.xml.sax.SAXException) ServletException(javax.servlet.ServletException) DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) PermissionDeniedException(org.exist.security.PermissionDeniedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 84 with PermissionDeniedException

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

the class RpcConnection method executeT.

@Override
public Map<String, Object> executeT(final String pathToQuery, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
    final long startTime = System.currentTimeMillis();
    final Optional<String> sortBy = Optional.ofNullable(parameters.get(RpcAPI.SORT_EXPR)).map(Object::toString);
    return this.<Map<String, Object>>readDocument(XmldbURI.createInternal(pathToQuery)).apply((document, broker, transaction) -> {
        final BinaryDocument xquery = (BinaryDocument) document;
        if (xquery.getResourceType() != DocumentImpl.BINARY_FILE) {
            throw new EXistException("Document " + pathToQuery + " is not a binary resource");
        }
        if (!xquery.getPermissions().validate(user, Permission.READ | Permission.EXECUTE)) {
            throw new PermissionDeniedException("Insufficient privileges to access resource");
        }
        final Source source = new DBSource(broker, xquery, true);
        try {
            final Map<String, Object> rpcResponse = this.<Map<String, Object>>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> queryResultToTypedRpcResponse(startTime, doQuery(broker, compiledQuery, null, parameters), sortBy));
            return rpcResponse;
        } catch (final XPathException e) {
            throw new EXistException(e);
        }
    });
}
Also used : DBSource(org.exist.source.DBSource) PermissionDeniedException(org.exist.security.PermissionDeniedException) EXistException(org.exist.EXistException) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) DBSource(org.exist.source.DBSource) InputSource(org.xml.sax.InputSource)

Example 85 with PermissionDeniedException

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

the class RpcConnection method queryPT.

private Map<String, Object> queryPT(final String xquery, final XmldbURI docUri, final String s_id, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
    final Source source = new StringSource(xquery);
    final Optional<String> sortBy = Optional.ofNullable(parameters.get(RpcAPI.SORT_EXPR)).map(Object::toString);
    return withDb((broker, transaction) -> {
        final long startTime = System.currentTimeMillis();
        final NodeSet nodes;
        if (docUri != null && s_id != null) {
            nodes = this.<NodeSet>readDocument(broker, transaction, docUri).apply((document, broker1, transaction1) -> {
                final Object[] docs = new Object[1];
                docs[0] = docUri.toString();
                parameters.put(RpcAPI.STATIC_DOCUMENTS, docs);
                if (s_id.length() > 0) {
                    final NodeId nodeId = factory.getBrokerPool().getNodeFactory().createFromString(s_id);
                    final NodeProxy node = new NodeProxy(document, nodeId);
                    final NodeSet nodeSet = new ExtArrayNodeSet(1);
                    nodeSet.add(node);
                    return nodeSet;
                } else {
                    return null;
                }
            });
        } else {
            nodes = null;
        }
        try {
            final Map<String, Object> rpcResponse = this.<Map<String, Object>>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> queryResultToTypedRpcResponse(startTime, doQuery(broker, compiledQuery, nodes, parameters), sortBy));
            return rpcResponse;
        } catch (final XPathException e) {
            throw new EXistException(e);
        }
    });
}
Also used : Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) LockMode(org.exist.storage.lock.Lock.LockMode) Txn(org.exist.storage.txn.Txn) ValidationReport(org.exist.validation.ValidationReport) EXistOutputKeys(org.exist.storage.serializers.EXistOutputKeys) StringSource(org.exist.source.StringSource) TemporaryFileManager(org.exist.util.io.TemporaryFileManager) URISyntaxException(java.net.URISyntaxException) ManagedCollectionLock(org.exist.storage.lock.ManagedCollectionLock) Modification(org.exist.xupdate.Modification) PermissionDeniedException(org.exist.security.PermissionDeniedException) XmlRpcDocumentFunction(org.exist.xmlrpc.function.XmlRpcDocumentFunction) org.xmldb.api.base(org.xmldb.api.base) java.nio.file(java.nio.file) EXistSchemaType(org.exist.security.EXistSchemaType) org.exist.xquery(org.exist.xquery) Tuple(com.evolvedbinary.j8fu.tuple.Tuple.Tuple) Version(org.exist.Version) PreserveType(org.exist.storage.DBBroker.PreserveType) SerializerPool(org.exist.util.serializer.SerializerPool) Namespaces(org.exist.Namespaces) SchemaType(org.exist.security.SchemaType) DigestType(org.exist.util.crypto.digest.DigestType) Collection(org.exist.collections.Collection) NodeImpl(org.exist.dom.memtree.NodeImpl) SystemTaskJob(org.exist.scheduler.SystemTaskJob) SystemTaskJobImpl(org.exist.scheduler.impl.SystemTaskJobImpl) ACEAider(org.exist.security.internal.aider.ACEAider) AttributesImpl(org.xml.sax.helpers.AttributesImpl) PermissionFactory(org.exist.security.PermissionFactory) ManagedDocumentLock(org.exist.storage.lock.ManagedDocumentLock) GroupAider(org.exist.security.internal.aider.GroupAider) java.util.concurrent(java.util.concurrent) AXSchemaType(org.exist.security.AXSchemaType) SupplierE(com.evolvedbinary.j8fu.function.SupplierE) StandardOpenOption(java.nio.file.StandardOpenOption) GuardedBy(javax.annotation.concurrent.GuardedBy) StandardCharsets(java.nio.charset.StandardCharsets) SecurityManager(org.exist.security.SecurityManager) Logger(org.apache.logging.log4j.Logger) XUpdateProcessor(org.exist.xupdate.XUpdateProcessor) LockManager(org.exist.storage.lock.LockManager) SAXException(org.xml.sax.SAXException) ShutdownTask(org.exist.scheduler.impl.ShutdownTask) Restore(org.exist.backup.Restore) SAXSerializer(org.exist.util.serializer.SAXSerializer) java.util(java.util) QName(org.exist.dom.QName) org.exist.xquery.value(org.exist.xquery.value) org.exist.dom.persistent(org.exist.dom.persistent) Function2E(com.evolvedbinary.j8fu.function.Function2E) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) XmlRpcCollectionFunction(org.exist.xmlrpc.function.XmlRpcCollectionFunction) LockedDocumentMap(org.exist.storage.lock.LockedDocumentMap) Account(org.exist.security.Account) Source(org.exist.source.Source) org.exist.storage(org.exist.storage) ACLPermission(org.exist.security.ACLPermission) Charset(java.nio.charset.Charset) DBSource(org.exist.source.DBSource) Subject(org.exist.security.Subject) XmldbURI(org.exist.xmldb.XmldbURI) EXistException(org.exist.EXistException) Validator(org.exist.validation.Validator) Permission(org.exist.security.Permission) Nullable(javax.annotation.Nullable) InputSource(org.xml.sax.InputSource) RestoreListener(org.exist.backup.restore.listener.RestoreListener) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Group(org.exist.security.Group) Backup(org.exist.backup.Backup) XmlRpcFunction(org.exist.xmlrpc.function.XmlRpcFunction) Sync(org.exist.storage.sync.Sync) OutputKeys(javax.xml.transform.OutputKeys) UserAider(org.exist.security.internal.aider.UserAider) Function3E(com.evolvedbinary.j8fu.function.Function3E) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) MessageDigest(org.exist.util.crypto.digest.MessageDigest) HTTPUtils(org.exist.xquery.util.HTTPUtils) DocumentType(org.w3c.dom.DocumentType) Lock(java.util.concurrent.locks.Lock) java.io(java.io) NodeId(org.exist.numbering.NodeId) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CollectionConfigurationException(org.exist.collections.CollectionConfigurationException) XmldbURL(org.exist.protocolhandler.xmldb.XmldbURL) org.exist.util(org.exist.util) Serializer(org.exist.storage.serializers.Serializer) BEGIN_PROTECTED_MAX_LOCKING_RETRIES(org.exist.xmldb.EXistXPathQueryService.BEGIN_PROTECTED_MAX_LOCKING_RETRIES) EmbeddedInputStream(org.exist.protocolhandler.embedded.EmbeddedInputStream) XmlRpcCompiledXQueryFunction(org.exist.xmlrpc.function.XmlRpcCompiledXQueryFunction) ConsumerE(com.evolvedbinary.j8fu.function.ConsumerE) LogManager(org.apache.logging.log4j.LogManager) EXistException(org.exist.EXistException) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) DBSource(org.exist.source.DBSource) InputSource(org.xml.sax.InputSource) NodeId(org.exist.numbering.NodeId) StringSource(org.exist.source.StringSource)

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