Skip to content

Commit

Permalink
[INJWEB-762]&[INJIWEB-910] : update error message for unavailable res…
Browse files Browse the repository at this point in the history
…ource & add credential expiry times disclaimer notes to PDF (#487)

* [INJWEB-762]&[INJIWEB-910] : update error message for unavailable resource & add credential expiry times disclaimer notes to PDF

Signed-off-by: Vijay <[email protected]>

* [INJWEB-762]&[INJIWEB-910] : add the credential expiry times disclaimer in the PDF

Signed-off-by: Vijay <[email protected]>

---------

Signed-off-by: Vijay <[email protected]>
  • Loading branch information
vijay151096 authored Oct 16, 2024
1 parent cc10c19 commit 83346ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ByteArrayInputStream downloadCredentialAsPDF(String issuerId, String cred
boolean verificationStatus = vcCredentialResponse.getCredential().getProof().getType().equals("RsaSignature2018") ? verifyCredential(vcCredentialResponse) : true;
if(verificationStatus) {
String dataShareUrl = QRCodeType.OnlineSharing.equals(issuerConfig.getQr_code_type()) ? dataShareService.storeDataInDataShare(objectMapper.writeValueAsString(vcCredentialResponse), credentialValidity) : "";
return generatePdfForVerifiableCredentials(vcCredentialResponse, issuerConfig, credentialsSupportedResponse, dataShareUrl);
return generatePdfForVerifiableCredentials(vcCredentialResponse, issuerConfig, credentialsSupportedResponse, dataShareUrl, credentialValidity);
}
throw new VCVerificationException(SIGNATURE_VERIFICATION_EXCEPTION.getErrorCode(),
SIGNATURE_VERIFICATION_EXCEPTION.getErrorMessage());
Expand Down Expand Up @@ -156,16 +156,19 @@ public VCCredentialRequest generateVCCredentialRequest(IssuerDTO issuerDTO, Cred
.build();
}

public ByteArrayInputStream generatePdfForVerifiableCredentials(VCCredentialResponse vcCredentialResponse, IssuerDTO issuerDTO, CredentialsSupportedResponse credentialsSupportedResponse, String dataShareUrl) throws Exception {
public ByteArrayInputStream generatePdfForVerifiableCredentials(VCCredentialResponse vcCredentialResponse, IssuerDTO issuerDTO, CredentialsSupportedResponse credentialsSupportedResponse, String dataShareUrl, String credentialValidity) throws Exception {
LinkedHashMap<String, Object> displayProperties = loadDisplayPropertiesFromWellknown(vcCredentialResponse, credentialsSupportedResponse);
Map<String, Object> data = getPdfResourceFromVcProperties(displayProperties, credentialsSupportedResponse, vcCredentialResponse, issuerDTO, dataShareUrl);
Map<String, Object> data = getPdfResourceFromVcProperties(displayProperties, credentialsSupportedResponse, vcCredentialResponse, issuerDTO, dataShareUrl, credentialValidity);
return renderVCInCredentialTemplate(data);
}

public Boolean verifyCredential(VCCredentialResponse vcCredentialResponse) throws VCVerificationException {
try {
log.info("Initiated the VC Verification : Started");
String credentialString = objectMapper.writeValueAsString(vcCredentialResponse.getCredential());
return credentialsVerifier.verifyCredentials(credentialString);
boolean isCredentialVerified = credentialsVerifier.verifyCredentials(credentialString);
log.info("Completed the VC Verification : Completed -> status : " + isCredentialVerified);
return isCredentialVerified;
} catch (ProofDocumentNotFoundException | ProofTypeNotSupportedException | SignatureVerificationException | UnknownException | JsonProcessingException |
PublicKeyNotFoundException exception ) {
String errorCode = UNKNOWN_EXCEPTION.getErrorCode();
Expand Down Expand Up @@ -217,7 +220,7 @@ private static LinkedHashMap<String, Object> loadDisplayPropertiesFromWellknown(
}


private Map<String, Object> getPdfResourceFromVcProperties(LinkedHashMap<String, Object> displayProperties, CredentialsSupportedResponse credentialsSupportedResponse, VCCredentialResponse vcCredentialResponse, IssuerDTO issuerDTO, String dataShareUrl) throws IOException, WriterException {
private Map<String, Object> getPdfResourceFromVcProperties(LinkedHashMap<String, Object> displayProperties, CredentialsSupportedResponse credentialsSupportedResponse, VCCredentialResponse vcCredentialResponse, IssuerDTO issuerDTO, String dataShareUrl, String credentialValidity) throws IOException, WriterException {
Map<String, Object> data = new HashMap<>();
LinkedHashMap<String, Object> rowProperties = new LinkedHashMap<>();
String backgroundColor = credentialsSupportedResponse.getDisplay().get(0).getBackgroundColor();
Expand Down Expand Up @@ -246,6 +249,7 @@ private Map<String, Object> getPdfResourceFromVcProperties(LinkedHashMap<String,
String qrCodeImage = QRCodeType.OnlineSharing.equals(issuerDTO.getQr_code_type()) ? constructQRCodeWithAuthorizeRequest(vcCredentialResponse, dataShareUrl) :
QRCodeType.EmbeddedVC.equals(issuerDTO.getQr_code_type()) ? constructQRCodeWithVCData(vcCredentialResponse) : "";
data.put("qrCodeImage", qrCodeImage);
data.put("credentialValidity", credentialValidity);
data.put("logoUrl", issuerDTO.getDisplay().stream().map(d -> d.getLogo().getUrl()).findFirst().orElse(""));
data.put("rowProperties", rowProperties);
data.put("textColor", textColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.mimoto.dto.DataShareResponseDto;
import io.mosip.mimoto.dto.mimoto.VCCredentialResponse;
import io.mosip.mimoto.dto.openid.datashare.DataShareResponseWrapperDTO;
import io.mosip.mimoto.dto.openid.presentation.PresentationRequestDTO;
Expand Down Expand Up @@ -108,7 +109,9 @@ public VCCredentialResponse downloadCredentialFromDataShare(PresentationRequest
VCCredentialResponse vcCredentialResponse = objectMapper.readValue(vcCredentialResponseString, VCCredentialResponse.class);
log.info("Completed Mapping the Credential to Object => " + vcCredentialResponse );
if(vcCredentialResponse.getCredential() == null){
throw new InvalidCredentialResourceException(ErrorConstants.RESOURCE_EXPIRED.getErrorMessage());
DataShareResponseDto dataShareResponse = objectMapper.readValue(vcCredentialResponseString, DataShareResponseDto.class);
String errorCode = dataShareResponse.getErrors().get(0).getErrorCode();
throw new InvalidCredentialResourceException(errorCode.equals("DAT-SER-008") ? ErrorConstants.RESOURCE_NOT_FOUND.getErrorMessage() : ErrorConstants.RESOURCE_EXPIRED.getErrorMessage());
}
return vcCredentialResponse;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mosip.inji.ovp.redirect.url.pattern=%s#vp_token=%s&presentation_submission=%s
mosip.inji.ovp.error.redirect.url.pattern=%s?error=%s&error_description=%s

#DataShare Config
mosip.data.share.url=http://injiweb.datashare-inji
mosip.data.share.url=https://datashare-inji.dev1.mosip.net
mosip.data.share.create.url=${mosip.data.share.url}/v1/datashare/create/static-policyid/static-subscriberid
mosip.data.share.create.retry.count=3
mosip.data.share.get.url.pattern=http://datashare.datashare/v1/datashare/get/static-policyid/static-subscriberid/*
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/templates/credential-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
</div>
</div>
<img src="data:image/png;base64,$qrCodeImage" alt="QR Code"/>
<div style="display: flex; width: 100%; padding: 8px; border-radius: 8px; border: 2px solid #f6dfbe; background-color: #FFF7E5; margin: 32px 0;">
<div style="padding: 0 16px; text-align: center; color: #8B6105; font-size: 12px;">This credential can be verified a total of $credentialValidity times by authorized verifiers.</div>
</div>
</div>
</body>
</html>

0 comments on commit 83346ea

Please sign in to comment.