0

I like to explore the contents of my triplestores with either the rrdf or SPARQL packages in R. I believe they use cURL under the hood. They can take additional parameters, beyond the endpoint address and the query itself.

Here's GraphDB's notes on cURL-based queries: http://graphdb.ontotext.com/documentation/standard/quick-start-guide.html#query-data-programmatically

I could swear I connected to some password-protected triplestore from R in the past, but I can't remember how I did it. It might have been Stardog or Blazegraph.

I'll be connecting over a VPN. I hope that I can relax the usual rule about not embedding sensitive data (like a password) in a plain text URL.

  • Can I connect to a password-protected GraphDB (or any other RDF4J compliant triplestore) by including the username and password as part of the URL?
  • Or, can I establish an authenticated connection/session with GraphDB over cURL, as opposed to establishing a secure connection within some Java or Scala code?
Mark Miller
  • 3,011
  • 1
  • 14
  • 34
  • 1
    Ideally you will not want to sent your username/password as part of the url since someone can intercept it. What you need is to have SSL enabled on your graphdb server, though that does not seem trivial to do. Graphdb runs in Tomcat, but the normal Tomcat config files do not seem to be accessible. Seems like they have a Java class that starts Tomcat which means the config files are somewhere hidden in a library. The graphdb documentation is a bit sketchy in this regard. – Henriette Harmse Dec 05 '17 at 12:20
  • Yes, good point about URL interception. I just added that I'll be connecting over a VPN. – Mark Miller Dec 05 '17 at 13:11
  • 1
    @MarkMiller, HTH: https://stackoverflow.com/a/46338252/7879193 – Stanislav Kralin Mar 01 '18 at 19:13

1 Answers1

1

From RCurl: HTTP Authentication When Site Responds With HTTP 401 Code Without WWW-Authenticate:

the key is specifying the type of authentication (httpauth) as a bitmap option (1L), to be passed to rCURL.

library(SPARQL)

graphdb.address.port <- "http://localhost:7200"

selected.repo <- "mymedicalrecrods"

sparql.base <-
  paste0(graphdb.address.port, "/repositories/", selected.repo)

sparql.prefixes <- ""

api.user <- "markmiller"
api.pass <- rstudioapi::askForPassword()

placeholder.q <- paste0(
'
PREFIX owl: <http://www.w3.org/2002/07/owl#>
select *
where {
    graph ?g {
        ?s ?p ?o
    }
}
limit 9
')

sparql.result <-
  SPARQL::SPARQL(
    url = sparql.base,
    query = placeholder.q,
    curl_args = list('userpwd' = paste0(api.user,":", api.pass), "httpauth" = 1L)
  )
sparql.result<- sparql.result$results
Mark Miller
  • 3,011
  • 1
  • 14
  • 34