diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java index f684cc107..fb4ed5954 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java @@ -509,8 +509,6 @@ private void updateSummeryCredentials(DidDocument issuerDidDocument, byte[] issu Map subject = Map.of(StringPool.ID, holderDid, StringPool.HOLDER_IDENTIFIER, holderBpn, - StringPool.TYPE, MIWVerifiableCredentialType.SUMMARY_LIST_CREDENTIAL, - StringPool.NAME, StringPool.CX_CREDENTIALS, StringPool.ITEMS, items, StringPool.CONTRACT_TEMPLATES, miwSettings.contractTemplatesUrl()); diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java index 9371bd733..c90de34a2 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java @@ -117,8 +117,6 @@ public Map createPresentation(Map data, boolean List verifiableCredentials = new ArrayList<>(verifiableCredentialList.size()); verifiableCredentialList.forEach(map -> { VerifiableCredential verifiableCredential = new VerifiableCredential(map); - validateCredential(verifiableCredential, holderIdentifier); - verifiableCredentials.add(verifiableCredential); }); @@ -126,20 +124,23 @@ public Map createPresentation(Map data, boolean Did issuerDid = DidParser.parse(verifiableCredentials.get(0).getIssuer()); commonService.getWalletByIdentifier(issuerDidString); - //validate BPN access - Issuer(Creator) of VP must be caller + //validate BPN access - Issuer(Creator) of VP must be caller Issuer of VP must be holder of VC Validate.isFalse(holderWallet.getBpn().equalsIgnoreCase(callerBpn)).launch(new ForbiddenException("Issuer wallet BPN is not matching with request BPN(from the token)")); if (asJwt) { Validate.isFalse(StringUtils.hasText(audience)).launch(new BadDataException("Audience needed to create VP as JWT")); + //Issuer of VP is holder of VC + Did vpIssuerDid = DidParser.parse(holderWallet.getDid()); + //JWT Factory SerializedJwtPresentationFactory presentationFactory = new SerializedJwtPresentationFactoryImpl( - new SignedJwtFactory(new OctetKeyPairFactory()), new JsonLdSerializerImpl(), issuerDid); + new SignedJwtFactory(new OctetKeyPairFactory()), new JsonLdSerializerImpl(), vpIssuerDid); //Build JWT - SignedJWT presentation = presentationFactory.createPresentation( - issuerDid, verifiableCredentials, audience, walletKeyService.getPrivateKeyByWalletIdentifier(holderWallet.getId())); + SignedJWT presentation = presentationFactory.createPresentation(vpIssuerDid + , verifiableCredentials, audience, walletKeyService.getPrivateKeyByWalletIdentifier(holderWallet.getId())); response.put(StringPool.VP, presentation.serialize()); } else { @@ -251,9 +252,4 @@ private boolean validateAudience(String audience, SignedJWT signedJWT) { return true; } } - - private void validateCredential(VerifiableCredential verifiableCredential, String holderIdentifier) { - //check holders - Validate.isFalse(verifiableCredential.getCredentialSubject().get(0).get(StringPool.ID).toString().equals(holderIdentifier)).launch(new ForbiddenException("VC " + verifiableCredential.getTypes() + " is not match with holder identifier " + holderIdentifier)); - } } diff --git a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java index 07ef656e6..998c98b75 100644 --- a/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java +++ b/src/test/java/org/eclipse/tractusx/managedidentitywallets/vp/PresentationTest.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; import org.eclipse.tractusx.managedidentitywallets.ManagedIdentityWalletsApplication; import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer; @@ -53,6 +54,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import java.text.ParseException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -177,13 +179,19 @@ void validateVPAsJwtWithValidAudienceAndDateValidation() throws JsonProcessingEx } @Test - void createPresentationAsJWT201() throws JsonProcessingException { + void createPresentationAsJWT201() throws JsonProcessingException, ParseException { String bpn = UUID.randomUUID().toString(); + String did = "did:web:localhost:" + bpn; String audience = "smartSense"; ResponseEntity vpResponse = createBpnVCAsJwt(bpn, audience); Assertions.assertEquals(vpResponse.getStatusCode().value(), HttpStatus.CREATED.value()); + String jwt = vpResponse.getBody().get("vp").toString(); + SignedJWT signedJWT = SignedJWT.parse(jwt); + JWTClaimsSet claimsSet = signedJWT.getJWTClaimsSet(); + String iss = claimsSet.getStringClaim("iss"); - + //issuer of VP is must be holder of VP + Assertions.assertEquals(iss, did); } private ResponseEntity createBpnVCAsJwt(String bpn, String audience) throws JsonProcessingException {