diff --git a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/RevocationSettings.java b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/RevocationSettings.java index c36bb2ec..43b2a3a1 100644 --- a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/RevocationSettings.java +++ b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/RevocationSettings.java @@ -26,5 +26,5 @@ import java.net.URI; @ConfigurationProperties(prefix = "miw.revocation") -public record RevocationSettings(URI url) { +public record RevocationSettings(URI url, URI bitStringStatusListContext) { } diff --git a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java index dba5f6a9..6f1592dc 100644 --- a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java +++ b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java @@ -42,6 +42,7 @@ import org.eclipse.tractusx.managedidentitywallets.commons.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.commons.utils.Validate; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; +import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings; import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential; import org.eclipse.tractusx.managedidentitywallets.dao.entity.IssuersCredential; import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet; @@ -77,6 +78,7 @@ import org.springframework.util.StringUtils; import java.io.IOException; +import java.net.URI; import java.net.http.HttpClient; import java.text.ParseException; import java.util.ArrayList; @@ -115,6 +117,8 @@ public class IssuersCredentialService extends BaseService getRepository() { @@ -239,6 +243,14 @@ public CredentialsResponse issueCredentialUsingBaseWallet(String holderDid, Map< //get credential status in case of revocation VerifiableCredentialStatusList2021Entry statusListEntry = revocationService.getStatusListEntry(issuerWallet.getBpn(), token); builder.verifiableCredentialStatus(statusListEntry); + + //add revocation context if missing + List uris = miwSettings.vcContexts(); + if (!uris.contains(revocationSettings.bitStringStatusListContext())) { + uris.add(revocationSettings.bitStringStatusListContext()); + builder.contexts(uris); + } + } CredentialCreationConfig holdersCredentialCreationConfig = builder.build(); diff --git a/miw/src/main/resources/application.yaml b/miw/src/main/resources/application.yaml index d705efe1..c40961bb 100644 --- a/miw/src/main/resources/application.yaml +++ b/miw/src/main/resources/application.yaml @@ -110,6 +110,7 @@ miw: refresh-token-url: ${miw.security.token-url} revocation: url: ${REVOCATION_SERVICE_URL:http://localhost:8081} + bitStringStatusListContext: ${BITSTRING_STATUS_LIST_CONTEXT_URL:https://w3c.github.io/vc-bitstring-status-list/contexts/v1.jsonld} sts: diff --git a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java index 4c52d70c..4127dc59 100644 --- a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java +++ b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialServiceTest.java @@ -153,7 +153,7 @@ public static void beforeAll() throws SQLException { issuersCredentialRepository, miwSettings, new SpecificationUtil(), - holdersCredentialRepository, commonService, objectMapper, revocationService); + holdersCredentialRepository, commonService, objectMapper, revocationService, revocationSettings); } @BeforeEach diff --git a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/TestUtils.java b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/TestUtils.java index 5f1d85b7..3eb7ed69 100644 --- a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/TestUtils.java +++ b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/utils/TestUtils.java @@ -38,6 +38,7 @@ import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool; import org.eclipse.tractusx.managedidentitywallets.commons.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; +import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet; import org.eclipse.tractusx.managedidentitywallets.dao.repository.WalletRepository; @@ -129,14 +130,14 @@ public static Wallet createWallet(String bpn, String did, WalletRepository walle return walletRepository.save(wallet); } - public static void checkVC(VerifiableCredential verifiableCredential, MIWSettings miwSettings) { - //text context URL - Assertions.assertEquals(verifiableCredential.getContext().size(), miwSettings.vcContexts().size() + 1); - + public static void checkVC(VerifiableCredential verifiableCredential, MIWSettings miwSettings, RevocationSettings revocationSettings) { for (URI link : miwSettings.vcContexts()) { Assertions.assertTrue(verifiableCredential.getContext().contains(link)); } + if (verifiableCredential.getVerifiableCredentialStatus() != null) { + Assertions.assertTrue(verifiableCredential.getContext().contains(revocationSettings.bitStringStatusListContext())); + } //check expiry date Assertions.assertEquals(0, verifiableCredential.getExpirationDate().compareTo(miwSettings.vcExpiryDate().toInstant())); } @@ -261,7 +262,6 @@ public static Map getCredentialAsMap(String holderBpn, String ho //VC Subject VerifiableCredentialSubject verifiableCredentialSubject = new VerifiableCredentialSubject(subjectData); - //Using Builder VerifiableCredential credentialWithoutProof = verifiableCredentialBuilder diff --git a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java index 624eb5d6..16efe6b5 100644 --- a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java +++ b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/HoldersCredentialTest.java @@ -29,6 +29,7 @@ import org.eclipse.tractusx.managedidentitywallets.commons.constant.CredentialStatus; import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; +import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings; import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; import org.eclipse.tractusx.managedidentitywallets.controller.IssuersCredentialController; @@ -101,6 +102,9 @@ class HoldersCredentialTest { @Autowired private TestRestTemplate restTemplate; + @Autowired + private RevocationSettings revocationSettings; + @MockInBean(RevocationService.class) private RevocationClient revocationClient; @@ -149,7 +153,7 @@ void issueCredentialTest200() throws JsonProcessingException { List credentials = holdersCredentialRepository.getByHolderDidAndType(did, type); Assertions.assertFalse(credentials.isEmpty()); - TestUtils.checkVC(credentials.get(0).getData(), miwSettings); + TestUtils.checkVC(credentials.get(0).getData(), miwSettings, revocationSettings); Assertions.assertTrue(credentials.get(0).isSelfIssued()); Assertions.assertFalse(credentials.get(0).isStored()); } diff --git a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java index 92fc8b40..52f73c4d 100644 --- a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java +++ b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/vc/IssuersCredentialTest.java @@ -31,6 +31,7 @@ import org.eclipse.tractusx.managedidentitywallets.commons.constant.StringPool; import org.eclipse.tractusx.managedidentitywallets.commons.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; +import org.eclipse.tractusx.managedidentitywallets.config.RevocationSettings; import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential; @@ -89,6 +90,9 @@ class IssuersCredentialTest { @Autowired private IssuersCredentialRepository issuersCredentialRepository; + @Autowired + private RevocationSettings revocationSettings; + @MockInBean(RevocationService.class) private RevocationClient revocationClient; @@ -259,7 +263,7 @@ void issueCredentials200() throws com.fasterxml.jackson.core.JsonProcessingExcep List credentials = holdersCredentialRepository.getByHolderDidAndType(did, type); Assertions.assertFalse(credentials.isEmpty()); - TestUtils.checkVC(credentials.get(0).getData(), miwSettings); + TestUtils.checkVC(credentials.get(0).getData(), miwSettings, revocationSettings); Assertions.assertFalse(credentials.get(0).isStored()); //stored must be false Assertions.assertFalse(credentials.get(0).isSelfIssued()); //stored must be false