AbstractBaseCredential renamed to Credential

This commit is contained in:
Xavi Aracil 2022-11-23 09:08:42 +01:00
parent 3ab9c52300
commit 7beb69f87b
12 changed files with 30 additions and 30 deletions

View File

@ -18,7 +18,7 @@ import com.google.common.collect.ImmutableMap;
* and the extracted JSON data plus any other stuff Probes need. * and the extracted JSON data plus any other stuff Probes need.
* @author xaracil * @author xaracil
*/ */
public class Assertion extends AbstractBaseCredential { public class Assertion extends Credential {
final Assertion.Type assertionType; final Assertion.Type assertionType;
@ -46,7 +46,7 @@ public class Assertion extends AbstractBaseCredential {
.put(Type.Assertion, Catalog.OB_21_ASSERTION_JSON) .put(Type.Assertion, Catalog.OB_21_ASSERTION_JSON)
.build(); .build();
public static class Builder extends AbstractBaseCredential.Builder<Assertion> { public static class Builder extends Credential.Builder<Assertion> {
@Override @Override
public Assertion build() { public Assertion build() {

View File

@ -22,13 +22,13 @@ import com.google.common.base.MoreObjects;
* This contains e.g. the origin resource and the extracted JSON data. * This contains e.g. the origin resource and the extracted JSON data.
* @author xaracil * @author xaracil
*/ */
public abstract class AbstractBaseCredential extends GeneratedObject { public abstract class Credential extends GeneratedObject {
final Resource resource; final Resource resource;
final JsonNode jsonData; final JsonNode jsonData;
final String jwt; final String jwt;
final Map<String, SchemaKey> schemas; final Map<String, SchemaKey> schemas;
protected AbstractBaseCredential(String id, Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) { protected Credential(String id, Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) {
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);
@ -72,7 +72,7 @@ public abstract class AbstractBaseCredential extends GeneratedObject {
public static final List<ResourceType> RECOGNIZED_PAYLOAD_TYPES = List.of(SVG, PNG, JSON, JWT); public static final List<ResourceType> RECOGNIZED_PAYLOAD_TYPES = List.of(SVG, PNG, JSON, JWT);
public static final String CREDENTIAL_KEY = "CREDENTIAL_KEY"; public static final String CREDENTIAL_KEY = "CREDENTIAL_KEY";
public abstract static class Builder<B extends AbstractBaseCredential> { public abstract static class Builder<B extends Credential> {
private Resource resource; private Resource resource;
private JsonNode jsonData; private JsonNode jsonData;
private String jwt; private String jwt;

View File

@ -5,7 +5,7 @@ import static org.oneedtech.inspect.core.probe.RunContext.Key.*;
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;
import static org.oneedtech.inspect.vc.AbstractBaseCredential.CREDENTIAL_KEY; import static org.oneedtech.inspect.vc.Credential.CREDENTIAL_KEY;
import static org.oneedtech.inspect.vc.VerifiableCredential.ProofType.EXTERNAL; import static org.oneedtech.inspect.vc.VerifiableCredential.ProofType.EXTERNAL;
import java.net.URI; import java.net.URI;

View File

@ -5,7 +5,7 @@ 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.code.Defensives.*; import static org.oneedtech.inspect.util.code.Defensives.*;
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.AbstractBaseCredential.CREDENTIAL_KEY; import static org.oneedtech.inspect.vc.Credential.CREDENTIAL_KEY;
import static org.oneedtech.inspect.vc.VerifiableCredential.ProofType.EXTERNAL; import static org.oneedtech.inspect.vc.VerifiableCredential.ProofType.EXTERNAL;
import static org.oneedtech.inspect.vc.payload.PayloadParser.fromJwt; import static org.oneedtech.inspect.vc.payload.PayloadParser.fromJwt;
import static org.oneedtech.inspect.vc.util.JsonNodeUtil.asNodeList; import static org.oneedtech.inspect.vc.util.JsonNodeUtil.asNodeList;

View File

@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableMap;
* and the extracted JSON data plus any other stuff Probes need. * and the extracted JSON data plus any other stuff Probes need.
* @author mgylling * @author mgylling
*/ */
public class VerifiableCredential extends AbstractBaseCredential { public class VerifiableCredential extends Credential {
final VerifiableCredential.Type credentialType; final VerifiableCredential.Type credentialType;
protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) { protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) {
@ -91,7 +91,7 @@ public class VerifiableCredential extends AbstractBaseCredential {
.toString(); .toString();
} }
public static class Builder extends AbstractBaseCredential.Builder<VerifiableCredential> { public static class Builder extends Credential.Builder<VerifiableCredential> {
@Override @Override
public VerifiableCredential build() { public VerifiableCredential 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

View File

@ -7,7 +7,7 @@ import org.oneedtech.inspect.core.probe.RunContext;
import org.oneedtech.inspect.core.probe.RunContext.Key; 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.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
/** /**
@ -22,7 +22,7 @@ public final class JsonParser extends PayloadParser {
} }
@Override @Override
public AbstractBaseCredential parse(Resource resource, RunContext ctx) throws Exception { public Credential parse(Resource resource, RunContext ctx) throws Exception {
checkTrue(resource.getType() == ResourceType.JSON); checkTrue(resource.getType() == ResourceType.JSON);
String json = resource.asByteSource().asCharSource(UTF_8).read(); String json = resource.asByteSource().asCharSource(UTF_8).read();
JsonNode node = fromString(json, ctx); JsonNode node = fromString(json, ctx);

View File

@ -6,7 +6,7 @@ import static org.oneedtech.inspect.util.code.Defensives.checkTrue;
import org.oneedtech.inspect.core.probe.RunContext; import org.oneedtech.inspect.core.probe.RunContext;
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.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -22,7 +22,7 @@ public final class JwtParser extends PayloadParser {
} }
@Override @Override
public AbstractBaseCredential parse(Resource resource, RunContext ctx) throws Exception { public Credential parse(Resource resource, RunContext ctx) throws Exception {
checkTrue(resource.getType() == ResourceType.JWT); checkTrue(resource.getType() == ResourceType.JWT);
String jwt = resource.asByteSource().asCharSource(UTF_8).read(); String jwt = resource.asByteSource().asCharSource(UTF_8).read();
JsonNode node = fromJwt(jwt, ctx); JsonNode node = fromJwt(jwt, ctx);

View File

@ -7,7 +7,7 @@ import java.util.Base64.Decoder;
import org.oneedtech.inspect.core.probe.RunContext; import org.oneedtech.inspect.core.probe.RunContext;
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.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import org.oneedtech.inspect.vc.VerifiableCredential; import org.oneedtech.inspect.vc.VerifiableCredential;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -22,11 +22,11 @@ public abstract class PayloadParser {
public abstract boolean supports(ResourceType type); public abstract boolean supports(ResourceType type);
public abstract AbstractBaseCredential parse(Resource source, RunContext ctx) throws Exception; public abstract Credential parse(Resource source, RunContext ctx) throws Exception;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static AbstractBaseCredential.Builder getBuilder(RunContext context) { public static Credential.Builder getBuilder(RunContext context) {
return ((AbstractBaseCredential.Builder) context.get(RunContext.Key.GENERATED_OBJECT_BUILDER)); return ((Credential.Builder) context.get(RunContext.Key.GENERATED_OBJECT_BUILDER));
} }
protected static JsonNode fromString(String json, RunContext context) throws Exception { protected static JsonNode fromString(String json, RunContext context) throws Exception {

View File

@ -11,7 +11,7 @@ import javax.imageio.metadata.IIOMetadata;
import org.oneedtech.inspect.core.probe.RunContext; import org.oneedtech.inspect.core.probe.RunContext;
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.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -29,7 +29,7 @@ public final class PngParser extends PayloadParser {
} }
@Override @Override
public AbstractBaseCredential parse(Resource resource, RunContext ctx) throws Exception { public Credential parse(Resource resource, RunContext ctx) throws Exception {
checkTrue(resource.getType() == ResourceType.PNG); checkTrue(resource.getType() == ResourceType.PNG);

View File

@ -14,7 +14,7 @@ import org.oneedtech.inspect.core.probe.RunContext;
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.util.xml.XMLInputFactoryCache; import org.oneedtech.inspect.util.xml.XMLInputFactoryCache;
import org.oneedtech.inspect.vc.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -30,7 +30,7 @@ public final class SvgParser extends PayloadParser {
} }
@Override @Override
public AbstractBaseCredential parse(Resource resource, RunContext ctx) throws Exception { public Credential parse(Resource resource, RunContext ctx) throws Exception {
final QNames qNames = (QNames) ctx.get(RunContext.Key.SVG_CREDENTIAL_QNAME); final QNames qNames = (QNames) ctx.get(RunContext.Key.SVG_CREDENTIAL_QNAME);
checkTrue(resource.getType() == ResourceType.SVG); checkTrue(resource.getType() == ResourceType.SVG);

View File

@ -8,7 +8,7 @@ import org.oneedtech.inspect.core.report.ReportItems;
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.util.resource.detect.TypeDetector; import org.oneedtech.inspect.util.resource.detect.TypeDetector;
import org.oneedtech.inspect.vc.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import org.oneedtech.inspect.vc.VerifiableCredential; import org.oneedtech.inspect.vc.VerifiableCredential;
import org.oneedtech.inspect.vc.payload.PayloadParserFactory; import org.oneedtech.inspect.vc.payload.PayloadParserFactory;
@ -43,7 +43,7 @@ public class CredentialParseProbe extends Probe<Resource> {
return fatal("Payload type not supported: " + type.get().getName(), context); return fatal("Payload type not supported: " + type.get().getName(), context);
} }
AbstractBaseCredential crd = PayloadParserFactory.of(resource).parse(resource, context); Credential crd = PayloadParserFactory.of(resource).parse(resource, context);
context.addGeneratedObject(crd); context.addGeneratedObject(crd);
return success(this, context); return success(this, context);

View File

@ -11,7 +11,7 @@ import org.oneedtech.inspect.core.probe.json.JsonPathEvaluator;
import org.oneedtech.inspect.util.json.ObjectMapperCache; import org.oneedtech.inspect.util.json.ObjectMapperCache;
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.AbstractBaseCredential; import org.oneedtech.inspect.vc.Credential;
import org.oneedtech.inspect.vc.OB30Inspector; import org.oneedtech.inspect.vc.OB30Inspector;
import org.oneedtech.inspect.vc.Samples; import org.oneedtech.inspect.vc.Samples;
import org.oneedtech.inspect.vc.payload.PayloadParser; import org.oneedtech.inspect.vc.payload.PayloadParser;
@ -27,7 +27,7 @@ public class PayloadParserTests {
Resource res = Samples.OB30.SVG.SIMPLE_JSON_SVG.asFileResource(ResourceType.SVG); Resource res = Samples.OB30.SVG.SIMPLE_JSON_SVG.asFileResource(ResourceType.SVG);
PayloadParser ext = PayloadParserFactory.of(res); PayloadParser ext = PayloadParserFactory.of(res);
assertNotNull(ext); assertNotNull(ext);
AbstractBaseCredential crd = ext.parse(res, mockOB30Context(res)); Credential crd = ext.parse(res, mockOB30Context(res));
//System.out.println(crd.getJson().toPrettyString()); //System.out.println(crd.getJson().toPrettyString());
assertNotNull(crd); assertNotNull(crd);
assertNotNull(crd.getJson()); assertNotNull(crd.getJson());
@ -41,7 +41,7 @@ public class PayloadParserTests {
Resource res = Samples.OB30.SVG.SIMPLE_JWT_SVG.asFileResource(ResourceType.SVG); Resource res = Samples.OB30.SVG.SIMPLE_JWT_SVG.asFileResource(ResourceType.SVG);
PayloadParser ext = PayloadParserFactory.of(res); PayloadParser ext = PayloadParserFactory.of(res);
assertNotNull(ext); assertNotNull(ext);
AbstractBaseCredential crd = ext.parse(res, mockOB30Context(res)); Credential crd = ext.parse(res, mockOB30Context(res));
//System.out.println(crd.getJson().toPrettyString()); //System.out.println(crd.getJson().toPrettyString());
assertNotNull(crd); assertNotNull(crd);
assertNotNull(crd.getJson()); assertNotNull(crd.getJson());
@ -55,7 +55,7 @@ public class PayloadParserTests {
Resource res = Samples.OB30.PNG.SIMPLE_JSON_PNG.asFileResource(ResourceType.PNG); Resource res = Samples.OB30.PNG.SIMPLE_JSON_PNG.asFileResource(ResourceType.PNG);
PayloadParser ext = PayloadParserFactory.of(res); PayloadParser ext = PayloadParserFactory.of(res);
assertNotNull(ext); assertNotNull(ext);
AbstractBaseCredential crd = ext.parse(res, mockOB30Context(res)); Credential crd = ext.parse(res, mockOB30Context(res));
//System.out.println(crd.getJson().toPrettyString()); //System.out.println(crd.getJson().toPrettyString());
assertNotNull(crd); assertNotNull(crd);
assertNotNull(crd.getJson()); assertNotNull(crd.getJson());
@ -69,7 +69,7 @@ public class PayloadParserTests {
Resource res = Samples.OB30.PNG.SIMPLE_JWT_PNG.asFileResource(ResourceType.PNG); Resource res = Samples.OB30.PNG.SIMPLE_JWT_PNG.asFileResource(ResourceType.PNG);
PayloadParser ext = PayloadParserFactory.of(res); PayloadParser ext = PayloadParserFactory.of(res);
assertNotNull(ext); assertNotNull(ext);
AbstractBaseCredential crd = ext.parse(res, mockOB30Context(res)); Credential crd = ext.parse(res, mockOB30Context(res));
//System.out.println(crd.getJson().toPrettyString()); //System.out.println(crd.getJson().toPrettyString());
assertNotNull(crd); assertNotNull(crd);
assertNotNull(crd.getJson()); assertNotNull(crd.getJson());
@ -83,7 +83,7 @@ public class PayloadParserTests {
Resource res = Samples.OB30.JWT.SIMPLE_JWT.asFileResource(ResourceType.JWT); Resource res = Samples.OB30.JWT.SIMPLE_JWT.asFileResource(ResourceType.JWT);
PayloadParser ext = PayloadParserFactory.of(res); PayloadParser ext = PayloadParserFactory.of(res);
assertNotNull(ext); assertNotNull(ext);
AbstractBaseCredential crd = ext.parse(res, mockOB30Context(res)); Credential crd = ext.parse(res, mockOB30Context(res));
//System.out.println(crd.getJson().toPrettyString()); //System.out.println(crd.getJson().toPrettyString());
assertNotNull(crd); assertNotNull(crd);
assertNotNull(crd.getJson()); assertNotNull(crd.getJson());
@ -97,7 +97,7 @@ public class PayloadParserTests {
Resource res = Samples.OB30.JSON.SIMPLE_JSON.asFileResource(ResourceType.JSON); Resource res = Samples.OB30.JSON.SIMPLE_JSON.asFileResource(ResourceType.JSON);
PayloadParser ext = PayloadParserFactory.of(res); PayloadParser ext = PayloadParserFactory.of(res);
assertNotNull(ext); assertNotNull(ext);
AbstractBaseCredential crd = ext.parse(res, mockOB30Context(res)); Credential crd = ext.parse(res, mockOB30Context(res));
//System.out.println(crd.getJson().toPrettyString()); //System.out.println(crd.getJson().toPrettyString());
assertNotNull(crd); assertNotNull(crd);
assertNotNull(crd.getJson()); assertNotNull(crd.getJson());