具有受保护的SPARQL端点的联合查询 [英] Federated query with secured SPARQL endpoint

查看:105
本文介绍了具有受保护的SPARQL端点的联合查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Fuseki端点对Jena使用联合查询.使用SPARQL查询中的 SERVICE 关键字,我正在连接到Stardog端点.由于它是一个受保护的URL,因此端点的指定如下: http://admin:admin @ url .由于这是不安全的,Jena会显示以下消息:

I'm trying to use federated queries with Jena via a Fuseki endpoint. With the SERVICE keyword in my SPARQL query, I'm connecting to a Stardog endpoint. As it's a secured URL, the endpoint is specified as follows: http://admin:admin@url. As this is not secure, Jena shows the following message:

Code: 36/HAS_PASSWORD in USER: Including passwords in URIs is deprecated.

根据 docs ,您可以指定 srv:queryAuthUser srv:queryAuthPwd 作为凭据.有什么方法可以直接在SPARQL查询中执行此操作吗?还是可以在Fuseki(ttl文件)中配置它?

According to the docs, you can specify srv:queryAuthUser and srv:queryAuthPwd for the credentials. Is there any way to do this directly in the SPARQL query? Or, can it be configured in Fuseki (ttl file)?

编辑

当我使用@RobV的解决方案时,服务上下文似乎没有被拾取.这是上下文的样子:

When I use @RobV's solution, the service context doesn't seem to be picked up. This is what the context looks like:

symbol:http://jena.hpl.hp.com/ARQ#regexImpl = symbol:http://jena.hpl.hp.com/ARQ#javaRegex
symbol:http://jena.hpl.hp.com/ARQ#constantBNodeLabels = true
symbol:http://jena.hpl.hp.com/ARQ#strictGraph = false
symbol:http://jena.hpl.hp.com/ARQ#strictSPARQL = false
symbol:http://jena.hpl.hp.com/ARQ#stageGenerator = com.hp.hpl.jena.tdb.solver.StageGeneratorDirectTDB@6f2dd58d
symbol:http://jena.hpl.hp.com/ARQ#enablePropertyFunctions = true
symbol:http://jena.hpl.hp.com/ARQ#romanNumerals = false
symbol:http://jena.hpl.hp.com/ARQ#optFilterPlacement = false
symbol:http://jena.hpl.hp.com/ARQ#registryPropertyFunctions = com.hp.hpl.jena.sparql.pfunction.PropertyFunctionRegistry@6f05ca41
symbol:http://jena.hpl.hp.com/ARQ/system#opExecutorFactory = com.hp.hpl.jena.tdb.solver.OpExecutorTDB$1@2a1f5501

当我保持Fuseki配置不变,并在我的业务层中添加服务上下文时,似乎确实添加了服务上下文:

When I leave the Fuseki config as is, and add the service context in my business layer, the service context does seem to be added:

symbol:http://jena.hpl.hp.com/Service#serviceContext = {http://host:5820/db/query=symbol:http://jena.hpl.hp.com/Service#queryAuthPwd = usr
symbol:http://jena.hpl.hp.com/Service#queryAuthUser = pwd}

无论如何,我在执行联合查询时仍会收到未经授权的消息.

Eitherway, I'm still getting an unauthorized message when I execute a federated query.

推荐答案

没有办法直接在SPARQL查询中做到这一点

No there is no way to do this directly in the SPARQL query

理论上,您可以使用Fuseki配置文件中的ja:context属性来指定上下文属性.但是实际上,这是行不通的,因为服务上下文是嵌套上下文,并且汇编程序当前不支持嵌套上下文.

In theory you could use the ja:context property in the Fuseki configuration file to specify context properties. However in practise this does not work because a service context is a nested context and the assembler does not support nested contexts currently.

但是,您可以使用ja:loadClass机制来加载自定义类,该类将添加到执行必要的静态初始化的类路径中.

However what you can do instead is to to use the ja:loadClass mechanism to load a custom class that you add to the class path which does the necessary static initialisation e.g.

[] rdf:type fuseki:Server ;
   ja:loadClass "com.example.YourInitializer" ;
   fuseki:services (
     # Whatever services you are defining
   ) .

请注意,您必须将初始化程序与代表fuseki:Server实例的主题相关联,否则可能无法处理ja:loadClass三元组.

Note that you MUST associate your initialiser with the subject that represents the fuseki:Server instance otherwise the ja:loadClass triple may not get processed.

然后:

package org.apache.jena.playground;

import java.util.HashMap;
import java.util.Map;

import com.hp.hpl.jena.query.ARQ;
import com.hp.hpl.jena.sparql.engine.http.Service;
import com.hp.hpl.jena.sparql.util.Context;

public class StardogInitializer {

    public static void init() {
        // Prepare Stardog specific context
        Context stardogContext = new Context();
        stardogContext.set(Service.queryAuthUser, "admin");
        stardogContext.set(Service.queryAuthPwd, "admin");

        // Associate context with your endpoint URL
        Map<String, Context> serviceContexts = new HashMap<>();
        // temp here is the name of the Stardog database to be queried
        serviceContexts.put("http://localhost:5820/temp/query", stardogContext);

        // Associate service contexts with the global ARQ context
        ARQ.getContext().set(Service.serviceContext, serviceContexts);
    }
}

请注意,该方法必须是静态的,并且需要调用init()才能使Fuseki调用它.

Note that the method needs to be static and needs to be called init() in order for Fuseki to invoke it.

使用此修改后的设置,我能够成功查询我的本地Stardog服务器.

With this revised setup I was able to successfully query my local Stardog server.

这篇关于具有受保护的SPARQL端点的联合查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆