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();
}
}
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.");
}
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();
}
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);
}
});
}
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);
}
});
}
Aggregations