Reputation: 68
I am trying to perform a SPARQL Insert in a Graph that I have loaded in Virtuoso, doing it trough a HTTP Request against the Virtuoso endpoint.
For the HTTP Request I am using axios, and I have already made some SPARQL Select queries succesfully, so my problem lays on the Authentication process that I need to do for updating the Graph.
After quite a lot of research, I have seen that Virtuoso has some paths enabled for different authentication proccesses:
http://<cname>/sparql-auth
(SQL authentication)http://<cname>/sparql-oauth
(OAuth)http://<cname>/sparql-graph-crud-auth
(OAuth CRUD)https://<cname>/sparql
and https://<cname>/sparql-webid
(WebID Protocol)I want to make it as simple as possible, so I have checked the http://<cname>/sparql-auth
and I have been able to log in and perform an Insert query succesfully. This means (I guess) that I do not have any permission problems on my user.
When I try to do it through the HTTP Request however, I am not able to authenticate my user properly, I do not know how to specify the username and the password in a correct way.
I have also discovered that Virtuoso has, by default, the Digest Authentication method activated, so I changed it to the Basic Authentication on the /sparql-auth
path as it is the easiest method for me. I have done this change using the http://<cname>/conductor
of Virtuoso.
And still, I am not able to authenticate myself correctly through the HTTP Get request, receiving the HTTP status code 401 (Unauthorized).
This is exatly how I make the Request:
axios.get('http://localhost:8890/sparql-auth?query=' + encodeURIComponent(pruebaInsertQuery),{
auth: { // This is provided by axios, to perform an HTTP Basic auth
username: 'myUserName',
password: 'myPassword'
},
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
I have gone through every tutorial and guide that Virtuoso has, but I'm really new in the SPARQL, RDF and Virtuoso world and I still get lost in everything.
Thank you in advance!!
Question edited due to some of the comments:
I have also tried it with a Post Request and nothing changes.
Another way I've tried is using the http://myUserName:myPassword@localhost:8890/sparql-auth
format, but I get the exact same response.
I am not sure at all about if I am passing the exact same strings via the axios
call and through the /sparql-auth
path. Virtuoso may use some encoding that I have not found about, and I am not being able to find any example of an SQL authentication for Virtuoso (the type of authentication I am trying to use), not even for the Digest Authentication method, which is the default method of Virtuoso.
Nothing appears in my Virtuoso.log regarding the HTTP Requests, not even the succesful ones. I will research more about this as it may be because of the configuration that I have.
Thank you for the help!
Finally found a way for getting the result I want:
I have not been able to find a solution to the authentication problem I stated here, but I still needed to do those inserts, so I have finally changed completely my approach and created my own Java RESTful service as an intermediary between my application and Virtuoso.
I have found that Virtuoso provides some libraries for Java, and these libraries have helped me connecting to Virtuoso with the appropiate authorization. I also have to say that creating the service was not easy, but it finally worked.
I hope this information helps someone to think on this approach earlier, because it has caused me a big waste of time in my project. As I have said, I have solved my own problem of doing inserts through my application, but the authentication problem is still there, so feel free to add any new comments on this topic.
Upvotes: 2
Views: 1492
Reputation: 925
You can perform INSERT, DELETE, and UPDATE (combining DELETE and INSERT) via the SPARQL Query Service endpoint provided by any Virtuoso instance using the SPARQL Update Language (SPARUL).
Naturally, Virtuoso endpoints are protected by default; this is why /sparql
didn't work for you. The /sparql-update
endpoint is in place for basic Digest Authentication, which boils down to conventional Role-based Access Controls (RBAC) scoped to Virtuoso SQL User Accounts.
To enable the much more powerful Attribute-based Access Controls (ABAC) functionality, which is scoped to Web-scale identities, you need to install the Enterprise Edition plus the Virtuoso Authentication Layer (VAL) module (delivered by a Virtuoso Application Distribution (VAD) package).
Here's a simple step-by-guide regarding ABAC functionality:
Use the System Admin → Packages tab of the Conductor UI to confirm that VAL is enabled.
Return to your SPARQL endpoint and attempt to perform an INSERT
or DELETE
targeting a Named Graph.
I hope this helps?
Upvotes: 3