Added a UriFactory for allowing local resources in testing
This commit is contained in:
parent
e7de6c6ebc
commit
1677a0b359
@ -7,6 +7,7 @@ import static org.oneedtech.inspect.core.probe.RunContext.Key.JSON_DOCUMENT_LOAD
|
|||||||
import static org.oneedtech.inspect.core.probe.RunContext.Key.JWT_CREDENTIAL_NODE_NAME;
|
import static org.oneedtech.inspect.core.probe.RunContext.Key.JWT_CREDENTIAL_NODE_NAME;
|
||||||
import static org.oneedtech.inspect.core.probe.RunContext.Key.PNG_CREDENTIAL_KEY;
|
import static org.oneedtech.inspect.core.probe.RunContext.Key.PNG_CREDENTIAL_KEY;
|
||||||
import static org.oneedtech.inspect.core.probe.RunContext.Key.SVG_CREDENTIAL_QNAME;
|
import static org.oneedtech.inspect.core.probe.RunContext.Key.SVG_CREDENTIAL_QNAME;
|
||||||
|
import static org.oneedtech.inspect.core.probe.RunContext.Key.URI_RESOURCE_FACTORY;
|
||||||
import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException;
|
import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException;
|
||||||
import static org.oneedtech.inspect.util.code.Defensives.checkNotNull;
|
import static org.oneedtech.inspect.util.code.Defensives.checkNotNull;
|
||||||
import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT;
|
import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT;
|
||||||
@ -33,6 +34,7 @@ import org.oneedtech.inspect.vc.probe.AssertionRevocationListProbe;
|
|||||||
import org.oneedtech.inspect.vc.probe.ExpirationProbe;
|
import org.oneedtech.inspect.vc.probe.ExpirationProbe;
|
||||||
import org.oneedtech.inspect.vc.probe.IssuanceProbe;
|
import org.oneedtech.inspect.vc.probe.IssuanceProbe;
|
||||||
import org.oneedtech.inspect.vc.probe.VerificationDependenciesProbe;
|
import org.oneedtech.inspect.vc.probe.VerificationDependenciesProbe;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
|
|
||||||
import com.apicatalog.jsonld.loader.DocumentLoader;
|
import com.apicatalog.jsonld.loader.DocumentLoader;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -45,10 +47,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
public class OB20EndorsementInspector extends VCInspector implements SubInspector {
|
public class OB20EndorsementInspector extends VCInspector implements SubInspector {
|
||||||
|
|
||||||
private DocumentLoader documentLoader;
|
private DocumentLoader documentLoader;
|
||||||
|
private UriResourceFactory uriResourceFactory;
|
||||||
|
|
||||||
protected OB20EndorsementInspector(OB20EndorsementInspector.Builder builder) {
|
protected OB20EndorsementInspector(OB20EndorsementInspector.Builder builder) {
|
||||||
super(builder);
|
super(builder);
|
||||||
this.documentLoader = builder.documentLoader;
|
this.documentLoader = builder.documentLoader;
|
||||||
|
this.uriResourceFactory = builder.uriResourceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,6 +82,7 @@ public class OB20EndorsementInspector extends VCInspector implements SubInspecto
|
|||||||
.put(SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB20)
|
.put(SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB20)
|
||||||
.put(JSON_DOCUMENT_LOADER, documentLoader)
|
.put(JSON_DOCUMENT_LOADER, documentLoader)
|
||||||
.put(JWT_CREDENTIAL_NODE_NAME, Assertion.JWT_NODE_NAME)
|
.put(JWT_CREDENTIAL_NODE_NAME, Assertion.JWT_NODE_NAME)
|
||||||
|
.put(URI_RESOURCE_FACTORY, uriResourceFactory)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
parentObjects.entrySet().stream().forEach(entry -> {
|
parentObjects.entrySet().stream().forEach(entry -> {
|
||||||
@ -122,6 +127,7 @@ public class OB20EndorsementInspector extends VCInspector implements SubInspecto
|
|||||||
|
|
||||||
public static class Builder extends VCInspector.Builder<OB20EndorsementInspector.Builder> {
|
public static class Builder extends VCInspector.Builder<OB20EndorsementInspector.Builder> {
|
||||||
private DocumentLoader documentLoader;
|
private DocumentLoader documentLoader;
|
||||||
|
private UriResourceFactory uriResourceFactory;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
@ -133,6 +139,12 @@ public class OB20EndorsementInspector extends VCInspector implements SubInspecto
|
|||||||
this.documentLoader = documentLoader;
|
this.documentLoader = documentLoader;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder uriResourceFactory(UriResourceFactory uriResourceFactory) {
|
||||||
|
this.uriResourceFactory = uriResourceFactory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT;
|
|||||||
import static org.oneedtech.inspect.vc.Credential.CREDENTIAL_KEY;
|
import static org.oneedtech.inspect.vc.Credential.CREDENTIAL_KEY;
|
||||||
import static org.oneedtech.inspect.vc.util.JsonNodeUtil.asNodeList;
|
import static org.oneedtech.inspect.vc.util.JsonNodeUtil.asNodeList;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -48,6 +46,7 @@ import org.oneedtech.inspect.vc.probe.TypePropertyProbe;
|
|||||||
import org.oneedtech.inspect.vc.probe.VerificationDependenciesProbe;
|
import org.oneedtech.inspect.vc.probe.VerificationDependenciesProbe;
|
||||||
import org.oneedtech.inspect.vc.probe.VerificationJWTProbe;
|
import org.oneedtech.inspect.vc.probe.VerificationJWTProbe;
|
||||||
import org.oneedtech.inspect.vc.probe.validation.ValidationPropertyProbeFactory;
|
import org.oneedtech.inspect.vc.probe.validation.ValidationPropertyProbeFactory;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
|
|
||||||
import com.apicatalog.jsonld.loader.DocumentLoader;
|
import com.apicatalog.jsonld.loader.DocumentLoader;
|
||||||
@ -55,8 +54,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import foundation.identity.jsonld.ConfigurableDocumentLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A verifier for Open Badges 2.0.
|
* A verifier for Open Badges 2.0.
|
||||||
* @author xaracil
|
* @author xaracil
|
||||||
@ -82,6 +79,7 @@ public class OB20Inspector extends VCInspector {
|
|||||||
ObjectMapper mapper = ObjectMapperCache.get(DEFAULT);
|
ObjectMapper mapper = ObjectMapperCache.get(DEFAULT);
|
||||||
JsonPathEvaluator jsonPath = new JsonPathEvaluator(mapper);
|
JsonPathEvaluator jsonPath = new JsonPathEvaluator(mapper);
|
||||||
DocumentLoader documentLoader = getDocumentLoader();
|
DocumentLoader documentLoader = getDocumentLoader();
|
||||||
|
UriResourceFactory uriResourceFactory = getUriResourceFactory(documentLoader);
|
||||||
|
|
||||||
RunContext ctx = new RunContext.Builder()
|
RunContext ctx = new RunContext.Builder()
|
||||||
.put(this)
|
.put(this)
|
||||||
@ -93,6 +91,7 @@ public class OB20Inspector extends VCInspector {
|
|||||||
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB20)
|
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB20)
|
||||||
.put(Key.JSON_DOCUMENT_LOADER, documentLoader)
|
.put(Key.JSON_DOCUMENT_LOADER, documentLoader)
|
||||||
.put(Key.JWT_CREDENTIAL_NODE_NAME, Assertion.JWT_NODE_NAME)
|
.put(Key.JWT_CREDENTIAL_NODE_NAME, Assertion.JWT_NODE_NAME)
|
||||||
|
.put(Key.URI_RESOURCE_FACTORY, uriResourceFactory)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
List<ReportItems> accumulator = new ArrayList<>();
|
List<ReportItems> accumulator = new ArrayList<>();
|
||||||
@ -189,7 +188,10 @@ public class OB20Inspector extends VCInspector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Embedded endorsements. Pass document loader because it has already cached documents, and it has localdomains for testing
|
// Embedded endorsements. Pass document loader because it has already cached documents, and it has localdomains for testing
|
||||||
OB20EndorsementInspector endorsementInspector = new OB20EndorsementInspector.Builder().documentLoader(documentLoader).build();
|
OB20EndorsementInspector endorsementInspector = new OB20EndorsementInspector.Builder()
|
||||||
|
.documentLoader(documentLoader)
|
||||||
|
.uriResourceFactory(uriResourceFactory)
|
||||||
|
.build();
|
||||||
|
|
||||||
// get endorsements for all JSON_LD objects in the graph
|
// get endorsements for all JSON_LD objects in the graph
|
||||||
List<JsonNode> endorsements = jsonLdGeneratedObjects.stream().flatMap(node -> {
|
List<JsonNode> endorsements = jsonLdGeneratedObjects.stream().flatMap(node -> {
|
||||||
@ -201,7 +203,7 @@ public class OB20Inspector extends VCInspector {
|
|||||||
for(JsonNode node : endorsements) {
|
for(JsonNode node : endorsements) {
|
||||||
probeCount++;
|
probeCount++;
|
||||||
// get endorsement json from context
|
// get endorsement json from context
|
||||||
UriResource uriResource = resolveUriResource(ctx, node.asText());
|
UriResource uriResource = uriResourceFactory.of(node.asText());
|
||||||
JsonLdGeneratedObject resolved = (JsonLdGeneratedObject) ctx.getGeneratedObject(JsonLDCompactionProve.getId(uriResource));
|
JsonLdGeneratedObject resolved = (JsonLdGeneratedObject) ctx.getGeneratedObject(JsonLDCompactionProve.getId(uriResource));
|
||||||
if (resolved == null) {
|
if (resolved == null) {
|
||||||
throw new IllegalArgumentException("endorsement " + node.toString() + " not found in graph");
|
throw new IllegalArgumentException("endorsement " + node.toString() + " not found in graph");
|
||||||
@ -244,20 +246,4 @@ public class OB20Inspector extends VCInspector {
|
|||||||
*/
|
*/
|
||||||
public static final String ALLOW_LOCAL_REDIRECTION = "ALLOW_LOCAL_REDIRECTION";
|
public static final String ALLOW_LOCAL_REDIRECTION = "ALLOW_LOCAL_REDIRECTION";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UriResource resolveUriResource(RunContext ctx, String url) throws URISyntaxException {
|
|
||||||
URI uri = new URI(url);
|
|
||||||
UriResource initialUriResource = new UriResource(uri);
|
|
||||||
UriResource uriResource = initialUriResource;
|
|
||||||
|
|
||||||
// check if uri points to a local resource
|
|
||||||
if (ctx.get(Key.JSON_DOCUMENT_LOADER) instanceof ConfigurableDocumentLoader) {
|
|
||||||
if (ConfigurableDocumentLoader.getDefaultHttpLoader() instanceof CachingDocumentLoader.HttpLoader) {
|
|
||||||
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
|
||||||
uriResource = new UriResource(resolvedUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uriResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ import org.oneedtech.inspect.core.report.Report;
|
|||||||
import org.oneedtech.inspect.core.report.ReportItems;
|
import org.oneedtech.inspect.core.report.ReportItems;
|
||||||
import org.oneedtech.inspect.util.code.Tuple;
|
import org.oneedtech.inspect.util.code.Tuple;
|
||||||
import org.oneedtech.inspect.vc.jsonld.probe.ExtensionProbe;
|
import org.oneedtech.inspect.vc.jsonld.probe.ExtensionProbe;
|
||||||
|
import org.oneedtech.inspect.vc.resource.DefaultUriResourceFactory;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
@ -82,6 +84,10 @@ public abstract class VCInspector extends Inspector {
|
|||||||
return new CachingDocumentLoader();
|
return new CachingDocumentLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected UriResourceFactory getUriResourceFactory(DocumentLoader documentLoader) {
|
||||||
|
return new DefaultUriResourceFactory();
|
||||||
|
}
|
||||||
|
|
||||||
protected List<Tuple<ExtensionProbe, JsonNode>> getExtensionProbes(JsonNode node, String entryPath) {
|
protected List<Tuple<ExtensionProbe, JsonNode>> getExtensionProbes(JsonNode node, String entryPath) {
|
||||||
List<Tuple<ExtensionProbe, JsonNode>> probes = new ArrayList<>();
|
List<Tuple<ExtensionProbe, JsonNode>> probes = new ArrayList<>();
|
||||||
if (!node.isObject()) {
|
if (!node.isObject()) {
|
||||||
|
@ -26,6 +26,7 @@ import org.oneedtech.inspect.vc.Assertion.ValueType;
|
|||||||
import org.oneedtech.inspect.vc.Validation;
|
import org.oneedtech.inspect.vc.Validation;
|
||||||
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
||||||
import org.oneedtech.inspect.vc.probe.CredentialParseProbe;
|
import org.oneedtech.inspect.vc.probe.CredentialParseProbe;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
import org.oneedtech.inspect.vc.util.PrimitiveValueValidator;
|
import org.oneedtech.inspect.vc.util.PrimitiveValueValidator;
|
||||||
@ -126,9 +127,11 @@ public class GraphFetcherProbe extends Probe<JsonNode> {
|
|||||||
|
|
||||||
private ReportItems fetchNode(RunContext ctx, ReportItems result, JsonNode idNode)
|
private ReportItems fetchNode(RunContext ctx, ReportItems result, JsonNode idNode)
|
||||||
throws URISyntaxException, Exception, JsonProcessingException, JsonMappingException {
|
throws URISyntaxException, Exception, JsonProcessingException, JsonMappingException {
|
||||||
UriResource uriResource = resolveUriResource(ctx, idNode.asText().strip());
|
System.out.println("fetchNode " + idNode.asText().strip());
|
||||||
|
UriResource uriResource = ((UriResourceFactory) ctx.get(Key.URI_RESOURCE_FACTORY)).of(idNode.asText().strip());
|
||||||
JsonLdGeneratedObject resolved = (JsonLdGeneratedObject) ctx.getGeneratedObject(JsonLDCompactionProve.getId(uriResource));
|
JsonLdGeneratedObject resolved = (JsonLdGeneratedObject) ctx.getGeneratedObject(JsonLDCompactionProve.getId(uriResource));
|
||||||
if (resolved == null) {
|
if (resolved == null) {
|
||||||
|
System.out.println("parsing and loading " + idNode.asText().strip());
|
||||||
result = new ReportItems(List.of(result, new CredentialParseProbe().run(uriResource, ctx)));
|
result = new ReportItems(List.of(result, new CredentialParseProbe().run(uriResource, ctx)));
|
||||||
if (!result.contains(Outcome.FATAL, Outcome.EXCEPTION)) {
|
if (!result.contains(Outcome.FATAL, Outcome.EXCEPTION)) {
|
||||||
Assertion fetchedAssertion = (Assertion) ctx.getGeneratedObject(uriResource.getID());
|
Assertion fetchedAssertion = (Assertion) ctx.getGeneratedObject(uriResource.getID());
|
||||||
@ -200,21 +203,6 @@ public class GraphFetcherProbe extends Probe<JsonNode> {
|
|||||||
return matcher.matches();
|
return matcher.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UriResource resolveUriResource(RunContext ctx, String url) throws URISyntaxException {
|
|
||||||
URI uri = new URI(url);
|
|
||||||
UriResource initialUriResource = new UriResource(uri);
|
|
||||||
UriResource uriResource = initialUriResource;
|
|
||||||
|
|
||||||
// check if uri points to a local resource
|
|
||||||
if (ctx.get(Key.JSON_DOCUMENT_LOADER) instanceof ConfigurableDocumentLoader) {
|
|
||||||
if (ConfigurableDocumentLoader.getDefaultHttpLoader() instanceof CachingDocumentLoader.HttpLoader) {
|
|
||||||
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
|
||||||
uriResource = new UriResource(resolvedUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uriResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String ID = GraphFetcherProbe.class.getSimpleName();
|
public static final String ID = GraphFetcherProbe.class.getSimpleName();
|
||||||
public static final String URN_REGEX = "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'";
|
public static final String URN_REGEX = "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'";
|
||||||
protected final static Logger logger = LogManager.getLogger(GraphFetcherProbe.class);
|
protected final static Logger logger = LogManager.getLogger(GraphFetcherProbe.class);
|
||||||
|
@ -12,7 +12,6 @@ import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
|||||||
|
|
||||||
import com.apicatalog.jsonld.JsonLd;
|
import com.apicatalog.jsonld.JsonLd;
|
||||||
import com.apicatalog.jsonld.JsonLdOptions;
|
import com.apicatalog.jsonld.JsonLdOptions;
|
||||||
import com.apicatalog.jsonld.api.CompactionApi;
|
|
||||||
import com.apicatalog.jsonld.document.JsonDocument;
|
import com.apicatalog.jsonld.document.JsonDocument;
|
||||||
import com.apicatalog.jsonld.loader.DocumentLoader;
|
import com.apicatalog.jsonld.loader.DocumentLoader;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import org.oneedtech.inspect.core.report.ReportItems;
|
|||||||
import org.oneedtech.inspect.util.resource.UriResource;
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
||||||
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
@ -41,9 +42,10 @@ public class AssertionRevocationListProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
public ReportItems run(JsonLdGeneratedObject jsonLdGeneratedObject, RunContext ctx) throws Exception {
|
public ReportItems run(JsonLdGeneratedObject jsonLdGeneratedObject, RunContext ctx) throws Exception {
|
||||||
ObjectMapper mapper = (ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER);
|
ObjectMapper mapper = (ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER);
|
||||||
JsonNode jsonNode = (mapper).readTree(jsonLdGeneratedObject.getJson());
|
JsonNode jsonNode = (mapper).readTree(jsonLdGeneratedObject.getJson());
|
||||||
|
UriResourceFactory uriResourceFactory = (UriResourceFactory) ctx.get(Key.URI_RESOURCE_FACTORY);
|
||||||
|
|
||||||
// get badge
|
// get badge
|
||||||
UriResource badgeUriResource = resolveUriResource(ctx, getBadgeClaimId(jsonNode));
|
UriResource badgeUriResource = uriResourceFactory.of(getBadgeClaimId(jsonNode));
|
||||||
JsonLdGeneratedObject badgeObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject badgeObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(badgeUriResource));
|
JsonLDCompactionProve.getId(badgeUriResource));
|
||||||
|
|
||||||
@ -51,7 +53,7 @@ public class AssertionRevocationListProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
JsonNode badgeNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode badgeNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
.readTree(badgeObject.getJson());
|
.readTree(badgeObject.getJson());
|
||||||
|
|
||||||
UriResource issuerUriResource = resolveUriResource(ctx, badgeNode.get("issuer").asText().strip());
|
UriResource issuerUriResource = uriResourceFactory.of(badgeNode.get("issuer").asText().strip());
|
||||||
JsonLdGeneratedObject issuerObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject issuerObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(issuerUriResource));
|
JsonLDCompactionProve.getId(issuerUriResource));
|
||||||
JsonNode issuerNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode issuerNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
@ -63,7 +65,7 @@ public class AssertionRevocationListProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
return success(ctx);
|
return success(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
UriResource revocationListUriResource = resolveUriResource(ctx, revocationListIdNode.asText().strip());
|
UriResource revocationListUriResource = uriResourceFactory.of(revocationListIdNode.asText().strip());
|
||||||
JsonLdGeneratedObject revocationListObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject revocationListObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(revocationListUriResource));
|
JsonLDCompactionProve.getId(revocationListUriResource));
|
||||||
JsonNode revocationListNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode revocationListNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
@ -88,21 +90,6 @@ public class AssertionRevocationListProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
return success(ctx);
|
return success(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UriResource resolveUriResource(RunContext ctx, String url) throws URISyntaxException {
|
|
||||||
URI uri = new URI(url);
|
|
||||||
UriResource initialUriResource = new UriResource(uri);
|
|
||||||
UriResource uriResource = initialUriResource;
|
|
||||||
|
|
||||||
// check if uri points to a local resource
|
|
||||||
if (ctx.get(Key.JSON_DOCUMENT_LOADER) instanceof ConfigurableDocumentLoader) {
|
|
||||||
if (ConfigurableDocumentLoader.getDefaultHttpLoader() instanceof CachingDocumentLoader.HttpLoader) {
|
|
||||||
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
|
||||||
uriResource = new UriResource(resolvedUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uriResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ID of the node with name propertyName
|
* Return the ID of the node with name propertyName
|
||||||
* @param jsonNode node
|
* @param jsonNode node
|
||||||
|
@ -13,14 +13,12 @@ import org.oneedtech.inspect.core.report.ReportItems;
|
|||||||
import org.oneedtech.inspect.util.resource.UriResource;
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
||||||
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import foundation.identity.jsonld.ConfigurableDocumentLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verification probe for Open Badges 2.0
|
* Verification probe for Open Badges 2.0
|
||||||
* Maps to "ASSERTION_VERIFICATION_DEPENDENCIES" task in python implementation
|
* Maps to "ASSERTION_VERIFICATION_DEPENDENCIES" task in python implementation
|
||||||
@ -45,13 +43,14 @@ public class VerificationDependenciesProbe extends Probe<JsonLdGeneratedObject>
|
|||||||
public ReportItems run(JsonLdGeneratedObject jsonLdGeneratedObject, RunContext ctx) throws Exception {
|
public ReportItems run(JsonLdGeneratedObject jsonLdGeneratedObject, RunContext ctx) throws Exception {
|
||||||
ObjectMapper mapper = (ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER);
|
ObjectMapper mapper = (ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER);
|
||||||
JsonNode jsonNode = (mapper).readTree(jsonLdGeneratedObject.getJson());
|
JsonNode jsonNode = (mapper).readTree(jsonLdGeneratedObject.getJson());
|
||||||
|
UriResourceFactory uriResourceFactory = (UriResourceFactory) ctx.get(Key.URI_RESOURCE_FACTORY);
|
||||||
|
|
||||||
JsonNode verificationNode = jsonNode.get("verification");
|
JsonNode verificationNode = jsonNode.get("verification");
|
||||||
checkNotNull(verificationNode);
|
checkNotNull(verificationNode);
|
||||||
String type = null;
|
String type = null;
|
||||||
if (verificationNode.isTextual()) {
|
if (verificationNode.isTextual()) {
|
||||||
// get verification from graph
|
// get verification from graph
|
||||||
UriResource verificationUriResource = resolveUriResource(ctx, verificationNode.asText().strip());
|
UriResource verificationUriResource = uriResourceFactory.of(verificationNode.asText().strip());
|
||||||
JsonLdGeneratedObject verificationObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject verificationObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(verificationUriResource));
|
JsonLDCompactionProve.getId(verificationUriResource));
|
||||||
JsonNode verificationRootNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode verificationRootNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
@ -63,14 +62,14 @@ public class VerificationDependenciesProbe extends Probe<JsonLdGeneratedObject>
|
|||||||
|
|
||||||
if ("HostedBadge".equals(type)) {
|
if ("HostedBadge".equals(type)) {
|
||||||
// get badge
|
// get badge
|
||||||
UriResource badgeUriResource = resolveUriResource(ctx, getBadgeClaimId(jsonNode));
|
UriResource badgeUriResource = uriResourceFactory.of(getBadgeClaimId(jsonNode));
|
||||||
JsonLdGeneratedObject badgeObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject badgeObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(badgeUriResource));
|
JsonLDCompactionProve.getId(badgeUriResource));
|
||||||
JsonNode badgeNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode badgeNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
.readTree(badgeObject.getJson());
|
.readTree(badgeObject.getJson());
|
||||||
|
|
||||||
// get issuer from badge
|
// get issuer from badge
|
||||||
UriResource issuerUriResource = resolveUriResource(ctx, badgeNode.get("issuer").asText().strip());
|
UriResource issuerUriResource = uriResourceFactory.of(badgeNode.get("issuer").asText().strip());
|
||||||
|
|
||||||
JsonLdGeneratedObject issuerObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject issuerObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(issuerUriResource));
|
JsonLDCompactionProve.getId(issuerUriResource));
|
||||||
@ -139,21 +138,6 @@ public class VerificationDependenciesProbe extends Probe<JsonLdGeneratedObject>
|
|||||||
return issuerUri.getAuthority();
|
return issuerUri.getAuthority();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UriResource resolveUriResource(RunContext ctx, String url) throws URISyntaxException {
|
|
||||||
URI uri = new URI(url);
|
|
||||||
UriResource initialUriResource = new UriResource(uri);
|
|
||||||
UriResource uriResource = initialUriResource;
|
|
||||||
|
|
||||||
// check if uri points to a local resource
|
|
||||||
if (ctx.get(Key.JSON_DOCUMENT_LOADER) instanceof ConfigurableDocumentLoader) {
|
|
||||||
if (ConfigurableDocumentLoader.getDefaultHttpLoader() instanceof CachingDocumentLoader.HttpLoader) {
|
|
||||||
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
|
||||||
uriResource = new UriResource(resolvedUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uriResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ID of the node with name propertyName
|
* Return the ID of the node with name propertyName
|
||||||
* @param jsonNode node
|
* @param jsonNode node
|
||||||
|
@ -15,6 +15,7 @@ import org.oneedtech.inspect.core.report.ReportItems;
|
|||||||
import org.oneedtech.inspect.util.resource.UriResource;
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
||||||
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
@ -44,16 +45,17 @@ public class VerificationJWTProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
public ReportItems run(JsonLdGeneratedObject assertion, RunContext ctx) throws Exception {
|
public ReportItems run(JsonLdGeneratedObject assertion, RunContext ctx) throws Exception {
|
||||||
ObjectMapper mapper = (ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER);
|
ObjectMapper mapper = (ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER);
|
||||||
JsonNode assertionNode = (mapper).readTree(assertion.getJson());
|
JsonNode assertionNode = (mapper).readTree(assertion.getJson());
|
||||||
|
UriResourceFactory uriResourceFactory = (UriResourceFactory) ctx.get(Key.URI_RESOURCE_FACTORY);
|
||||||
|
|
||||||
// get badge from assertion
|
// get badge from assertion
|
||||||
UriResource badgeUriResource = resolveUriResource(ctx, assertionNode.get("badge").asText().strip());
|
UriResource badgeUriResource = uriResourceFactory.of(assertionNode.get("badge").asText().strip());
|
||||||
JsonLdGeneratedObject badgeObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject badgeObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(badgeUriResource));
|
JsonLDCompactionProve.getId(badgeUriResource));
|
||||||
JsonNode badgeNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode badgeNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
.readTree(badgeObject.getJson());
|
.readTree(badgeObject.getJson());
|
||||||
|
|
||||||
// get issuer from badge
|
// get issuer from badge
|
||||||
UriResource issuerUriResource = resolveUriResource(ctx, badgeNode.get("issuer").asText().strip());
|
UriResource issuerUriResource = uriResourceFactory.of(badgeNode.get("issuer").asText().strip());
|
||||||
|
|
||||||
JsonLdGeneratedObject issuerObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject issuerObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(issuerUriResource));
|
JsonLDCompactionProve.getId(issuerUriResource));
|
||||||
@ -71,7 +73,7 @@ public class VerificationJWTProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get creator from id
|
// get creator from id
|
||||||
UriResource creatorUriResource = resolveUriResource(ctx, creatorId);
|
UriResource creatorUriResource = uriResourceFactory.of(creatorId);
|
||||||
JsonLdGeneratedObject creatorObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
JsonLdGeneratedObject creatorObject = (JsonLdGeneratedObject) ctx.getGeneratedObject(
|
||||||
JsonLDCompactionProve.getId(creatorUriResource));
|
JsonLDCompactionProve.getId(creatorUriResource));
|
||||||
JsonNode creatorNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
JsonNode creatorNode = ((ObjectMapper) ctx.get(Key.JACKSON_OBJECTMAPPER))
|
||||||
@ -106,21 +108,6 @@ public class VerificationJWTProbe extends Probe<JsonLdGeneratedObject> {
|
|||||||
return success(ctx);
|
return success(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UriResource resolveUriResource(RunContext ctx, String url) throws URISyntaxException {
|
|
||||||
URI uri = new URI(url);
|
|
||||||
UriResource initialUriResource = new UriResource(uri);
|
|
||||||
UriResource uriResource = initialUriResource;
|
|
||||||
|
|
||||||
// check if uri points to a local resource
|
|
||||||
if (ctx.get(Key.JSON_DOCUMENT_LOADER) instanceof ConfigurableDocumentLoader) {
|
|
||||||
if (ConfigurableDocumentLoader.getDefaultHttpLoader() instanceof CachingDocumentLoader.HttpLoader) {
|
|
||||||
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
|
||||||
uriResource = new UriResource(resolvedUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uriResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final List<String> allowedTypes = List.of("id", "email", "url", "telephone");
|
private static final List<String> allowedTypes = List.of("id", "email", "url", "telephone");
|
||||||
public static final String ID = VerificationJWTProbe.class.getSimpleName();
|
public static final String ID = VerificationJWTProbe.class.getSimpleName();
|
||||||
|
|
||||||
|
@ -5,10 +5,12 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.oneedtech.inspect.core.probe.RunContext;
|
import org.oneedtech.inspect.core.probe.RunContext;
|
||||||
|
import org.oneedtech.inspect.core.probe.RunContext.Key;
|
||||||
import org.oneedtech.inspect.core.report.ReportItems;
|
import org.oneedtech.inspect.core.report.ReportItems;
|
||||||
import org.oneedtech.inspect.util.resource.MimeType;
|
import org.oneedtech.inspect.util.resource.MimeType;
|
||||||
import org.oneedtech.inspect.util.resource.UriResource;
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
import org.oneedtech.inspect.vc.Validation;
|
import org.oneedtech.inspect.vc.Validation;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.PrimitiveValueValidator;
|
import org.oneedtech.inspect.vc.util.PrimitiveValueValidator;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -56,7 +58,7 @@ public class ValidationImagePropertyProbe extends ValidationPropertyProbe {
|
|||||||
}
|
}
|
||||||
} else if (!url.isEmpty()) {
|
} else if (!url.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
UriResource uriResource = resolveUriResource(ctx, url);
|
UriResource uriResource = ((UriResourceFactory) ctx.get(Key.URI_RESOURCE_FACTORY)).of(url);
|
||||||
// TODO: load resource from cache
|
// TODO: load resource from cache
|
||||||
// TODO: check accept type -> 'Accept': 'application/ld+json, application/json, image/png, image/svg+xml'
|
// TODO: check accept type -> 'Accept': 'application/ld+json, application/json, image/png, image/svg+xml'
|
||||||
uriResource.asByteSource();
|
uriResource.asByteSource();
|
||||||
|
@ -22,6 +22,7 @@ import org.oneedtech.inspect.vc.Validation;
|
|||||||
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
import org.oneedtech.inspect.vc.jsonld.JsonLdGeneratedObject;
|
||||||
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
import org.oneedtech.inspect.vc.jsonld.probe.JsonLDCompactionProve;
|
||||||
import org.oneedtech.inspect.vc.probe.PropertyProbe;
|
import org.oneedtech.inspect.vc.probe.PropertyProbe;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
@ -126,7 +127,7 @@ public class ValidationPropertyProbe extends PropertyProbe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get node from context
|
// get node from context
|
||||||
UriResource uriResource = resolveUriResource(ctx, childNode.asText());
|
UriResource uriResource = ((UriResourceFactory) ctx.get(Key.URI_RESOURCE_FACTORY)).of(childNode.asText().strip());
|
||||||
JsonLdGeneratedObject resolved = (JsonLdGeneratedObject) ctx.getGeneratedObject(JsonLDCompactionProve.getId(uriResource));
|
JsonLdGeneratedObject resolved = (JsonLdGeneratedObject) ctx.getGeneratedObject(JsonLDCompactionProve.getId(uriResource));
|
||||||
if (resolved == null) {
|
if (resolved == null) {
|
||||||
if (validation.isAllowRemoteUrl() && URL.getValidationFunction().apply(childNode)) {
|
if (validation.isAllowRemoteUrl() && URL.getValidationFunction().apply(childNode)) {
|
||||||
@ -153,21 +154,6 @@ public class ValidationPropertyProbe extends PropertyProbe {
|
|||||||
return result.size() > 0 ? result : success(ctx);
|
return result.size() > 0 ? result : success(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UriResource resolveUriResource(RunContext ctx, String url) throws URISyntaxException {
|
|
||||||
URI uri = new URI(url);
|
|
||||||
UriResource initialUriResource = new UriResource(uri);
|
|
||||||
UriResource uriResource = initialUriResource;
|
|
||||||
|
|
||||||
// check if uri points to a local resource
|
|
||||||
if (ctx.get(Key.JSON_DOCUMENT_LOADER) instanceof ConfigurableDocumentLoader) {
|
|
||||||
if (ConfigurableDocumentLoader.getDefaultHttpLoader() instanceof CachingDocumentLoader.HttpLoader) {
|
|
||||||
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
|
||||||
uriResource = new UriResource(resolvedUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uriResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReportItems validatePrerequisites(JsonNode node, RunContext ctx) {
|
private ReportItems validatePrerequisites(JsonNode node, RunContext ctx) {
|
||||||
List<ReportItems> results = validation.getPrerequisites().stream()
|
List<ReportItems> results = validation.getPrerequisites().stream()
|
||||||
.map(v -> ValidationPropertyProbeFactory.of(validation.getName(), v, validation.isFullValidate()))
|
.map(v -> ValidationPropertyProbeFactory.of(validation.getName(), v, validation.isFullValidate()))
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.oneedtech.inspect.vc.resource;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default factory for URIResources
|
||||||
|
* @author xaracil
|
||||||
|
*/
|
||||||
|
public class DefaultUriResourceFactory implements UriResourceFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UriResource of(String uri) throws URISyntaxException {
|
||||||
|
return new UriResource(new URI(uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package org.oneedtech.inspect.vc.resource;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory interface for URI resources
|
||||||
|
* @author xaracil
|
||||||
|
*/
|
||||||
|
public interface UriResourceFactory {
|
||||||
|
public UriResource of(String uri) throws URISyntaxException;
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package org.oneedtech.inspect.vc.resource;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import org.oneedtech.inspect.util.resource.UriResource;
|
||||||
|
import org.oneedtech.inspect.vc.util.CachingDocumentLoader;
|
||||||
|
|
||||||
|
import com.apicatalog.jsonld.loader.DocumentLoader;
|
||||||
|
|
||||||
|
import foundation.identity.jsonld.ConfigurableDocumentLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UriResource factory for test, resolving local references
|
||||||
|
* @author xaracil
|
||||||
|
*/
|
||||||
|
public class TestUriResourceFactory implements UriResourceFactory {
|
||||||
|
|
||||||
|
final DocumentLoader documentLoader;
|
||||||
|
|
||||||
|
public TestUriResourceFactory(DocumentLoader documentLoader) {
|
||||||
|
this.documentLoader = documentLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UriResource of(String uriString) throws URISyntaxException {
|
||||||
|
URI uri = new URI(uriString);
|
||||||
|
if (documentLoader instanceof CachingDocumentLoader) {
|
||||||
|
URI resolvedUri = ((CachingDocumentLoader.HttpLoader) ConfigurableDocumentLoader.getDefaultHttpLoader()).resolve(uri);
|
||||||
|
uri = resolvedUri;
|
||||||
|
}
|
||||||
|
return new UriResource(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,8 @@ import java.util.Map;
|
|||||||
import org.oneedtech.inspect.util.resource.ResourceType;
|
import org.oneedtech.inspect.util.resource.ResourceType;
|
||||||
import org.oneedtech.inspect.util.spec.Specification;
|
import org.oneedtech.inspect.util.spec.Specification;
|
||||||
import org.oneedtech.inspect.vc.OB20Inspector;
|
import org.oneedtech.inspect.vc.OB20Inspector;
|
||||||
|
import org.oneedtech.inspect.vc.resource.TestUriResourceFactory;
|
||||||
|
import org.oneedtech.inspect.vc.resource.UriResourceFactory;
|
||||||
|
|
||||||
import com.apicatalog.jsonld.loader.DocumentLoader;
|
import com.apicatalog.jsonld.loader.DocumentLoader;
|
||||||
|
|
||||||
@ -32,6 +34,11 @@ public class TestOB20Inspector extends OB20Inspector {
|
|||||||
return new CachingDocumentLoader(localDomains);
|
return new CachingDocumentLoader(localDomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UriResourceFactory getUriResourceFactory(DocumentLoader documentLoader) {
|
||||||
|
return new TestUriResourceFactory(documentLoader);
|
||||||
|
}
|
||||||
|
|
||||||
public static class TestBuilder extends OB20Inspector.Builder {
|
public static class TestBuilder extends OB20Inspector.Builder {
|
||||||
final Map<URI, String> localDomains;
|
final Map<URI, String> localDomains;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user