From d334c0f1430fa5bd59c847195ebb529c2a1c71b3 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Thu, 1 Dec 2022 12:34:36 +0100 Subject: [PATCH] Generic ExpirationProbe --- .../src/main/java/org/oneedtech/inspect/vc/Assertion.java | 7 ++++--- .../main/java/org/oneedtech/inspect/vc/Credential.java | 8 +++++++- .../org/oneedtech/inspect/vc/VerifiableCredential.java | 7 ++++--- .../org/oneedtech/inspect/vc/probe/ExpirationProbe.java | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java index 1892c4f..10c4144 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java @@ -26,8 +26,8 @@ public class Assertion extends Credential { final Assertion.Type assertionType; - protected Assertion(Resource resource, JsonNode data, String jwt, Map schemas, String issuedOnPropertyName) { - super(resource.getID(), resource, data, jwt, schemas, issuedOnPropertyName); + protected Assertion(Resource resource, JsonNode data, String jwt, Map schemas, String issuedOnPropertyName, String expiresAtPropertyName) { + super(resource.getID(), resource, data, jwt, schemas, issuedOnPropertyName, expiresAtPropertyName); JsonNode typeNode = jsonData.get("type"); this.assertionType = Assertion.Type.valueOf(typeNode); @@ -60,7 +60,7 @@ public class Assertion extends Credential { public Assertion build() { // transform key of schemas map to string because the type of the key in the base map is generic // and our specific key is an Enum - return new Assertion(getResource(), getJsonData(), getJwt(), schemas, ISSUED_ON_PROPERTY_NAME); + return new Assertion(getResource(), getJsonData(), getJwt(), schemas, ISSUED_ON_PROPERTY_NAME, EXPIRES_AT_PROPERTY_NAME); } } @@ -301,4 +301,5 @@ public class Assertion extends Credential { public static final String ID = Assertion.class.getCanonicalName(); private static final String ISSUED_ON_PROPERTY_NAME = "issuedOn"; + private static final String EXPIRES_AT_PROPERTY_NAME = "expires"; } diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java index 9c7701e..c7ba710 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java @@ -30,15 +30,17 @@ public abstract class Credential extends GeneratedObject { final JsonNode jsonData; final String jwt; final String issuedOnPropertyName; + final String expiresAtPropertyName; final Map schemas; - protected Credential(String id, Resource resource, JsonNode data, String jwt, Map schemas, String issuedOnPropertyName) { + protected Credential(String id, Resource resource, JsonNode data, String jwt, Map schemas, String issuedOnPropertyName, String expiresAtPropertyName) { super(id, GeneratedObject.Type.INTERNAL); this.resource = checkNotNull(resource); this.jsonData = checkNotNull(data); this.jwt = jwt; //may be null this.schemas = schemas; this.issuedOnPropertyName = issuedOnPropertyName; + this.expiresAtPropertyName = expiresAtPropertyName; checkTrue(RECOGNIZED_PAYLOAD_TYPES.contains(resource.getType())); } @@ -59,6 +61,10 @@ public abstract class Credential extends GeneratedObject { return issuedOnPropertyName; } + public String getExpiresAtPropertyName() { + return expiresAtPropertyName; + } + /** * Get the canonical schema for this credential if such exists. */ diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java index bd3985c..6077164 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java @@ -28,8 +28,8 @@ import com.google.common.collect.ImmutableMap; public class VerifiableCredential extends Credential { final VerifiableCredential.Type credentialType; - protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map schemas, String issuedOnPropertyName) { - super(ID, resource, data, jwt, schemas, issuedOnPropertyName); + protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map schemas, String issuedOnPropertyName, String expiresAtPropertyName) { + super(ID, resource, data, jwt, schemas, issuedOnPropertyName, expiresAtPropertyName); JsonNode typeNode = jsonData.get("type"); this.credentialType = VerifiableCredential.Type.valueOf(typeNode); @@ -133,10 +133,11 @@ public class VerifiableCredential extends Credential { public static class Builder extends Credential.Builder { @Override public VerifiableCredential build() { - return new VerifiableCredential(getResource(), getJsonData(), getJwt(), schemas, ISSUED_ON_PROPERTY_NAME); + return new VerifiableCredential(getResource(), getJsonData(), getJwt(), schemas, ISSUED_ON_PROPERTY_NAME, EXPIRES_AT_PROPERTY_NAME); } } public static final String ID = VerifiableCredential.class.getCanonicalName(); private static final String ISSUED_ON_PROPERTY_NAME = "issuanceDate"; + private static final String EXPIRES_AT_PROPERTY_NAME = "expirationDate"; } diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationProbe.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationProbe.java index b900ad4..01e6fb0 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationProbe.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationProbe.java @@ -25,7 +25,7 @@ public class ExpirationProbe extends Probe { * If the AchievementCredential or EndorsementCredential has an “expirationDate” property * and the expiration date is prior to the current date, the credential has expired. */ - JsonNode node = crd.getJson().get("expirationDate"); + JsonNode node = crd.getJson().get(crd.getExpiresAtPropertyName()); if(node != null) { try { ZonedDateTime expirationDate = ZonedDateTime.parse(node.textValue());