Skip to content

Commit 689d1eb

Browse files
committed
GH-5032 add support for overriding SECURE_MODE and WHITELIST JSON-LD setting
1 parent 7034492 commit 689d1eb

4 files changed

Lines changed: 78 additions & 14 deletions

File tree

core/rio/api/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@
8080
</exclusion>
8181
</exclusions>
8282
</dependency>
83+
<dependency>
84+
<groupId>com.fasterxml.jackson.core</groupId>
85+
<artifactId>jackson-annotations</artifactId>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.fasterxml.jackson.core</groupId>
89+
<artifactId>jackson-core</artifactId>
90+
</dependency>
91+
<dependency>
92+
<groupId>com.fasterxml.jackson.core</groupId>
93+
<artifactId>jackson-databind</artifactId>
94+
</dependency>
8395
<dependency>
8496
<groupId>commons-io</groupId>
8597
<artifactId>commons-io</artifactId>

core/rio/api/src/main/java/org/eclipse/rdf4j/rio/helpers/JSONLDSettings.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*******************************************************************************/
1111
package org.eclipse.rdf4j.rio.helpers;
1212

13-
import java.util.List;
1413
import java.util.Set;
1514

1615
import org.eclipse.rdf4j.rio.RioSetting;
@@ -38,7 +37,7 @@ public class JSONLDSettings {
3837
* @see <a href="http://json-ld.org/spec/latest/json-ld-api/#data-structures">JSONLD Data Structures</a>
3938
*
4039
*/
41-
public static final RioSetting<Boolean> COMPACT_ARRAYS = new BooleanRioSetting(
40+
public static final BooleanRioSetting COMPACT_ARRAYS = new BooleanRioSetting(
4241
"org.eclipse.rdf4j.rio.jsonld.compact_arrays", "Compact arrays", Boolean.TRUE);
4342

4443
/**
@@ -69,7 +68,7 @@ public class JSONLDSettings {
6968
* The JSON-LD processor will throw an exception if a warning is encountered during processing.
7069
*
7170
*/
72-
public static final RioSetting<Boolean> EXCEPTION_ON_WARNING = new ClassRioSetting<>(
71+
public static final BooleanRioSetting EXCEPTION_ON_WARNING = new BooleanRioSetting(
7372
"org.eclipse.rdf4j.rio.jsonld.exception_on_warning",
7473
"Throw an exception when logging a warning.",
7574
Boolean.FALSE);
@@ -86,7 +85,7 @@ public class JSONLDSettings {
8685
* @see <a href="http://json-ld.org/spec/latest/json-ld-api/#data-structures">JSONLD Data Structures</a>
8786
*
8887
*/
89-
public static final RioSetting<Boolean> OPTIMIZE = new BooleanRioSetting("org.eclipse.rdf4j.rio.jsonld.optimize",
88+
public static final BooleanRioSetting OPTIMIZE = new BooleanRioSetting("org.eclipse.rdf4j.rio.jsonld.optimize",
9089
"Optimize output", Boolean.FALSE);
9190

9291
/**
@@ -102,7 +101,7 @@ public class JSONLDSettings {
102101
* @see <a href="http://json-ld.org/spec/latest/json-ld-api/#data-structures">JSONLD Data Structures</a>
103102
*
104103
*/
105-
public static final RioSetting<Boolean> PRODUCE_GENERALIZED_RDF = new BooleanRioSetting(
104+
public static final BooleanRioSetting PRODUCE_GENERALIZED_RDF = new BooleanRioSetting(
106105
"org.eclipse.rdf4j.rio.jsonld.produce_generalized_rdf", "Produce generalized RDF", Boolean.FALSE);
107106

108107
/**
@@ -117,7 +116,7 @@ public class JSONLDSettings {
117116
* @see <a href="http://json-ld.org/spec/latest/json-ld-api/#data-structures">JSONLD Data Structures</a>
118117
*
119118
*/
120-
public static final RioSetting<Boolean> USE_NATIVE_TYPES = new BooleanRioSetting(
119+
public static final BooleanRioSetting USE_NATIVE_TYPES = new BooleanRioSetting(
121120
"org.eclipse.rdf4j.rio.jsonld.use_native_types", "Use Native JSON Types", Boolean.FALSE);
122121

123122
/**
@@ -131,7 +130,7 @@ public class JSONLDSettings {
131130
* @see <a href="http://json-ld.org/spec/latest/json-ld-api/#data-structures">JSONLD Data Structures</a>
132131
*
133132
*/
134-
public static final RioSetting<Boolean> USE_RDF_TYPE = new BooleanRioSetting(
133+
public static final BooleanRioSetting USE_RDF_TYPE = new BooleanRioSetting(
135134
"org.eclipse.rdf4j.rio.jsonld.use_rdf_type", "Use RDF Type", Boolean.FALSE);
136135

137136
/**
@@ -153,17 +152,19 @@ public class JSONLDSettings {
153152
* Can be overridden by setting system property {@code org.eclipse.rdf4j.rio.jsonld.hierarchical_view}.
154153
*
155154
*/
156-
public static final RioSetting<Boolean> HIERARCHICAL_VIEW = new BooleanRioSetting(
155+
public static final BooleanRioSetting HIERARCHICAL_VIEW = new BooleanRioSetting(
157156
"org.eclipse.rdf4j.rio.jsonld.hierarchical_view", "Hierarchical representation of the JSON", Boolean.FALSE);
158157

159158
/**
160-
* Whitelist of remote/local resources that the JSON-LD parser can retrieve. Set of URIs as strings.
159+
* Whitelist of remote/local resources that the JSON-LD parser can retrieve. Set of URIs as strings. This can be
160+
* overridden by setting a system property with the key {@code org.eclipse.rdf4j.rio.jsonld_whitelist} and a JSON
161+
* array of the desired values.
161162
* <p>
162163
* Default:
163164
* {@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");
164165
*
165166
*/
166-
public static final RioSetting<Set<String>> WHITELIST = new RioSettingImpl<>(
167+
public static final SetRioSetting<String> WHITELIST = new SetRioSetting<>(
167168
"org.eclipse.rdf4j.rio.jsonld_whitelist",
168169
"Whitelist of remote/local resources that the JSON-LD parser can retrieve. Set of URIs as strings.",
169170
Set.of(
@@ -195,11 +196,13 @@ public class JSONLDSettings {
195196
));
196197

197198
/**
198-
* Secure mode only allows loading remote/local resources (ex. context from url) that are whitelisted.
199+
* Secure mode only allows loading remote/local resources (ex. context from url) that are whitelisted. This can be
200+
* overridden by setting a system property with the key {@code org.eclipse.rdf4j.rio.jsonld_secure_mode} and a
201+
* boolean value.
199202
* <p>
200203
* Default: true
201204
*/
202-
public static final RioSetting<Boolean> SECURE_MODE = new RioSettingImpl<>(
205+
public static final BooleanRioSetting SECURE_MODE = new BooleanRioSetting(
203206
"org.eclipse.rdf4j.rio.jsonld_secure_mode",
204207
"Secure mode only allows loading remote/local resources (ex. context from url) that are whitelisted.",
205208
Boolean.TRUE);
@@ -211,7 +214,7 @@ public class JSONLDSettings {
211214
* <p>
212215
* Default: true
213216
*/
214-
public static final RioSetting<Boolean> DOCUMENT_LOADER_CACHE = new RioSettingImpl<>(
217+
public static final BooleanRioSetting DOCUMENT_LOADER_CACHE = new BooleanRioSetting(
215218
"org.eclipse.rdf4j.rio.jsonld_document_loader_cache",
216219
"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.",
217220
Boolean.TRUE);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
******************************************************************************/
11+
12+
package org.eclipse.rdf4j.rio.helpers;
13+
14+
import java.util.HashSet;
15+
import java.util.List;
16+
import java.util.Set;
17+
18+
import org.eclipse.rdf4j.rio.RioSetting;
19+
20+
import com.fasterxml.jackson.core.JsonProcessingException;
21+
import com.fasterxml.jackson.core.type.TypeReference;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
24+
/**
25+
* A {@link RioSetting} with a {@link Set} value. The given default for the setting can be overridden by means of a
26+
* System property with a name equal to the setting key, and a string value of a JSON array of the desired values.
27+
*
28+
* @param <T> the type of the elements in the set
29+
*/
30+
public final class SetRioSetting<T> extends AbstractRioSetting<Set<T>> {
31+
32+
private static final long serialVersionUID = 142127221198985291L;
33+
34+
public SetRioSetting(String key, String description, Set<T> defaultValue) {
35+
super(key, description, defaultValue);
36+
}
37+
38+
@Override
39+
public Set<T> convert(String stringRepresentation) {
40+
ObjectMapper objectMapper = new ObjectMapper();
41+
try {
42+
return new HashSet<>(objectMapper.readValue(stringRepresentation, new TypeReference<List<T>>() {
43+
}));
44+
} catch (JsonProcessingException e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
49+
}

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MAINTAINER Bart Hanssens (bart.hanssens@bosa.fgov.be)
1717
RUN apt-get clean && apt-get update && apt-get upgrade -y && apt-get clean
1818

1919
ENV JAVA_OPTS="-Xmx2g"
20-
ENV CATALINA_OPTS="-Dorg.eclipse.rdf4j.appdata.basedir=/var/rdf4j"
20+
ENV CATALINA_OPTS="-Dorg.eclipse.rdf4j.appdata.basedir=/var/rdf4j -Dorg.eclipse.rdf4j.rio.jsonld_secure_mode=false"
2121

2222
RUN adduser --system tomcat
2323

0 commit comments

Comments
 (0)