Federated query with secured SPARQL endpoint

南笙酒味 提交于 2019-12-11 02:04:58

问题


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.

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)?

EDIT

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

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.


回答1:


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

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.

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
   ) .

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.

And then:

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);
    }
}

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

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



来源:https://stackoverflow.com/questions/28812206/federated-query-with-secured-sparql-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!