From a2b44d9b47e6712c985576eaa5c9b01941157c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 19 Apr 2024 09:03:44 +0200 Subject: [PATCH 1/6] GH-3654 add caching in document loader --- .../rdf4j/rio/helpers/JSONLDSettings.java | 30 ++++++ core/rio/jsonld/pom.xml | 4 + .../rio/jsonld/CachingDocumentLoader.java | 77 ++++++++++++++++ .../rdf4j/rio/jsonld/JSONLDParser.java | 34 +++++-- .../rio/jsonld/JSONLDParserCustomTest.java | 92 +++++++++++++++++++ .../jsonld/localFileContext/context.jsonld | 6 ++ .../jsonld/localFileContext/data.jsonld | 9 ++ .../jsonld/remoteContext/data.jsonld | 83 +++++++++++++++++ .../jsonld/remoteContextException/data.jsonld | 83 +++++++++++++++++ 9 files changed, 408 insertions(+), 10 deletions(-) create mode 100644 core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java create mode 100644 core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/context.jsonld create mode 100644 core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/data.jsonld create mode 100644 core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContext/data.jsonld create mode 100644 core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContextException/data.jsonld diff --git a/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java b/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java index 1b1dde8d6db..df3697961b8 100644 --- a/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java +++ b/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.rdf4j.rio.helpers; +import java.util.List; +import java.util.Set; + import org.eclipse.rdf4j.rio.RioSetting; import com.github.jsonldjava.core.DocumentLoader; @@ -153,6 +156,33 @@ public class JSONLDSettings { public static final RioSetting HIERARCHICAL_VIEW = new BooleanRioSetting( "org.eclipse.rdf4j.rio.jsonld.hierarchical_view", "Hierarchical representation of the JSON", Boolean.FALSE); + /** + * + * + */ + public static final RioSetting> WHITELIST = new RioSettingImpl<>( + "org.eclipse.rdf4j.rio.jsonld_whitelist", + "Whitelist of remote/local resources that the JSON-LD parser can retrieve. Set of URIs as strings.", + Set.of()); + + /** + * + * + */ + public static final RioSetting SECURE_MODE = new RioSettingImpl<>( + "org.eclipse.rdf4j.rio.jsonld_secure_mode", + "Secure mode only allows loading remote/local resources (ex. context from url) that are whitelisted.", + Boolean.TRUE); + + /** + * + * + */ + public static final RioSetting DOCUMENT_LOADER_CACHE = new RioSettingImpl<>( + "org.eclipse.rdf4j.rio.jsonld_document_loader_cache", + "The document loader cache is enabled by default. All loaded documents, such as remote contexts, are cached for 1 hour, or until the cache is full. The cache holds up to 1000 documents. The cache is shared between all JSONLDParsers. The cache can be disabled by setting this value to false.", + Boolean.TRUE); + /** * Private default constructor. */ diff --git a/core/rio/jsonld/pom.xml b/core/rio/jsonld/pom.xml index c1af2971328..307928c78a8 100644 --- a/core/rio/jsonld/pom.xml +++ b/core/rio/jsonld/pom.xml @@ -74,6 +74,10 @@ commons-io commons-io + + com.google.guava + guava + ${project.groupId} rdf4j-rio-api diff --git a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java new file mode 100644 index 00000000000..e7b643d1d06 --- /dev/null +++ b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java @@ -0,0 +1,77 @@ +package org.eclipse.rdf4j.rio.jsonld; + +import java.net.URI; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.eclipse.rdf4j.rio.RDFParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; + +import no.hasmac.jsonld.JsonLdError; +import no.hasmac.jsonld.document.Document; +import no.hasmac.jsonld.loader.DocumentLoader; +import no.hasmac.jsonld.loader.DocumentLoaderOptions; +import no.hasmac.jsonld.loader.SchemeRouter; + +public class CachingDocumentLoader implements DocumentLoader { + private static final DocumentLoader defaultLoader = SchemeRouter.defaultInstance(); + private static final Logger logger = LoggerFactory.getLogger(CachingDocumentLoader.class); + + private static final LoadingCache cache = CacheBuilder.newBuilder() + .maximumSize(1000) // Maximum 1000 documents in cache + .expireAfterWrite(1, TimeUnit.HOURS) // Expire after 1 hour + .concurrencyLevel(8) // Optimize for 8 concurrent threads + .build(new CacheLoader<>() { + @Override + public Document load(URI url) throws Exception { + return defaultLoader.loadDocument(url, new DocumentLoaderOptions()); + } + }); + + private final boolean secureMode; + private final Set whitelist; + private final boolean documentLoaderCache; + + public CachingDocumentLoader(boolean secureMode, Set whitelist, boolean documentLoaderCache) { + this.secureMode = secureMode; + this.whitelist = whitelist; + this.documentLoaderCache = documentLoaderCache; + } + + @Override + public Document loadDocument(URI uri, DocumentLoaderOptions options) { + + try { + if (!secureMode || whitelist.contains(uri.toString())) { + if (documentLoaderCache) { + try { + return cache.get(uri); + } catch (ExecutionException e) { + if (e.getCause() != null) { + throw new RDFParseException("Could not load document from " + uri, e.getCause()); + } + throw new RDFParseException("Could not load document from " + uri, e); + } + } else { + try { + return defaultLoader.loadDocument(uri, options); + } catch (JsonLdError e) { + throw new RDFParseException("Could not load document from " + uri, e); + } + } + } else { + throw new RDFParseException("Could not load document from " + uri + + " because it is not whitelisted. See: JSONLDSettings.WHITELIST and JSONLDSettings.SECURE_MODE"); + } + } catch (RDFParseException e) { + logger.error(e.getMessage(), e); + throw e; + } + } +} diff --git a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java index 4fe15f728a2..481e9776d00 100644 --- a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java +++ b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java @@ -10,13 +10,19 @@ *******************************************************************************/ package org.eclipse.rdf4j.rio.jsonld; +import static org.eclipse.rdf4j.rio.helpers.JSONLDSettings.DOCUMENT_LOADER_CACHE; +import static org.eclipse.rdf4j.rio.helpers.JSONLDSettings.SECURE_MODE; +import static org.eclipse.rdf4j.rio.helpers.JSONLDSettings.WHITELIST; + import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URI; import java.net.URISyntaxException; import java.util.Collection; +import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.function.BiConsumer; import org.eclipse.rdf4j.model.IRI; @@ -126,12 +132,21 @@ private void parse(InputStream in, Reader reader, String baseURI) BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES); } + boolean secureMode = getParserConfig().get(SECURE_MODE); + boolean documentLoaderCache = getParserConfig().get(DOCUMENT_LOADER_CACHE); + + Set whitelist = getParserConfig().get(WHITELIST); + JsonLdOptions opts = new JsonLdOptions(); opts.setUriValidation(false); opts.setExceptionOnWarning(getParserConfig().get(JSONLDSettings.EXCEPTION_ON_WARNING)); Document context = getParserConfig().get(JSONLDSettings.EXPAND_CONTEXT); + DocumentLoader defaultDocumentLoader = opts.getDocumentLoader(); + CachingDocumentLoader cachingDocumentLoader = new CachingDocumentLoader(secureMode, whitelist, + documentLoaderCache); + if (context != null) { opts.setExpandContext(context); @@ -142,22 +157,21 @@ private void parse(InputStream in, Reader reader, String baseURI) throw new RDFParseException("Expand context is not a valid JSON document"); } opts.getContextCache().put(context.getDocumentUrl().toString(), jsonContent.get()); - opts.setDocumentLoader(new DocumentLoader() { - - private final DocumentLoader defaultDocumentLoader = SchemeRouter.defaultInstance(); - - @Override - public Document loadDocument(URI url, DocumentLoaderOptions options) throws JsonLdError { - if (url.equals(context.getDocumentUrl())) { - return context; - } - return defaultDocumentLoader.loadDocument(url, options); + opts.setDocumentLoader((uri, options) -> { + if (uri.equals(context.getDocumentUrl())) { + return context; } + + return cachingDocumentLoader.loadDocument(uri, options); }); } } + if (secureMode && opts.getDocumentLoader() == defaultDocumentLoader) { + opts.setDocumentLoader(cachingDocumentLoader); + } + if (baseURI != null && !baseURI.isEmpty()) { URI uri = new URI(baseURI); opts.setBase(uri); diff --git a/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java b/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java index e8e8e26bd5e..ca9e13e67e3 100644 --- a/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java +++ b/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java @@ -11,12 +11,19 @@ package org.eclipse.rdf4j.rio.jsonld; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.eclipse.rdf4j.rio.helpers.JSONLDSettings.SECURE_MODE; +import static org.eclipse.rdf4j.rio.helpers.JSONLDSettings.WHITELIST; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.File; import java.io.StringReader; import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.Set; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Model; @@ -24,7 +31,9 @@ import org.eclipse.rdf4j.model.Value; import org.eclipse.rdf4j.model.impl.LinkedHashModel; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.FOAF; import org.eclipse.rdf4j.model.vocabulary.XSD; +import org.eclipse.rdf4j.rio.ParserConfig; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFParseException; import org.eclipse.rdf4j.rio.RDFParser; @@ -32,7 +41,9 @@ import org.eclipse.rdf4j.rio.helpers.ContextStatementCollector; import org.eclipse.rdf4j.rio.helpers.JSONLDSettings; import org.eclipse.rdf4j.rio.helpers.ParseErrorCollector; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import no.hasmac.jsonld.document.Document; @@ -228,4 +239,85 @@ public void testContext() throws Exception { parser.parse(new StringReader(LOADER_JSONLD), ""); assertTrue(model.predicates().contains(testPredicate)); } + + @Test + public void testLocalFileSecurity() throws Exception { + + String contextUri = JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/localFileContext/context.jsonld") + .toString(); + + String jsonld = FileUtils + .readFileToString(new File(JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/localFileContext/data.jsonld") + .getFile()), StandardCharsets.UTF_8) + .replace("file:./context.jsonld", contextUri); + + // expect exception + RDFParseException rdfParseException = Assertions.assertThrowsExactly(RDFParseException.class, () -> { + parser.parse(new StringReader(jsonld), ""); + }); + + Assertions.assertEquals("Could not load document from " + contextUri + + " because it is not whitelisted. See: JSONLDSettings.WHITELIST and JSONLDSettings.SECURE_MODE", + rdfParseException.getMessage()); + } + + @Test + public void testLocalFileSecurityWhiteList() throws Exception { + String jsonld = FileUtils.readFileToString(new File(JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/localFileContext/data.jsonld") + .getFile()), StandardCharsets.UTF_8); + String contextUri = JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/localFileContext/context.jsonld") + .toString(); + jsonld = jsonld.replace("file:./context.jsonld", contextUri); + + parser.getParserConfig().set(WHITELIST, Set.of(contextUri)); + + parser.parse(new StringReader(jsonld), ""); + assertTrue(model.objects().contains(FOAF.PERSON)); + } + + @Test + public void testLocalFileSecurityDisableSecurity() throws Exception { + String jsonld = FileUtils.readFileToString(new File(JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/localFileContext/data.jsonld") + .getFile()), StandardCharsets.UTF_8); + jsonld = jsonld.replace("file:./context.jsonld", + JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/localFileContext/context.jsonld") + .toString()); + + parser.getParserConfig().set(SECURE_MODE, false); + + parser.parse(new StringReader(jsonld), ""); + assertTrue(model.objects().contains(FOAF.PERSON)); + } + + @RepeatedTest(10) + public void testRemoteContext() throws Exception { + String jsonld = FileUtils.readFileToString(new File(JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/remoteContext/data.jsonld") + .getFile()), StandardCharsets.UTF_8); + + parser.getParserConfig().set(WHITELIST, Set.of("https://schema.org")); + parser.parse(new StringReader(jsonld), ""); + assertEquals(59, model.size()); + } + + @Test + public void testRemoteContextException() throws Exception { + String jsonld = FileUtils.readFileToString(new File(JSONLDParserCustomTest.class.getClassLoader() + .getResource("testcases/jsonld/remoteContextException/data.jsonld") + .getFile()), StandardCharsets.UTF_8); + + parser.getParserConfig().set(WHITELIST, Set.of("https://example.org/context.jsonld")); + RDFParseException rdfParseException = Assertions.assertThrowsExactly(RDFParseException.class, () -> { + parser.parse(new StringReader(jsonld), ""); + }); + + assertEquals("Could not load document from https://example.org/context.jsonld", rdfParseException.getMessage()); + } + } diff --git a/core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/context.jsonld b/core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/context.jsonld new file mode 100644 index 00000000000..c2cb49f9339 --- /dev/null +++ b/core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": + { + "Person": "http://xmlns.com/foaf/0.1/Person" + } +} diff --git a/core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/data.jsonld b/core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/data.jsonld new file mode 100644 index 00000000000..daa68e7fc50 --- /dev/null +++ b/core/rio/jsonld/src/test/resources/testcases/jsonld/localFileContext/data.jsonld @@ -0,0 +1,9 @@ +{ + "@context": "file:./context.jsonld", + + "@id":"http://example/peter", + "@type":"Person" + + + +} diff --git a/core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContext/data.jsonld b/core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContext/data.jsonld new file mode 100644 index 00000000000..6b5b124a2ba --- /dev/null +++ b/core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContext/data.jsonld @@ -0,0 +1,83 @@ +{ +"@context": "https://schema.org", + "@type": ["ItemList", "CreativeWork"], + "name": "Top 5 covers of Bob Dylan Songs", + "author": "John Doe", + "about": { + "@type": "MusicRecording", + "byArtist": { + "@type": "MusicGroup", + "name": "Bob Dylan" + } + }, + "itemListOrder": "https://schema.org/ItemListOrderAscending", + "numberOfItems": 5, + "itemListElement": [ + { + "@type": "ListItem", + "position": 5, + "item": { + "@type": "MusicRecording", + "name": "If Not For You", + "byArtist": { + "@type": "MusicGroup", + "name": "George Harrison" + } + } + }, + { + "@type": "ListItem", + "position": 4, + "item": { + "@type": "MusicRecording", + "name": "The Times They Are A-Changin'", + "byArtist": { + "@type": "MusicGroup", + "name": "Tracy Chapman" + } + } + }, + { + "@type": "ListItem", + "position": 3, + "item": { + "@type": "MusicRecording", + "name": "It Ain't Me Babe", + "byArtist": [ + { + "@type": "MusicGroup", + "name": "Johnny Cash" + }, + { + "@type": "MusicGroup", + "name": "June Carter Cash" + } + ] + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@type": "MusicRecording", + "name": "Don't Think Twice It's Alright", + "byArtist": { + "@type": "MusicGroup", + "name": "Waylon Jennings" + } + } + }, + { + "@type": "ListItem", + "position": 1, + "item": { + "@type": "MusicRecording", + "name": "All Along the Watchtower", + "byArtist": { + "@type": "MusicGroup", + "name": "Jimi Hendrix" + } + } + } + ] +} diff --git a/core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContextException/data.jsonld b/core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContextException/data.jsonld new file mode 100644 index 00000000000..69ceb5882c6 --- /dev/null +++ b/core/rio/jsonld/src/test/resources/testcases/jsonld/remoteContextException/data.jsonld @@ -0,0 +1,83 @@ +{ +"@context": "https://example.org/context.jsonld", + "@type": ["ItemList", "CreativeWork"], + "name": "Top 5 covers of Bob Dylan Songs", + "author": "John Doe", + "about": { + "@type": "MusicRecording", + "byArtist": { + "@type": "MusicGroup", + "name": "Bob Dylan" + } + }, + "itemListOrder": "https://schema.org/ItemListOrderAscending", + "numberOfItems": 5, + "itemListElement": [ + { + "@type": "ListItem", + "position": 5, + "item": { + "@type": "MusicRecording", + "name": "If Not For You", + "byArtist": { + "@type": "MusicGroup", + "name": "George Harrison" + } + } + }, + { + "@type": "ListItem", + "position": 4, + "item": { + "@type": "MusicRecording", + "name": "The Times They Are A-Changin'", + "byArtist": { + "@type": "MusicGroup", + "name": "Tracy Chapman" + } + } + }, + { + "@type": "ListItem", + "position": 3, + "item": { + "@type": "MusicRecording", + "name": "It Ain't Me Babe", + "byArtist": [ + { + "@type": "MusicGroup", + "name": "Johnny Cash" + }, + { + "@type": "MusicGroup", + "name": "June Carter Cash" + } + ] + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@type": "MusicRecording", + "name": "Don't Think Twice It's Alright", + "byArtist": { + "@type": "MusicGroup", + "name": "Waylon Jennings" + } + } + }, + { + "@type": "ListItem", + "position": 1, + "item": { + "@type": "MusicRecording", + "name": "All Along the Watchtower", + "byArtist": { + "@type": "MusicGroup", + "name": "Jimi Hendrix" + } + } + } + ] +} From 4017f3ce319d5c0c673b15853fd7ff19eea201c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 19 Apr 2024 09:39:02 +0200 Subject: [PATCH 2/6] GH-3654 update javadocs --- .../rdf4j/rio/helpers/JSONLDSettings.java | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java b/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java index df3697961b8..fc4d5592ba3 100644 --- a/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java +++ b/core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java @@ -157,17 +157,47 @@ public class JSONLDSettings { "org.eclipse.rdf4j.rio.jsonld.hierarchical_view", "Hierarchical representation of the JSON", Boolean.FALSE); /** - * + * Whitelist of remote/local resources that the JSON-LD parser can retrieve. Set of URIs as strings. + *

+ * Default: + * {@code Set.of("http://www.w3.org/ns/anno.jsonld", "http://www.w3.org/ns/activitystreams.jsonld", "http://www.w3.org/ns/ldp.jsonld", "http://www.w3.org/ns/oa.jsonld", "http://www.w3.org/ns/hydra/context.jsonld", "http://schema.org/", "https://w3id.org/security/v1", "https://w3c.github.io/json-ld-rc/context.jsonld", "https://www.w3.org/2018/credentials/v1", "https://health-lifesci.schema.org/", "https://auto.schema.org/", "https://bib.schema.org/", "http://xmlns.com/foaf/spec/index.jsonld", "https://pending.schema.org/", "https://schema.org/", "https://schema.org/docs/jsonldcontext.jsonld", "https://schema.org/version/latest/schemaorg-current-https.jsonld", "https://schema.org/version/latest/schemaorg-all-http.jsonld", "https://schema.org/version/latest/schemaorg-all-https.jsonld", "https://schema.org/version/latest/schemaorg-current-http.jsonld", "https://schema.org/version/latest/schemaorg-all.jsonld", "https://schema.org/version/latest/schemaorg-current.jsonld", "https://project-open-data.cio.gov/v1.1/schema/catalog.jsonld", "https://geojson.org/geojson-ld/geojson-context.jsonld", "https://www.w3.org/2019/wot/td/v1"); * */ public static final RioSetting> WHITELIST = new RioSettingImpl<>( "org.eclipse.rdf4j.rio.jsonld_whitelist", "Whitelist of remote/local resources that the JSON-LD parser can retrieve. Set of URIs as strings.", - Set.of()); + Set.of( + "http://www.w3.org/ns/anno.jsonld", + "http://www.w3.org/ns/activitystreams.jsonld", + "http://www.w3.org/ns/ldp.jsonld", + "http://www.w3.org/ns/oa.jsonld", + "http://www.w3.org/ns/hydra/context.jsonld", + "http://schema.org/", + "https://w3id.org/security/v1", + "https://w3c.github.io/json-ld-rc/context.jsonld", + "https://www.w3.org/2018/credentials/v1", + "https://health-lifesci.schema.org/", + "https://auto.schema.org/", + "https://bib.schema.org/", + "http://xmlns.com/foaf/spec/index.jsonld", + "https://pending.schema.org/", + "https://schema.org/", + "https://schema.org/docs/jsonldcontext.jsonld", + "https://schema.org/version/latest/schemaorg-current-https.jsonld", + "https://schema.org/version/latest/schemaorg-all-http.jsonld", + "https://schema.org/version/latest/schemaorg-all-https.jsonld", + "https://schema.org/version/latest/schemaorg-current-http.jsonld", + "https://schema.org/version/latest/schemaorg-all.jsonld", + "https://schema.org/version/latest/schemaorg-current.jsonld", + "https://project-open-data.cio.gov/v1.1/schema/catalog.jsonld", + "https://geojson.org/geojson-ld/geojson-context.jsonld", + "https://www.w3.org/2019/wot/td/v1" + )); /** - * - * + * Secure mode only allows loading remote/local resources (ex. context from url) that are whitelisted. + *

+ * Default: true */ public static final RioSetting SECURE_MODE = new RioSettingImpl<>( "org.eclipse.rdf4j.rio.jsonld_secure_mode", @@ -175,8 +205,11 @@ public class JSONLDSettings { Boolean.TRUE); /** - * - * + * The document loader cache is enabled by default. All loaded documents, such as remote contexts, are cached for 1 + * hour, or until the cache is full. The cache holds up to 1000 documents. The cache is shared between all + * JSONLDParsers. The cache can be disabled by setting this value to false. + *

+ * Default: true */ public static final RioSetting DOCUMENT_LOADER_CACHE = new RioSettingImpl<>( "org.eclipse.rdf4j.rio.jsonld_document_loader_cache", From e6027b5eef7914bb51493f39e5dc8214f6286ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 19 Apr 2024 10:22:30 +0200 Subject: [PATCH 3/6] remove problematic test --- .../eclipse/rdf4j/rio/n3/N3ParserTest.java | 70 +++++++++---------- .../rdf4j/rio/jsonld/JSONLDParser.java | 3 - .../rio/jsonld/JSONLDParserCustomTest.java | 2 - 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java b/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java index 42be7fd908a..3e0819513ca 100644 --- a/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java +++ b/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java @@ -1,35 +1,35 @@ -/******************************************************************************* - * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Distribution License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - *******************************************************************************/ -package org.eclipse.rdf4j.rio.n3; - -import org.eclipse.rdf4j.rio.RDFParser; -import org.eclipse.rdf4j.rio.turtle.TurtleParser; -import org.eclipse.rdf4j.testsuite.rio.n3.N3ParserTestCase; -import org.junit.jupiter.api.Disabled; - -import junit.framework.Test; - -/** - * JUnit test for the N3 parser that uses the tests that are available - * online. - */ -@Disabled("FIXME: This test is badly broken") -public class N3ParserTest extends N3ParserTestCase { - - public static Test suite() throws Exception { - return new N3ParserTest().createTestSuite(); - } - - @Override - protected RDFParser createRDFParser() { - return new TurtleParser(); - } -} +///******************************************************************************* +// * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. +// * +// * All rights reserved. This program and the accompanying materials +// * are made available under the terms of the Eclipse Distribution License v1.0 +// * which accompanies this distribution, and is available at +// * http://www.eclipse.org/org/documents/edl-v10.php. +// * +// * SPDX-License-Identifier: BSD-3-Clause +// *******************************************************************************/ +//package org.eclipse.rdf4j.rio.n3; +// +//import org.eclipse.rdf4j.rio.RDFParser; +//import org.eclipse.rdf4j.rio.turtle.TurtleParser; +//import org.eclipse.rdf4j.testsuite.rio.n3.N3ParserTestCase; +//import org.junit.jupiter.api.Disabled; +// +//import junit.framework.Test; +// +///** +// * JUnit test for the N3 parser that uses the tests that are available +// * online. +// */ +//@Disabled("FIXME: This test is badly broken") +//public class N3ParserTest extends N3ParserTestCase { +// +// public static Test suite() throws Exception { +// return new N3ParserTest().createTestSuite(); +// } +// +// @Override +// protected RDFParser createRDFParser() { +// return new TurtleParser(); +// } +//} diff --git a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java index 481e9776d00..0c3561620c4 100644 --- a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java +++ b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParser.java @@ -20,7 +20,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Collection; -import java.util.List; import java.util.Optional; import java.util.Set; import java.util.function.BiConsumer; @@ -54,8 +53,6 @@ import no.hasmac.jsonld.document.JsonDocument; import no.hasmac.jsonld.lang.Keywords; import no.hasmac.jsonld.loader.DocumentLoader; -import no.hasmac.jsonld.loader.DocumentLoaderOptions; -import no.hasmac.jsonld.loader.SchemeRouter; import no.hasmac.rdf.RdfConsumer; import no.hasmac.rdf.RdfValueFactory; diff --git a/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java b/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java index ca9e13e67e3..1e61a4423fe 100644 --- a/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java +++ b/core/rio/jsonld/src/test/java/org/eclipse/rdf4j/rio/jsonld/JSONLDParserCustomTest.java @@ -23,7 +23,6 @@ import java.util.Set; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; import org.eclipse.rdf4j.model.Model; @@ -33,7 +32,6 @@ import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.FOAF; import org.eclipse.rdf4j.model.vocabulary.XSD; -import org.eclipse.rdf4j.rio.ParserConfig; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFParseException; import org.eclipse.rdf4j.rio.RDFParser; From 0d2ce0767229df30c327a6910a3631a887721e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 19 Apr 2024 10:23:40 +0200 Subject: [PATCH 4/6] fix copyright --- .../rdf4j/rio/jsonld/CachingDocumentLoader.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java index e7b643d1d06..fc7074d12ce 100644 --- a/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java +++ b/core/rio/jsonld/src/main/java/org/eclipse/rdf4j/rio/jsonld/CachingDocumentLoader.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2024 Eclipse RDF4J contributors. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Distribution License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + ******************************************************************************/ + package org.eclipse.rdf4j.rio.jsonld; import java.net.URI; From 2b9f138bc31a588dba1a947c10250414be622878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 19 Apr 2024 11:08:02 +0200 Subject: [PATCH 5/6] try to fix junit issues --- .../eclipse/rdf4j/rio/n3/N3ParserTest.java | 70 +++++++++---------- pom.xml | 2 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java b/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java index 3e0819513ca..42be7fd908a 100644 --- a/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java +++ b/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java @@ -1,35 +1,35 @@ -///******************************************************************************* -// * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. -// * -// * All rights reserved. This program and the accompanying materials -// * are made available under the terms of the Eclipse Distribution License v1.0 -// * which accompanies this distribution, and is available at -// * http://www.eclipse.org/org/documents/edl-v10.php. -// * -// * SPDX-License-Identifier: BSD-3-Clause -// *******************************************************************************/ -//package org.eclipse.rdf4j.rio.n3; -// -//import org.eclipse.rdf4j.rio.RDFParser; -//import org.eclipse.rdf4j.rio.turtle.TurtleParser; -//import org.eclipse.rdf4j.testsuite.rio.n3.N3ParserTestCase; -//import org.junit.jupiter.api.Disabled; -// -//import junit.framework.Test; -// -///** -// * JUnit test for the N3 parser that uses the tests that are available -// * online. -// */ -//@Disabled("FIXME: This test is badly broken") -//public class N3ParserTest extends N3ParserTestCase { -// -// public static Test suite() throws Exception { -// return new N3ParserTest().createTestSuite(); -// } -// -// @Override -// protected RDFParser createRDFParser() { -// return new TurtleParser(); -// } -//} +/******************************************************************************* + * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Distribution License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + *******************************************************************************/ +package org.eclipse.rdf4j.rio.n3; + +import org.eclipse.rdf4j.rio.RDFParser; +import org.eclipse.rdf4j.rio.turtle.TurtleParser; +import org.eclipse.rdf4j.testsuite.rio.n3.N3ParserTestCase; +import org.junit.jupiter.api.Disabled; + +import junit.framework.Test; + +/** + * JUnit test for the N3 parser that uses the tests that are available + * online. + */ +@Disabled("FIXME: This test is badly broken") +public class N3ParserTest extends N3ParserTestCase { + + public static Test suite() throws Exception { + return new N3ParserTest().createTestSuite(); + } + + @Override + protected RDFParser createRDFParser() { + return new TurtleParser(); + } +} diff --git a/pom.xml b/pom.xml index 6c315200678..7ef42cdf85b 100644 --- a/pom.xml +++ b/pom.xml @@ -378,7 +378,7 @@ 32.1.3-jre 1.37 3.1.0 - 5.9.3 + 5.9.2 9.4.53.v20231009 From 898ded779815441fdf953124fb4afc9966215a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Fri, 19 Apr 2024 11:18:11 +0200 Subject: [PATCH 6/6] try to fix junit issues --- .../eclipse/rdf4j/rio/n3/N3ParserTest.java | 35 ------------------- pom.xml | 2 +- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java diff --git a/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java b/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java deleted file mode 100644 index 42be7fd908a..00000000000 --- a/compliance/rio/src/test/java/org/eclipse/rdf4j/rio/n3/N3ParserTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Distribution License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - *******************************************************************************/ -package org.eclipse.rdf4j.rio.n3; - -import org.eclipse.rdf4j.rio.RDFParser; -import org.eclipse.rdf4j.rio.turtle.TurtleParser; -import org.eclipse.rdf4j.testsuite.rio.n3.N3ParserTestCase; -import org.junit.jupiter.api.Disabled; - -import junit.framework.Test; - -/** - * JUnit test for the N3 parser that uses the tests that are available - * online. - */ -@Disabled("FIXME: This test is badly broken") -public class N3ParserTest extends N3ParserTestCase { - - public static Test suite() throws Exception { - return new N3ParserTest().createTestSuite(); - } - - @Override - protected RDFParser createRDFParser() { - return new TurtleParser(); - } -} diff --git a/pom.xml b/pom.xml index 7ef42cdf85b..6c315200678 100644 --- a/pom.xml +++ b/pom.xml @@ -378,7 +378,7 @@ 32.1.3-jre 1.37 3.1.0 - 5.9.2 + 5.9.3 9.4.53.v20231009