Skip to content

Commit

Permalink
fix: fixed bug with the credetials configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Brunkow Moser committed Jun 21, 2024
1 parent 2136070 commit 5816453
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.eclipse.tractusx.digitalproductpass.core.exceptions.ControllerException;
import org.eclipse.tractusx.digitalproductpass.verification.config.VerificationConfig;
import org.eclipse.tractusx.digitalproductpass.verification.manager.VerificationManager;
import org.eclipse.tractusx.digitalproductpass.verification.models.CertifiedDataCredential;
import org.eclipse.tractusx.digitalproductpass.verification.models.VerificationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
Expand Down Expand Up @@ -246,7 +245,7 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr

// Verification Add-on Functionality
if(this.verificationConfig.getEnabled()) {
String path = this.verificationManager.setVerificationStatus(processId, subModel, bpn);
String path = verificationManager.setVerificationStatus(processId, subModel, bpn);
if(path == null){
processManager.setStatus(processId, "verification-check-failed", new History(
subModel.getIdentification(),
Expand Down Expand Up @@ -353,16 +352,8 @@ public Response endpoint(@RequestBody Object body, @PathVariable String processI

VerificationInfo verificationInfo = status.getVerification();
if(verificationInfo.vc){
CertifiedDataCredential certifiedDataCredential = jsonUtil.bind(passport, new TypeReference<>(){});

if(certifiedDataCredential == null){
verificationInfo.setVerified(false);
verificationInfo.setError("It was not possible to parse the verifiable credential as a Certified Data Credential!");
verificationManager.setVerificationInfo(processId, verificationInfo);
return this.savePassport(processId, endpointData, passport);
}

verificationInfo = verificationManager.buildVerification(certifiedDataCredential, verificationInfo);
verificationInfo = verificationManager.buildVerification(passport, verificationInfo);
}

verificationManager.setVerificationInfo(processId, verificationInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@
@Configuration
public class CDCConfig {

List<SemanticKey> semanticIds;
List<SemanticKey> semanticIdKeys;

public CDCConfig(List<SemanticKey> semanticIds) {
this.semanticIds = semanticIds;
public CDCConfig() {
}

public CDCConfig() {
public CDCConfig(List<SemanticKey> semanticIdKeys) {
this.semanticIdKeys = semanticIdKeys;
}

public List<SemanticKey> getSemanticIds() {
return semanticIds;
public List<SemanticKey> getSemanticIdKeys() {
return semanticIdKeys;
}

public void setSemanticIds(List<SemanticKey> semanticIds) {
this.semanticIds = semanticIds;
public void setSemanticIdKeys(List<SemanticKey> semanticIdKeys) {
this.semanticIdKeys = semanticIdKeys;
}


public static class SemanticKey {
String key;
String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ public class VerificationConfig {
Boolean enabled;
Boolean autoVerify;
WalletConfig wallet;

CDCConfig certifiedDataCredential;

/**
* CONSTRUCTOR(S)
**/

public VerificationConfig(Boolean enabled, Boolean autoVerify, WalletConfig wallet) {
this.enabled = enabled;
this.autoVerify = autoVerify;
this.wallet = wallet;
}

public VerificationConfig() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.eclipse.tractusx.digitalproductpass.core.models.http.Response;
import org.eclipse.tractusx.digitalproductpass.core.services.AuthenticationService;
import org.eclipse.tractusx.digitalproductpass.verification.config.VerificationConfig;
import org.eclipse.tractusx.digitalproductpass.verification.models.CertifiedDataCredential;
import org.eclipse.tractusx.digitalproductpass.verification.services.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
Expand All @@ -49,6 +48,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import utils.HttpUtil;
import utils.JsonUtil;

import java.awt.print.Book;

Expand Down Expand Up @@ -89,7 +89,7 @@ public class VerificationController {
@ApiResponse(description = "If the user is not authorized", responseCode = "401", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Response.class)))
})
public Response verify(@io.swagger.v3.oas.annotations.parameters.RequestBody(description="Verifiable Credential with JsonWebSignature2020 proof type",content=@Content(mediaType="application/vc+ld+json", schema=@Schema(ref = "#/components/schemas/CertifiedDataCredential")), required = true) @RequestBody CertifiedDataCredential credential) {
public Response verify(@io.swagger.v3.oas.annotations.parameters.RequestBody(description="Verifiable Credential with JsonWebSignature2020 proof type",content=@Content(mediaType="application/vc+ld+json", schema=@Schema(ref = "#/components/schemas/CertifiedDataCredential")), required = true) @RequestBody JsonNode credential) {
Response response = httpUtil.getInternalError();
if (!authService.isAuthenticated(httpRequest)) {
response = httpUtil.getNotAuthorizedResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import org.eclipse.tractusx.digitalproductpass.core.models.manager.Status;
import org.eclipse.tractusx.digitalproductpass.verification.config.CDCConfig;
import org.eclipse.tractusx.digitalproductpass.verification.config.VerificationConfig;
import org.eclipse.tractusx.digitalproductpass.verification.models.CertifiedDataCredential;
import org.eclipse.tractusx.digitalproductpass.verification.models.Proof;
import org.eclipse.tractusx.digitalproductpass.verification.models.VerifiableCredential;
import org.eclipse.tractusx.digitalproductpass.verification.models.VerificationInfo;
import org.eclipse.tractusx.digitalproductpass.verification.services.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -66,7 +64,6 @@ public class VerificationManager {
private FileUtil fileUtil;
@Autowired
private ProcessManager processManager;

@Autowired
private WalletService walletService;
@Autowired
Expand Down Expand Up @@ -194,9 +191,11 @@ public String setVerificationInfo(String processId, VerificationInfo verificatio
}
}
public Boolean isVerifiableCredential(SubModel subModel){

CDCConfig cdcConfig = verificationConfig.getCertifiedDataCredential();
List<CDCConfig.SemanticKey> keys = cdcConfig.getSemanticIds();
if(cdcConfig == null){
throw new ManagerException(this.getClass().getName()+".isVerifiableCredential", "No Certified Data Credential configuration available!");
}
List<CDCConfig.SemanticKey> keys = cdcConfig.getSemanticIdKeys();

if(keys == null){
return null;
Expand Down Expand Up @@ -250,7 +249,7 @@ public String extractBPNFromIssuer(String issuer){
return bpn;
}

public VerificationInfo buildVerification(CertifiedDataCredential verifiableCredential, VerificationInfo verificationInfo){
public VerificationInfo buildVerification(JsonNode verifiableCredential, VerificationInfo verificationInfo){
JsonNode response = walletService.verifyCredential(verifiableCredential);
boolean verified = false;
String message = "An unexpected error occurred while verifying!";
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.tractusx.digitalproductpass.core.services.VaultService;
import org.eclipse.tractusx.digitalproductpass.verification.config.VerificationConfig;
import org.eclipse.tractusx.digitalproductpass.verification.config.WalletConfig;
import org.eclipse.tractusx.digitalproductpass.verification.models.CertifiedDataCredential;
import org.sonarsource.scanner.api.internal.shaded.minimaljson.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -174,11 +174,8 @@ public Boolean checkHealth(){
* @return a {@code Map<String, String>} map object with the irs first response
* @throws ServiceException if unable to start the verification process
*/
public JsonNode verifyCredential(CertifiedDataCredential verifiableCredential) {
public JsonNode verifyCredential(JsonNode verifiableCredential) {
try {
System.out.println("Verifying credential:");
System.out.println(jsonUtil.toJson(verifiableCredential, true));

this.checkEmptyVariables();
String url = this.walletUrl + this.verifyEndpoint;
HttpHeaders headers = httpUtil.getHeadersWithApiKey(this.apiKey);
Expand Down
22 changes: 22 additions & 0 deletions dpp-backend/digitalproductpass/src/main/java/utils/JsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ public Object loadJson(String jsonString, Class<?> classType){
}
}

/**
* Loads the JSON file from the given file path and maps it to an object.
* <p>
* @param jsonString
* the path representation to the target JSON file as a String.
* @param reference
* the class type to map the json structure from the file to an object.
*
* @return a {@code Object} object mapped with the json file structure.
*
* @throws UtilException
* if unable to load the JSON file.
*/
public <T> T loadJson(String jsonString, TypeReference<T> reference){
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(jsonString, reference);
} catch (Exception e) {
throw new UtilException(JsonUtil.class, "I was not possible to load JSON in object -> [" + e.getMessage() + "]");
}
}

/**
* Loads the JSON file from the given file path as a String.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ configuration:
maxRetries: 30
delay: 1000

verification:
enabled: true
autoVerify: true
wallet:
url: "https://dpp-consumer-wallet.int.demo.catena-x.net"
endpoints:
health: "/health"
verify: "/verify"

certifiedDataCredential:
semanticIdKeys:
- key: "Entity"
value: "https://www.w3.org/ns/credentials/v2"
- key: "DataElement"
value: "urn:samm:io.catenax.dpp_verification.cdc:1.0.0#CertifiedDataCredential"
- key: "Operation"
value: "https://w3c.github.io/vc-jws-2020/contexts/v1/"

process:
store: true
dir: 'process'
Expand Down

0 comments on commit 5816453

Please sign in to comment.