misc small edits
This commit is contained in:
parent
5d5f3f7588
commit
c655b3ca1c
@ -45,7 +45,7 @@ public class Credential extends GeneratedObject {
|
|||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode asJson() {
|
public JsonNode getJson() {
|
||||||
return jsonData;
|
return jsonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import java.util.Map;
|
|||||||
import org.oneedtech.inspect.core.SubInspector;
|
import org.oneedtech.inspect.core.SubInspector;
|
||||||
import org.oneedtech.inspect.core.probe.GeneratedObject;
|
import org.oneedtech.inspect.core.probe.GeneratedObject;
|
||||||
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.probe.json.JsonPathEvaluator;
|
import org.oneedtech.inspect.core.probe.json.JsonPathEvaluator;
|
||||||
import org.oneedtech.inspect.core.report.Report;
|
import org.oneedtech.inspect.core.report.Report;
|
||||||
import org.oneedtech.inspect.core.report.ReportItems;
|
import org.oneedtech.inspect.core.report.ReportItems;
|
||||||
@ -18,7 +17,7 @@ import org.oneedtech.inspect.util.resource.Resource;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An inspector for EndersementCredential objects.
|
* An inspector for EndorsementCredential objects.
|
||||||
* @author mgylling
|
* @author mgylling
|
||||||
*/
|
*/
|
||||||
public class EndorsementInspector extends VCInspector implements SubInspector {
|
public class EndorsementInspector extends VCInspector implements SubInspector {
|
||||||
@ -30,7 +29,7 @@ public class EndorsementInspector extends VCInspector implements SubInspector {
|
|||||||
@Override
|
@Override
|
||||||
public Report run(Resource resource, Map<String, GeneratedObject> parentObjects) {
|
public Report run(Resource resource, Map<String, GeneratedObject> parentObjects) {
|
||||||
/*
|
/*
|
||||||
* resource is the top-level credential that embeds the endorsement, we
|
* The resource param is the top-level credential that embeds the endorsement, we
|
||||||
* expect parentObjects to provide a pointer to the JsonNode we should check
|
* expect parentObjects to provide a pointer to the JsonNode we should check
|
||||||
*/
|
*/
|
||||||
Credential endorsement = (Credential) parentObjects.get(ENDORSEMENT_KEY);
|
Credential endorsement = (Credential) parentObjects.get(ENDORSEMENT_KEY);
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package org.oneedtech.inspect.vc;
|
package org.oneedtech.inspect.vc;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
import static java.lang.Boolean.TRUE;
|
import static java.lang.Boolean.TRUE;
|
||||||
import static org.oneedtech.inspect.core.Inspector.Behavior.RESET_CACHES_ON_RUN;
|
import static org.oneedtech.inspect.core.Inspector.Behavior.RESET_CACHES_ON_RUN;
|
||||||
import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException;
|
import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException;
|
||||||
import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT;
|
import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT;
|
||||||
import static org.oneedtech.inspect.vc.EndorsementInspector.ENDORSEMENT_KEY;
|
|
||||||
import static org.oneedtech.inspect.vc.util.JsonNodeUtil.getEndorsements;
|
import static org.oneedtech.inspect.vc.util.JsonNodeUtil.getEndorsements;
|
||||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.oneedtech.inspect.core.probe.Outcome;
|
import org.oneedtech.inspect.core.probe.Outcome;
|
||||||
@ -92,15 +90,15 @@ public class OB30Inspector extends VCInspector {
|
|||||||
|
|
||||||
//validate the value of the type property
|
//validate the value of the type property
|
||||||
probeCount++;
|
probeCount++;
|
||||||
accumulator.add(new JsonArrayProbe(vcType).run(crd.asJson(), ctx));
|
accumulator.add(new JsonArrayProbe(vcType).run(crd.getJson(), ctx));
|
||||||
probeCount++;
|
probeCount++;
|
||||||
accumulator.add(new JsonArrayProbe(obType).run(crd.asJson(), ctx));
|
accumulator.add(new JsonArrayProbe(obType).run(crd.getJson(), ctx));
|
||||||
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
|
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
|
||||||
|
|
||||||
//validate against the canonical schema
|
//validate against the canonical schema
|
||||||
SchemaKey canonical = crd.getSchemaKey().orElseThrow();
|
SchemaKey canonical = crd.getSchemaKey().orElseThrow();
|
||||||
probeCount++;
|
probeCount++;
|
||||||
accumulator.add(new JsonSchemaProbe(canonical).run(crd.asJson(), ctx));
|
accumulator.add(new JsonSchemaProbe(canonical).run(crd.getJson(), ctx));
|
||||||
|
|
||||||
//validate against any inline schemas
|
//validate against any inline schemas
|
||||||
probeCount++;
|
probeCount++;
|
||||||
@ -148,7 +146,7 @@ public class OB30Inspector extends VCInspector {
|
|||||||
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
|
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
|
||||||
|
|
||||||
//embedded endorsements
|
//embedded endorsements
|
||||||
List<JsonNode> endorsements = getEndorsements(crd.asJson(), jsonPath);
|
List<JsonNode> endorsements = getEndorsements(crd.getJson(), jsonPath);
|
||||||
if(endorsements.size() > 0) {
|
if(endorsements.size() > 0) {
|
||||||
EndorsementInspector subInspector = new EndorsementInspector.Builder().build();
|
EndorsementInspector subInspector = new EndorsementInspector.Builder().build();
|
||||||
for(JsonNode endorsementNode : endorsements) {
|
for(JsonNode endorsementNode : endorsements) {
|
||||||
|
@ -28,7 +28,7 @@ public class ExpirationVerifierProbe extends Probe<Credential> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
JsonNode node = crd.asJson().get("expirationDate");
|
JsonNode node = crd.getJson().get("expirationDate");
|
||||||
if(node != null) {
|
if(node != null) {
|
||||||
ZonedDateTime expirationDate = null;
|
ZonedDateTime expirationDate = null;
|
||||||
try {
|
try {
|
||||||
|
@ -37,7 +37,7 @@ public class InlineJsonSchemaProbe extends Probe<Credential> {
|
|||||||
// ArrayNode nodes = jsonPath.eval("$..*[?(@.credentialSchema)]", crd.getJson());
|
// ArrayNode nodes = jsonPath.eval("$..*[?(@.credentialSchema)]", crd.getJson());
|
||||||
// note - we dont get deep nested ones in e.g. EndorsementCredential
|
// note - we dont get deep nested ones in e.g. EndorsementCredential
|
||||||
|
|
||||||
JsonNode credentialSchemaNode = crd.asJson().get("credentialSchema");
|
JsonNode credentialSchemaNode = crd.getJson().get("credentialSchema");
|
||||||
if(credentialSchemaNode == null) return success(ctx);
|
if(credentialSchemaNode == null) return success(ctx);
|
||||||
|
|
||||||
ArrayNode schemas = (ArrayNode) credentialSchemaNode; //TODO guard this cast
|
ArrayNode schemas = (ArrayNode) credentialSchemaNode; //TODO guard this cast
|
||||||
@ -51,7 +51,7 @@ public class InlineJsonSchemaProbe extends Probe<Credential> {
|
|||||||
if(ioErrors.contains(id)) continue;
|
if(ioErrors.contains(id)) continue;
|
||||||
if(skipCanonical && equals(crd.getSchemaKey(), id)) continue;
|
if(skipCanonical && equals(crd.getSchemaKey(), id)) continue;
|
||||||
try {
|
try {
|
||||||
accumulator.add(new JsonSchemaProbe(id).run(crd.asJson(), ctx));
|
accumulator.add(new JsonSchemaProbe(id).run(crd.getJson(), ctx));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(!ioErrors.contains(id)) {
|
if(!ioErrors.contains(id)) {
|
||||||
ioErrors.add(id);
|
ioErrors.add(id);
|
||||||
|
@ -28,7 +28,7 @@ public class IssuanceVerifierProbe extends Probe<Credential> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
JsonNode node = crd.asJson().get("issuanceDate");
|
JsonNode node = crd.getJson().get("issuanceDate");
|
||||||
if(node != null) {
|
if(node != null) {
|
||||||
ZonedDateTime issuanceDate = null;
|
ZonedDateTime issuanceDate = null;
|
||||||
try {
|
try {
|
||||||
|
@ -61,7 +61,7 @@ public class ProofVerifierProbe extends Probe<Credential> {
|
|||||||
|
|
||||||
//clone the incoming credential object so we can modify it freely
|
//clone the incoming credential object so we can modify it freely
|
||||||
ObjectMapper mapper = (ObjectMapper)ctx.get(JACKSON_OBJECTMAPPER);
|
ObjectMapper mapper = (ObjectMapper)ctx.get(JACKSON_OBJECTMAPPER);
|
||||||
JsonNode copy = mapper.readTree(crd.asJson().toString());
|
JsonNode copy = mapper.readTree(crd.getJson().toString());
|
||||||
|
|
||||||
//remove proof
|
//remove proof
|
||||||
((ObjectNode)copy).remove("proof");
|
((ObjectNode)copy).remove("proof");
|
||||||
@ -69,7 +69,7 @@ public class ProofVerifierProbe extends Probe<Credential> {
|
|||||||
//create JSON-P Json-LD instance
|
//create JSON-P Json-LD instance
|
||||||
JsonDocument jsonLdDoc = JsonDocument.of(new StringReader(copy.toString()));
|
JsonDocument jsonLdDoc = JsonDocument.of(new StringReader(copy.toString()));
|
||||||
|
|
||||||
//create rdf and normalize
|
//create rdf and normalize //TODO add DocumentLoader to cache contexts
|
||||||
RdfDataset dataSet = JsonLd.toRdf(jsonLdDoc).ordered(true).get();
|
RdfDataset dataSet = JsonLd.toRdf(jsonLdDoc).ordered(true).get();
|
||||||
RdfDataset normalized = RdfNormalize.normalize(dataSet);
|
RdfDataset normalized = RdfNormalize.normalize(dataSet);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class RevocationListProbe extends Probe<Credential> {
|
|||||||
* report a warning, not an error.
|
* report a warning, not an error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
JsonNode credentialStatus = crd.asJson().get("credentialStatus");
|
JsonNode credentialStatus = crd.getJson().get("credentialStatus");
|
||||||
if(credentialStatus != null) {
|
if(credentialStatus != null) {
|
||||||
JsonNode type = credentialStatus.get("type");
|
JsonNode type = credentialStatus.get("type");
|
||||||
if(type != null && type.asText().strip().equals("1EdTechRevocationList")) {
|
if(type != null && type.asText().strip().equals("1EdTechRevocationList")) {
|
||||||
@ -52,7 +52,7 @@ public class RevocationListProbe extends Probe<Credential> {
|
|||||||
* credential's id is in the list of revokedCredentials and the value of
|
* credential's id is in the list of revokedCredentials and the value of
|
||||||
* revoked is true or ommitted, the issuer has revoked the credential. */
|
* revoked is true or ommitted, the issuer has revoked the credential. */
|
||||||
|
|
||||||
JsonNode crdID = crd.asJson().get("id");
|
JsonNode crdID = crd.getJson().get("id"); //TODO these != checks sb removed (trigger warning)
|
||||||
if(crdID != null) {
|
if(crdID != null) {
|
||||||
List<JsonNode> list = JsonNodeUtil.asNodeList(revocList.get("revokedCredentials"));
|
List<JsonNode> list = JsonNodeUtil.asNodeList(revocList.get("revokedCredentials"));
|
||||||
if(list != null) {
|
if(list != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user