Skip to content

Add a read-only SPARQL query endpoint for authorized users#853

Draft
dennisvang wants to merge 23 commits intosupport/1.19.xfrom
feature/852-sparql
Draft

Add a read-only SPARQL query endpoint for authorized users#853
dennisvang wants to merge 23 commits intosupport/1.19.xfrom
feature/852-sparql

Conversation

@dennisvang
Copy link
Contributor

@dennisvang dennisvang commented Mar 9, 2026

Added a /search/sparql API endpoint that is only accessible for authenticated users.

The implementation uses org.eclipse.rdf4j.http.server.readonly.sparql.SparqlQueryEvaluator and is based on the QueryResponder example.

TODO:

  • limit supported output formats to JSON and/or JSON-LD
  • change input format from application/x-www-form-urlencoded to application/json, for consistence with the other api endpoints
  • add the ability to save raw sparql queries (in addition to the restricted sparql queries)
  • test to verify that unauthenticated users cannot access
  • tests to verify that SPARQL Query operations work as expected (ASK, CONSTRUCT, DESCRIBE, SELECT)
  • tests to verify that SPARQL Update operations are disallowed (INSERT, DELETE, LOAD, CLEAR, CREATE, DROP, COPY, MOVE, ADD)
  • (optional) tests to verify that subqueries cannot contain update operations? (looks like the SPARQL grammar does not allow this, but it could be implementation dependent...)
  • (optional) tests to check for side-effects of named graphs

fixes #852

do this first so we won't forget
to disambiguate from the profileController defined in org/springframework/data/rest/webmvc/RestControllerConfiguration.class, which is used by the rdf4j sparql endpoint package
@dennisvang
Copy link
Contributor Author

dennisvang commented Mar 9, 2026

Apparently, the package rdf4j-spring-boot-sparql-web does not play nice with the FDP configuration.

To make it work at all, we need to exclude the logback transient dependency, and we need to rename our ProfileController to prevent ambiguity.

Even then, including the package breaks the api documentation (/v3/api-docs):

...
java.lang.IllegalStateException: Ambiguous search mapping detected; 
  Both public abstract java.lang.Iterable nl.dtls.fairdatapoint.database.mongo.repository.IndexEntryRepository.findAllByPermitIn(java.util.List) 
  and public abstract org.springframework.data.domain.Page nl.dtls.fairdatapoint.database.mongo.repository.IndexEntryRepository.findAllByPermitIn(org.springframework.data.domain.Pageable,java.util.List) 
  are mapped to /findAllByPermitIn; 
  Tweak configuration to get to unambiguous paths
	at org.springframework.data.rest.core.mapping.SearchResourceMappings.<init>(SearchResourceMappings.java:62) ~[spring-data-rest-core-4.5.8.jar:4.5.8]
...

@dennisvang
Copy link
Contributor Author

dennisvang commented Mar 10, 2026

For some reason, simply adding the rdf4j-spring-boot-sparql-web dependency, even without creating a sparql endpoint, causes springdoc-openapi to start generating documentation for all the JPA repository methods and spring mvc controller endpoints, in addition to the grouped endpoints that were there originally.

Because springdoc-openapi now tries to generate docs for JPA repository methods, it breaks down, as it considers the overloaded IndexEntryRepository.findAllByPermitIn methods to be ambiguous (see error above).

UPDATE:

This is probably caused by the transitive dependency on spring data rest:

Spring Data REST builds on top of the Spring Data repositories and automatically exports those as REST resources. [...]

To prevent any more of these unwelcome surprises we should probably exclude all transitive dependencies from rdf4j-spring-boot-sparql-web. We only need the class definitions anyway.

because we don't need them, and dependencies like spring-data-rest cause unwanted side-effects, such as exposing all repository methods as rest endpoints
@dennisvang
Copy link
Contributor Author

dennisvang commented Mar 10, 2026

Now the api docs are generated normally, but the swagger-ui endpoint for /search/sparql fails because it does not include the specified Accept header in the generated curl request. Instead, it includes Accept: */*, which causes the sparql query handler to fail.

This probably has to do with the following OpenAPI 3 restrictions:

Note: Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords: [...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant