Generic property name for credential into jws

This commit is contained in:
Xavi Aracil 2022-12-02 11:28:24 +01:00
parent d286347294
commit 550dde03f6
4 changed files with 13 additions and 4 deletions

View File

@ -96,6 +96,7 @@ public class OB30Inspector extends VCInspector implements SubInspector {
.put(Key.GENERATED_OBJECT_BUILDER, new VerifiableCredential.Builder()) .put(Key.GENERATED_OBJECT_BUILDER, new VerifiableCredential.Builder())
.put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30) .put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30)
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30)
.put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME)
.build(); .build();
List<ReportItems> accumulator = new ArrayList<>(); List<ReportItems> accumulator = new ArrayList<>();

View File

@ -140,4 +140,5 @@ public class VerifiableCredential extends Credential {
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"; private static final String EXPIRES_AT_PROPERTY_NAME = "expirationDate";
public static final String JWT_NODE_NAME = "vc";
} }

View File

@ -1,14 +1,16 @@
package org.oneedtech.inspect.vc.payload; package org.oneedtech.inspect.vc.payload;
import static com.apicatalog.jsonld.StringUtils.isBlank;
import java.util.Base64; import java.util.Base64;
import java.util.List;
import java.util.Base64.Decoder; import java.util.Base64.Decoder;
import java.util.List;
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.util.resource.Resource; import org.oneedtech.inspect.util.resource.Resource;
import org.oneedtech.inspect.util.resource.ResourceType; import org.oneedtech.inspect.util.resource.ResourceType;
import org.oneedtech.inspect.vc.Credential; import org.oneedtech.inspect.vc.Credential;
import org.oneedtech.inspect.vc.VerifiableCredential;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -48,9 +50,13 @@ public abstract class PayloadParser {
*/ */
String jwtPayload = new String(decoder.decode(parts.get(1))); String jwtPayload = new String(decoder.decode(parts.get(1)));
//Deserialize and fetch the 'vc' node from the object //Deserialize and fetch the credential node from the object
JsonNode outerPayload = fromString(jwtPayload, context); JsonNode outerPayload = fromString(jwtPayload, context);
JsonNode vcNode = outerPayload.get("vc"); String nodeName = (String) context.get(Key.JWT_CREDENTIAL_NODE_NAME);
if (isBlank(nodeName)) {
return outerPayload;
}
JsonNode vcNode = outerPayload.get(nodeName);
return vcNode; return vcNode;
} }

View File

@ -119,6 +119,7 @@ public class PayloadParserTests {
.put(Key.GENERATED_OBJECT_BUILDER, new VerifiableCredential.Builder()) .put(Key.GENERATED_OBJECT_BUILDER, new VerifiableCredential.Builder())
.put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30) .put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30)
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30)
.put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME)
.build(); .build();
} }
} }