Skip to content

Commit

Permalink
fix: Throw exception and log in validation step
Browse files Browse the repository at this point in the history
  • Loading branch information
koptan committed Jan 31, 2024
1 parent ce0109f commit fd5fbb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
package org.eclipse.tractusx.ssi.lib.proof;

import java.util.logging.Logger;
// import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdValidator;
// import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdValidatorImpl;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,8 @@

/** The type Json ld validator. */
public class JsonLdValidatorImpl implements JsonLdValidator {
private static final String UNDEFINED_TERM_URI = "urn:UNDEFINEDTERM";
static final Logger LOG = Logger.getLogger(JsonLdValidatorImpl.class.getName());

public void validate(Verifiable verifiable) throws InvalidJsonLdException {
if (verifiable instanceof VerifiableCredential) {
validateJsonLd(verifiable);
} else if (verifiable instanceof VerifiablePresentation) {
VerifiablePresentation verifiablePresentation = (VerifiablePresentation) verifiable;
for (VerifiableCredential verifiableCredential :
verifiablePresentation.getVerifiableCredentials()) {
validate(verifiableCredential);
}
} else {
LOG.warning("Unsupported Verifiable type: " + verifiable.getClass().getName());
throw new InvalidJsonLdException(
String.format("Unsupported Verifiable type: %s", verifiable.getClass().getName()));
}
}
private static final String UNDEFINED_TERM_URI = "urn:UNDEFINEDTERM";

private static void findUndefinedTerms(JsonArray jsonArray) throws InvalidJsonLdException {
for (JsonValue entry : jsonArray) {
Expand Down Expand Up @@ -114,4 +98,21 @@ private void validateJsonLd(JsonLdObject jsonLdObject) throws InvalidJsonLdExcep
ex);
}
}

public void validate(Verifiable verifiable) throws InvalidJsonLdException {
if (verifiable instanceof VerifiableCredential) {
validateJsonLd(verifiable);
} else if (verifiable instanceof VerifiablePresentation) {
VerifiablePresentation verifiablePresentation = (VerifiablePresentation) verifiable;
for (VerifiableCredential verifiableCredential :
verifiablePresentation.getVerifiableCredentials()) {
validate(verifiableCredential);
}
} else {
LOG.warning("Unsupported Verifiable type: " + verifiable.getClass().getName());
throw new InvalidJsonLdException(
String.format(
"Verifiable type %s is not supported", verifiable.getClass().getSimpleName()));
}
}
}

0 comments on commit fd5fbb0

Please sign in to comment.