Generic ExpirationProbe
This commit is contained in:
parent
ce89968837
commit
d334c0f143
@ -26,8 +26,8 @@ public class Assertion extends Credential {
|
|||||||
|
|
||||||
final Assertion.Type assertionType;
|
final Assertion.Type assertionType;
|
||||||
|
|
||||||
protected Assertion(Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> schemas, String issuedOnPropertyName) {
|
protected Assertion(Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> schemas, String issuedOnPropertyName, String expiresAtPropertyName) {
|
||||||
super(resource.getID(), resource, data, jwt, schemas, issuedOnPropertyName);
|
super(resource.getID(), resource, data, jwt, schemas, issuedOnPropertyName, expiresAtPropertyName);
|
||||||
|
|
||||||
JsonNode typeNode = jsonData.get("type");
|
JsonNode typeNode = jsonData.get("type");
|
||||||
this.assertionType = Assertion.Type.valueOf(typeNode);
|
this.assertionType = Assertion.Type.valueOf(typeNode);
|
||||||
@ -60,7 +60,7 @@ public class Assertion extends Credential {
|
|||||||
public Assertion build() {
|
public Assertion build() {
|
||||||
// transform key of schemas map to string because the type of the key in the base map is generic
|
// 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
|
// 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();
|
public static final String ID = Assertion.class.getCanonicalName();
|
||||||
private static final String ISSUED_ON_PROPERTY_NAME = "issuedOn";
|
private static final String ISSUED_ON_PROPERTY_NAME = "issuedOn";
|
||||||
|
private static final String EXPIRES_AT_PROPERTY_NAME = "expires";
|
||||||
}
|
}
|
||||||
|
@ -30,15 +30,17 @@ public abstract class Credential extends GeneratedObject {
|
|||||||
final JsonNode jsonData;
|
final JsonNode jsonData;
|
||||||
final String jwt;
|
final String jwt;
|
||||||
final String issuedOnPropertyName;
|
final String issuedOnPropertyName;
|
||||||
|
final String expiresAtPropertyName;
|
||||||
final Map<CredentialEnum, SchemaKey> schemas;
|
final Map<CredentialEnum, SchemaKey> schemas;
|
||||||
|
|
||||||
protected Credential(String id, Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> schemas, String issuedOnPropertyName) {
|
protected Credential(String id, Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> schemas, String issuedOnPropertyName, String expiresAtPropertyName) {
|
||||||
super(id, GeneratedObject.Type.INTERNAL);
|
super(id, GeneratedObject.Type.INTERNAL);
|
||||||
this.resource = checkNotNull(resource);
|
this.resource = checkNotNull(resource);
|
||||||
this.jsonData = checkNotNull(data);
|
this.jsonData = checkNotNull(data);
|
||||||
this.jwt = jwt; //may be null
|
this.jwt = jwt; //may be null
|
||||||
this.schemas = schemas;
|
this.schemas = schemas;
|
||||||
this.issuedOnPropertyName = issuedOnPropertyName;
|
this.issuedOnPropertyName = issuedOnPropertyName;
|
||||||
|
this.expiresAtPropertyName = expiresAtPropertyName;
|
||||||
|
|
||||||
checkTrue(RECOGNIZED_PAYLOAD_TYPES.contains(resource.getType()));
|
checkTrue(RECOGNIZED_PAYLOAD_TYPES.contains(resource.getType()));
|
||||||
}
|
}
|
||||||
@ -59,6 +61,10 @@ public abstract class Credential extends GeneratedObject {
|
|||||||
return issuedOnPropertyName;
|
return issuedOnPropertyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExpiresAtPropertyName() {
|
||||||
|
return expiresAtPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the canonical schema for this credential if such exists.
|
* Get the canonical schema for this credential if such exists.
|
||||||
*/
|
*/
|
||||||
|
@ -28,8 +28,8 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
public class VerifiableCredential extends Credential {
|
public class VerifiableCredential extends Credential {
|
||||||
final VerifiableCredential.Type credentialType;
|
final VerifiableCredential.Type credentialType;
|
||||||
|
|
||||||
protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> schemas, String issuedOnPropertyName) {
|
protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> schemas, String issuedOnPropertyName, String expiresAtPropertyName) {
|
||||||
super(ID, resource, data, jwt, schemas, issuedOnPropertyName);
|
super(ID, resource, data, jwt, schemas, issuedOnPropertyName, expiresAtPropertyName);
|
||||||
|
|
||||||
JsonNode typeNode = jsonData.get("type");
|
JsonNode typeNode = jsonData.get("type");
|
||||||
this.credentialType = VerifiableCredential.Type.valueOf(typeNode);
|
this.credentialType = VerifiableCredential.Type.valueOf(typeNode);
|
||||||
@ -133,10 +133,11 @@ public class VerifiableCredential extends Credential {
|
|||||||
public static class Builder extends Credential.Builder<VerifiableCredential> {
|
public static class Builder extends Credential.Builder<VerifiableCredential> {
|
||||||
@Override
|
@Override
|
||||||
public VerifiableCredential build() {
|
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();
|
public static final String ID = VerifiableCredential.class.getCanonicalName();
|
||||||
private static final String ISSUED_ON_PROPERTY_NAME = "issuanceDate";
|
private static final String ISSUED_ON_PROPERTY_NAME = "issuanceDate";
|
||||||
|
private static final String EXPIRES_AT_PROPERTY_NAME = "expirationDate";
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class ExpirationProbe extends Probe<Credential> {
|
|||||||
* If the AchievementCredential or EndorsementCredential has an “expirationDate” property
|
* If the AchievementCredential or EndorsementCredential has an “expirationDate” property
|
||||||
* and the expiration date is prior to the current date, the credential has expired.
|
* 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) {
|
if(node != null) {
|
||||||
try {
|
try {
|
||||||
ZonedDateTime expirationDate = ZonedDateTime.parse(node.textValue());
|
ZonedDateTime expirationDate = ZonedDateTime.parse(node.textValue());
|
||||||
|
Loading…
Reference in New Issue
Block a user