From fcf51fd092e7471fc8ddffaf0f6aa54142e69593 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Fri, 10 Mar 2023 13:34:46 +0530 Subject: [PATCH 01/12] Print attribute keys. --- .../print/service/impl/PrintServiceImpl.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index a998efa4..d9f688de 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -199,7 +199,11 @@ public boolean generateCard(EventModel eventModel) { String printid = (String) eventModel.getEvent().getId(); - + StringBuilder stringBuilder = new StringBuilder(); + for(Map.Entry entry : attributes.entrySet()) { + stringBuilder.append(entry.getKey()).append(","); + } + printLogger.info("Attribute keys: {}", stringBuilder.toString()); org.json.simple.JSONObject obj = new org.json.simple.JSONObject(); Object photo = attributes.get(APPLICANT_PHOTO); if (photo == null && isChildRegistration(attributes)) { @@ -208,24 +212,25 @@ public boolean generateCard(EventModel eventModel) { obj.put("photo", photo); obj.put("qrCode", attributes.get(QRCODE)); String fullAddress = getFullAddress(attributes); - obj.put("address", (fullAddress.length() > 0) ? fullAddress : "N/A"); - obj.put("locality", ((attributes.get("locality") != null && !attributes.get("locality").equals("")) ? attributes.get("locality").toString() : "N/A")); - obj.put("city", ((attributes.get("city") != null && !attributes.get("city").equals("")) ? attributes.get("city").toString() : "N/A")); - obj.put("state", ((attributes.get("state") != null && !attributes.get("state").equals("")) ? attributes.get("state").toString() : "N/A")); - obj.put("postalCode", ((attributes.get("postalCode") != null && !attributes.get("postalCode").equals("")) ? attributes.get("postalCode").toString() : "N/A")); - obj.put("gender", ((attributes.get("gender") != null && !attributes.get("gender").equals("")) ? attributes.get("gender").toString() : "N/A")); - obj.put("fullName", ((attributes.get("fullName") != null && !attributes.get("fullName").equals("")) ? attributes.get("fullName").toString() : "N/A")); - obj.put("dateOfBirth", ((attributes.get("dateOfBirth") != null && !attributes.get("dateOfBirth").equals("")) ? attributes.get("dateOfBirth").toString() : "N/A")); - obj.put("phone", ((attributes.get("phone") != null && !attributes.get("phone").equals("")) ? attributes.get("phone").toString() : "N/A")); - obj.put("vid", ((attributes.get("VID") != null && !attributes.get("VID").equals("")) ? attributes.get("VID").toString() : "N/A")); - obj.put("UIN", ((attributes.get("UIN") != null && !attributes.get("UIN").equals("")) ? attributes.get("UIN").toString() : "N/A")); - obj.put("email", ((attributes.get("email") != null && !attributes.get("email").equals("")) ? attributes.get("email").toString() : "N/A")); + obj.put("address", (fullAddress.length() > 0) ? fullAddress : " "); + obj.put("locality", ((attributes.get("locality") != null && !attributes.get("locality").equals("")) ? attributes.get("locality").toString() : " ")); + obj.put("city", ((attributes.get("city") != null && !attributes.get("city").equals("")) ? attributes.get("city").toString() : " ")); + obj.put("state", ((attributes.get("state") != null && !attributes.get("state").equals("")) ? attributes.get("state").toString() : " ")); + obj.put("postalCode", ((attributes.get("postalCode") != null && !attributes.get("postalCode").equals("")) ? attributes.get("postalCode").toString() : " ")); + obj.put("gender", ((attributes.get("gender") != null && !attributes.get("gender").equals("")) ? attributes.get("gender").toString() : " ")); + obj.put("fullName", ((attributes.get("fullName") != null && !attributes.get("fullName").equals("")) ? attributes.get("fullName").toString() : " ")); + obj.put("dateOfBirth", ((attributes.get("dateOfBirth") != null && !attributes.get("dateOfBirth").equals("")) ? attributes.get("dateOfBirth").toString() : " ")); + obj.put("phone", ((attributes.get("phone") != null && !attributes.get("phone").equals("")) ? attributes.get("phone").toString() : " ")); + obj.put("vid", ((attributes.get("VID") != null && !attributes.get("VID").equals("")) ? attributes.get("VID").toString() : " ")); + obj.put("UIN", ((attributes.get("UIN") != null && !attributes.get("UIN").equals("")) ? attributes.get("UIN").toString() : " ")); + obj.put("email", ((attributes.get("email") != null && !attributes.get("email").equals("")) ? attributes.get("email").toString() : " ")); String woenc = obj.toJSONString(); MspCardEntity mspCardEntity = new MspCardEntity(); mspCardEntity.setJsonData(woenc); mspCardEntity.setRequestId(printid); + mspCardEntity.setRegistrationDate(DateUtils.getUTCCurrentDateTime()); mspCardEntity.setStatus(90); UUID uuid=UUID.randomUUID(); mspCardEntity.setId(uuid.toString()); @@ -306,6 +311,7 @@ private Map getDocuments(String credential, String credentialTyp } setTemplateAttributes(decryptedJson.toString(), attributes); attributes.put(IdType.UIN.toString(), uin); + attributes.put(IdType.RID.toString(), registrationId); byte[] textFileByte = createTextFile(decryptedJson.toString()); byteMap.put(UIN_TEXT_FILE, textFileByte); From b01041f0a46c2e18e0833d90d9c4e3dbcc1ad04c Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Wed, 24 May 2023 18:57:04 +0530 Subject: [PATCH 02/12] New print design changes implemented --- pom.xml | 24 +- .../io/mosip/print/PrintPDFApplication.java | 20 -- .../io/mosip/print/config/PrintConfig.java | 15 ++ .../constant/CredentialStatusConstant.java | 10 + .../java/io/mosip/print/controller/Print.java | 2 +- .../print/service/impl/PrintServiceImpl.java | 205 ++++++++++-------- 6 files changed, 148 insertions(+), 128 deletions(-) create mode 100644 src/main/java/io/mosip/print/constant/CredentialStatusConstant.java diff --git a/pom.xml b/pom.xml index 0749d45f..dd0b9a56 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.mosip.print print - 1.2.0.1-SNAPSHOT + 1.2.0.1-B1 print @@ -39,8 +39,8 @@ **/dto/**,**/config/**,**/api/** 1.4.2 2.8.4 - 1.2.0.1-SNAPSHOT - 1.2.0.1-SNAPSHOT + 1.2.0.1-B1 + 1.2.0.1-B1 7.1.0 2.0.0 5.5.13 @@ -240,16 +240,16 @@ jackson-datatype-jsr310 2.12.0 - - info.weboftrust - ld-signatures-java - 0.8.0 - org.postgresql postgresql ${postgresql.version} + + io.mosip.vercred + vcverifier + 1.0-SNAPSHOT + @@ -271,10 +271,10 @@ false - - danubetech-maven-public - https://repo.danubetech.com/repository/maven-public/ - + + danubetech-maven-public + https://repo.danubetech.com/repository/maven-public/ + diff --git a/src/main/java/io/mosip/print/PrintPDFApplication.java b/src/main/java/io/mosip/print/PrintPDFApplication.java index 8cebd3b2..4bdde05b 100644 --- a/src/main/java/io/mosip/print/PrintPDFApplication.java +++ b/src/main/java/io/mosip/print/PrintPDFApplication.java @@ -6,14 +6,9 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import io.mosip.print.service.impl.CbeffImpl; -import io.mosip.print.spi.CbeffUtil; @SpringBootApplication(scanBasePackages = { "io.mosip.print.*", "${mosip.auth.adapter.impl.basepackage}" }, exclude = { SecurityAutoConfiguration.class, DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, @@ -26,21 +21,6 @@ @EnableAsync public class PrintPDFApplication { - - @Bean - @Primary - public CbeffUtil getCbeffUtil() { - return new CbeffImpl(); - } - - @Bean - public ThreadPoolTaskScheduler taskScheduler() { - ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); - threadPoolTaskScheduler.setPoolSize(5); - threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler"); - return threadPoolTaskScheduler; - } - public static void main(String[] args) { SpringApplication.run(PrintPDFApplication.class, args); } diff --git a/src/main/java/io/mosip/print/config/PrintConfig.java b/src/main/java/io/mosip/print/config/PrintConfig.java index c4fb5d7a..4e4010bc 100644 --- a/src/main/java/io/mosip/print/config/PrintConfig.java +++ b/src/main/java/io/mosip/print/config/PrintConfig.java @@ -1,7 +1,11 @@ package io.mosip.print.config; +import io.mosip.print.service.impl.CbeffImpl; +import io.mosip.print.spi.CbeffUtil; +import io.mosip.vercred.CredentialsVerifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -9,6 +13,17 @@ @Configuration public class PrintConfig { + @Bean + @Primary + public CbeffUtil getCbeffUtil() { + return new CbeffImpl(); + } + + @Bean + public CredentialsVerifier credentialsVerifier() { + return new CredentialsVerifier(); + } + @Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); diff --git a/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java b/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java new file mode 100644 index 00000000..41920645 --- /dev/null +++ b/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java @@ -0,0 +1,10 @@ +package io.mosip.print.constant; + +public enum CredentialStatusConstant { + + RECEIVED, + DOWNLOADED, + VALIDATED, + PRINTED, + ERROR +} diff --git a/src/main/java/io/mosip/print/controller/Print.java b/src/main/java/io/mosip/print/controller/Print.java index 93174aa2..11565003 100644 --- a/src/main/java/io/mosip/print/controller/Print.java +++ b/src/main/java/io/mosip/print/controller/Print.java @@ -40,7 +40,7 @@ public class Print { @PostMapping(path = "/callback/notifyPrint", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthenticateContentAndVerifyIntent(secret = "${mosip.event.secret}", callback = "/v1/cardprint/print/callback/notifyPrint", topic = "${mosip.event.topic}") public ResponseEntity handleSubscribeEvent(@RequestBody EventModel eventModel) throws Exception { - printLogger.info("event recieved from websub"+", id: {}",eventModel.getEvent().getId()); + printLogger.info("Event received from WebSub"+", id: {}",eventModel.getEvent().getId()); boolean isPrinted = printService.generateCard(eventModel); printLogger.info("printing status : {} for event id: {}",isPrinted,eventModel.getEvent().getId()); return new ResponseEntity<>("request accepted.", HttpStatus.OK); diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index d9f688de..087afde6 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -23,6 +23,11 @@ import io.mosip.print.spi.CbeffUtil; import io.mosip.print.spi.QrCodeGenerator; import io.mosip.print.util.*; +import io.mosip.vercred.CredentialsVerifier; +import io.mosip.vercred.exception.ProofDocumentNotFoundException; +import io.mosip.vercred.exception.ProofTypeNotFoundException; +import io.mosip.vercred.exception.PubicKeyNotFoundException; +import io.mosip.vercred.exception.UnknownException; import org.apache.commons.codec.binary.Base64; import org.joda.time.DateTime; import org.json.simple.JSONArray; @@ -80,9 +85,6 @@ public class PrintServiceImpl implements PrintService{ /** The Constant VALUE. */ private static final String VALUE = "value"; - /** The Constant UIN_CARD_TEMPLATE. */ - private static final String UIN_CARD_TEMPLATE = "RPR_UIN_CARD_TEMPLATE"; - /** The Constant FACE. */ private static final String FACE = "Face"; @@ -121,6 +123,8 @@ public class PrintServiceImpl implements PrintService{ @Autowired private QrCodeGenerator qrCodeGenerator; + @Autowired + private CredentialsVerifier credentialsVerifier; /** The Constant VID_CREATE_ID. */ public static final String VID_CREATE_ID = "registration.processor.id.repo.generate"; @@ -174,73 +178,75 @@ public class PrintServiceImpl implements PrintService{ public boolean generateCard(EventModel eventModel) { Map byteMap = new HashMap<>(); - String decodedCrdential = null; String credential = null; boolean isPrinted =false; - try{ - if (eventModel.getEvent().getDataShareUri() == null || eventModel.getEvent().getDataShareUri().isEmpty()) { - credential = eventModel.getEvent().getData().get("credential").toString(); - } else { - String dataShareUrl = eventModel.getEvent().getDataShareUri(); - URI dataShareUri = URI.create(dataShareUrl); - credential = restApiClient.getApi(dataShareUri, String.class); - } - - String ecryptionPin = eventModel.getEvent().getData().get("protectionKey").toString(); - decodedCrdential = cryptoCoreUtil.decrypt(credential); - - Map proofMap = new HashMap(); - proofMap = (Map) eventModel.getEvent().getData().get("proof"); - String sign = proofMap.get("signature").toString(); - Map attributes = getDocuments(decodedCrdential, - eventModel.getEvent().getData().get("credentialType").toString(), ecryptionPin, - eventModel.getEvent().getTransactionId(), getSignature(sign, credential), "UIN", false, eventModel.getEvent().getId(), - eventModel.getEvent().getData().get("registrationId").toString()); - - - String printid = (String) eventModel.getEvent().getId(); - StringBuilder stringBuilder = new StringBuilder(); - for(Map.Entry entry : attributes.entrySet()) { - stringBuilder.append(entry.getKey()).append(","); - } - printLogger.info("Attribute keys: {}", stringBuilder.toString()); - org.json.simple.JSONObject obj = new org.json.simple.JSONObject(); - Object photo = attributes.get(APPLICANT_PHOTO); - if (photo == null && isChildRegistration(attributes)) { - photo = defaultBabyPhoto; - } - obj.put("photo", photo); - obj.put("qrCode", attributes.get(QRCODE)); - String fullAddress = getFullAddress(attributes); - obj.put("address", (fullAddress.length() > 0) ? fullAddress : " "); - obj.put("locality", ((attributes.get("locality") != null && !attributes.get("locality").equals("")) ? attributes.get("locality").toString() : " ")); - obj.put("city", ((attributes.get("city") != null && !attributes.get("city").equals("")) ? attributes.get("city").toString() : " ")); - obj.put("state", ((attributes.get("state") != null && !attributes.get("state").equals("")) ? attributes.get("state").toString() : " ")); - obj.put("postalCode", ((attributes.get("postalCode") != null && !attributes.get("postalCode").equals("")) ? attributes.get("postalCode").toString() : " ")); - obj.put("gender", ((attributes.get("gender") != null && !attributes.get("gender").equals("")) ? attributes.get("gender").toString() : " ")); - obj.put("fullName", ((attributes.get("fullName") != null && !attributes.get("fullName").equals("")) ? attributes.get("fullName").toString() : " ")); - obj.put("dateOfBirth", ((attributes.get("dateOfBirth") != null && !attributes.get("dateOfBirth").equals("")) ? attributes.get("dateOfBirth").toString() : " ")); - obj.put("phone", ((attributes.get("phone") != null && !attributes.get("phone").equals("")) ? attributes.get("phone").toString() : " ")); - obj.put("vid", ((attributes.get("VID") != null && !attributes.get("VID").equals("")) ? attributes.get("VID").toString() : " ")); - obj.put("UIN", ((attributes.get("UIN") != null && !attributes.get("UIN").equals("")) ? attributes.get("UIN").toString() : " ")); - obj.put("email", ((attributes.get("email") != null && !attributes.get("email").equals("")) ? attributes.get("email").toString() : " ")); - - String woenc = obj.toJSONString(); - - MspCardEntity mspCardEntity = new MspCardEntity(); - mspCardEntity.setJsonData(woenc); - mspCardEntity.setRequestId(printid); - mspCardEntity.setRegistrationDate(DateUtils.getUTCCurrentDateTime()); - mspCardEntity.setStatus(90); - UUID uuid=UUID.randomUUID(); - mspCardEntity.setId(uuid.toString()); - mspCardRepository.create(mspCardEntity); - isPrinted=true; - }catch (Exception e){ - printLogger.error(e.getMessage() , e); - isPrinted = false; - } - return isPrinted; + try { + printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.RECEIVED.name()); + if (eventModel.getEvent().getDataShareUri() == null || eventModel.getEvent().getDataShareUri().isEmpty()) { + credential = eventModel.getEvent().getData().get("credential").toString(); + } else { + String dataShareUrl = eventModel.getEvent().getDataShareUri(); + URI dataShareUri = URI.create(dataShareUrl); + credential = restApiClient.getApi(dataShareUri, String.class); + } + printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.DOWNLOADED.name()); + String encryptionPin = eventModel.getEvent().getData().get("protectionKey").toString(); + String decodedCredential = cryptoCoreUtil.decrypt(credential); + printLogger.debug("vc is printed security valuation.... : {}", decodedCredential); + if (!hasPrintCredentialVerified(eventModel, decodedCredential)) return false; + printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.VALIDATED.name()); + Map proofMap = new HashMap(); + proofMap = (Map) eventModel.getEvent().getData().get("proof"); + String sign = proofMap.get("signature").toString(); + Map attributes = getDocuments(decodedCredential, + eventModel.getEvent().getData().get("credentialType").toString(), encryptionPin, + eventModel.getEvent().getTransactionId(), getSignature(sign, credential), "UIN", false, eventModel.getEvent().getId(), + eventModel.getEvent().getData().get("registrationId").toString()); + + + String printid = (String) eventModel.getEvent().getId(); + StringBuilder stringBuilder = new StringBuilder(); + for(Map.Entry entry : attributes.entrySet()) { + stringBuilder.append(entry.getKey()).append(","); + } + printLogger.info("Attribute keys: {}", stringBuilder.toString()); + org.json.simple.JSONObject obj = new org.json.simple.JSONObject(); + Object photo = attributes.get(APPLICANT_PHOTO); + if (photo == null && isChildRegistration(attributes)) { + photo = defaultBabyPhoto; + } + obj.put("photo", photo); + obj.put("qrCode", attributes.get(QRCODE)); + String fullAddress = getFullAddress(attributes); + obj.put("address", (fullAddress.length() > 0) ? fullAddress : " "); + obj.put("locality", ((attributes.get("locality") != null && !attributes.get("locality").equals("")) ? attributes.get("locality").toString() : " ")); + obj.put("city", ((attributes.get("city") != null && !attributes.get("city").equals("")) ? attributes.get("city").toString() : " ")); + obj.put("state", ((attributes.get("state") != null && !attributes.get("state").equals("")) ? attributes.get("state").toString() : " ")); + obj.put("postalCode", ((attributes.get("postalCode") != null && !attributes.get("postalCode").equals("")) ? attributes.get("postalCode").toString() : " ")); + obj.put("gender", ((attributes.get("gender") != null && !attributes.get("gender").equals("")) ? attributes.get("gender").toString() : " ")); + obj.put("fullName", ((attributes.get("fullName") != null && !attributes.get("fullName").equals("")) ? attributes.get("fullName").toString() : " ")); + obj.put("dateOfBirth", ((attributes.get("dateOfBirth") != null && !attributes.get("dateOfBirth").equals("")) ? attributes.get("dateOfBirth").toString() : " ")); + obj.put("phone", ((attributes.get("phone") != null && !attributes.get("phone").equals("")) ? attributes.get("phone").toString() : " ")); + obj.put("vid", ((attributes.get("VID") != null && !attributes.get("VID").equals("")) ? attributes.get("VID").toString() : " ")); + obj.put("UIN", ((attributes.get("UIN") != null && !attributes.get("UIN").equals("")) ? attributes.get("UIN").toString() : " ")); + obj.put("email", ((attributes.get("email") != null && !attributes.get("email").equals("")) ? attributes.get("email").toString() : " ")); + + String woenc = obj.toJSONString(); + + MspCardEntity mspCardEntity = new MspCardEntity(); + mspCardEntity.setJsonData(woenc); + mspCardEntity.setRequestId(printid); + mspCardEntity.setRegistrationDate(DateUtils.getUTCCurrentDateTime()); + mspCardEntity.setStatus(90); + UUID uuid=UUID.randomUUID(); + mspCardEntity.setId(uuid.toString()); + mspCardRepository.create(mspCardEntity); + isPrinted=true; + } catch (Exception e) { + printLogger.error(e.getMessage() , e); + isPrinted = false; + } + return isPrinted; } private boolean isChildRegistration(Map attributes) { @@ -285,13 +291,13 @@ private Map getDocuments(String credential, String credentialTyp Map attributes = new LinkedHashMap<>(); boolean isTransactionSuccessful = false; IdResponseDTO1 response = null; - String template = UIN_CARD_TEMPLATE; byte[] pdfbytes = null; try { credentialSubject = getCrdentialSubject(credential); org.json.JSONObject credentialSubjectJson = new org.json.JSONObject(credentialSubject); org.json.JSONObject decryptedJson = decryptAttribute(credentialSubjectJson, encryptionPin, credential); + //Print decryptedJson if(decryptedJson.has("biometrics")){ individualBio = decryptedJson.getString("biometrics"); String individualBiometric = new String(individualBio); @@ -323,7 +329,7 @@ private Map getDocuments(String credential, String credentialTyp PlatformErrorMessages.PRT_PRT_QRCODE_NOT_SET.name()); } - printStatusUpdate(requestId, credentialType, uin, refId, registrationId); + printStatusUpdate(requestId, CredentialStatusConstant.PRINTED.name()); isTransactionSuccessful = true; } catch (VidCreationException e) { @@ -430,6 +436,36 @@ private Map getDocuments(String credential, String credentialTyp return attributes; } + /** + * Verifies Print credentials using credential verifier. + * @param eventModel + * @param decodedCredential + * @return + */ + private boolean hasPrintCredentialVerified(EventModel eventModel, String decodedCredential) { + + if (verifyCredentialsFlag) { + printLogger.info("Configured received credentials to be verified. Flag {}", verifyCredentialsFlag); + try { + boolean verified = credentialsVerifier.verifyPrintCredentials(decodedCredential); + if (!verified) { + printLogger.error("Received Credentials failed in verifiable credential verify method. So, the credentials will not be printed." + + " Id: {}, Transaction Id: {}", eventModel.getEvent().getId(), eventModel.getEvent().getTransactionId()); + return false; + } + } catch (ProofDocumentNotFoundException | ProofTypeNotFoundException e) { + printLogger.error("Proof document is not available in the received credentials." + + " Id: {}, Transaction Id: {}", eventModel.getEvent().getId(), eventModel.getEvent().getTransactionId()); + return false; + } catch (UnknownException | PubicKeyNotFoundException e) { + printLogger.error("Received Credentials failed in verifiable credential verify method. So, the credentials will not be printed." + + " Id: {}, Transaction Id: {}", eventModel.getEvent().getId(), eventModel.getEvent().getTransactionId()); + return false; + } + } + return true; + } + /** * Creates the text file. @@ -727,44 +763,23 @@ private String getCrdentialSubject(String crdential) { return credentialSubject; } - private void printStatusUpdate(String requestId, byte[] data, String credentialType) - throws DataShareException, ApiNotAccessibleException, IOException, Exception { - DataShare dataShare = null; - dataShare = dataShareUtil.getDataShare(data, policyId, partnerId); - CredentialStatusEvent creEvent = new CredentialStatusEvent(); - LocalDateTime currentDtime = DateUtils.getUTCCurrentDateTime(); - StatusEvent sEvent = new StatusEvent(); - sEvent.setId(UUID.randomUUID().toString()); - sEvent.setRequestId(requestId); - sEvent.setStatus("printing"); - sEvent.setUrl(dataShare.getUrl()); - sEvent.setTimestamp(Timestamp.valueOf(currentDtime).toString()); - creEvent.setPublishedOn(new DateTime().toString()); - creEvent.setPublisher("PRINT_SERVICE"); - creEvent.setTopic(topic); - creEvent.setEvent(sEvent); - webSubSubscriptionHelper.printStatusUpdateEvent(topic, creEvent); - } - + private void printStatusUpdate(String requestId, String status) { - private void printStatusUpdate(String requestId, String credentialType, String uin, String printRefId, String registrationId) - throws DataShareException, ApiNotAccessibleException, IOException, Exception { CredentialStatusEvent creEvent = new CredentialStatusEvent(); LocalDateTime currentDtime = DateUtils.getUTCCurrentDateTime(); StatusEvent sEvent = new StatusEvent(); sEvent.setId(UUID.randomUUID().toString()); sEvent.setRequestId(requestId); - sEvent.setStatus("printing"); + sEvent.setStatus(status); sEvent.setUrl(""); sEvent.setTimestamp(Timestamp.valueOf(currentDtime).toString()); creEvent.setPublishedOn(new DateTime().toString()); - creEvent.setPublisher("PRINT_SERVICE"); + creEvent.setPublisher("MSP_PRINT_SERVICE"); creEvent.setTopic(topic); creEvent.setEvent(sEvent); webSubSubscriptionHelper.printStatusUpdateEvent(topic, creEvent); } - public org.json.JSONObject decryptAttribute(org.json.JSONObject data, String encryptionPin, String credential) throws ParseException { @@ -780,7 +795,7 @@ public org.json.JSONObject decryptAttribute(org.json.JSONObject data, String enc for (Object str : jsonArray) { CryptoWithPinRequestDto cryptoWithPinRequestDto = new CryptoWithPinRequestDto(); - CryptoWithPinResponseDto cryptoWithPinResponseDto = new CryptoWithPinResponseDto(); + CryptoWithPinResponseDto cryptoWithPinResponseDto; cryptoWithPinRequestDto.setUserPin(encryptionPin); cryptoWithPinRequestDto.setData(data.getString(str.toString())); From 470d4dec8149a752dd52f481a611a6e5e597bc11 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Thu, 1 Jun 2023 17:31:48 +0530 Subject: [PATCH 03/12] Enabled VC --- pom.xml | 16 +++++++-- .../print/service/impl/PrintServiceImpl.java | 33 ++++++++++++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index dd0b9a56..80db8d15 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ 3.7 2.6 1.11 - 1.66 + 1.68 3.8.1 3.3.3 42.2.2 @@ -70,6 +70,12 @@ org.springframework.cloud spring-cloud-starter-config 2.0.2.RELEASE + + + org.bouncycastle + bcprov-jdk15on + + org.springframework.boot @@ -145,7 +151,7 @@ org.bouncycastle - bcprov-jdk15on + bcprov-jdk15to18 ${bouncycastle.version} @@ -209,6 +215,12 @@ io.mosip.kernel kernel-websubclient-api ${kernel.websub.version} + + + org.bouncycastle + bcprov-jdk15on + + io.mosip.kernel diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index 087afde6..7bf84602 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -182,13 +182,7 @@ public boolean generateCard(EventModel eventModel) { boolean isPrinted =false; try { printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.RECEIVED.name()); - if (eventModel.getEvent().getDataShareUri() == null || eventModel.getEvent().getDataShareUri().isEmpty()) { - credential = eventModel.getEvent().getData().get("credential").toString(); - } else { - String dataShareUrl = eventModel.getEvent().getDataShareUri(); - URI dataShareUri = URI.create(dataShareUrl); - credential = restApiClient.getApi(dataShareUri, String.class); - } + credential = getCredential(eventModel); printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.DOWNLOADED.name()); String encryptionPin = eventModel.getEvent().getData().get("protectionKey").toString(); String decodedCredential = cryptoCoreUtil.decrypt(credential); @@ -249,6 +243,24 @@ public boolean generateCard(EventModel eventModel) { return isPrinted; } + /** + * Fetch credential from the event if not using datashare URL. + * @param eventModel + * @return + * @throws Exception + */ + private String getCredential(EventModel eventModel) throws Exception { + String credential; + if (eventModel.getEvent().getDataShareUri() == null || eventModel.getEvent().getDataShareUri().isEmpty()) { + credential = eventModel.getEvent().getData().get("credential").toString(); + } else { + String dataShareUrl = eventModel.getEvent().getDataShareUri(); + URI dataShareUri = URI.create(dataShareUrl); + credential = restApiClient.getApi(dataShareUri, String.class); + } + return credential; + } + private boolean isChildRegistration(Map attributes) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dobPattern); LocalDate dateOfBirth = LocalDate.parse((String) attributes.get("dateOfBirth"), dateTimeFormatter); @@ -610,6 +622,10 @@ private void setTemplateAttributes(String jsonString, Map attrib Object object = demographicIdentity.get(value); if (object != null) { try { + if (object instanceof Collection) { + // In order to parse the collection values, mainly for VC. + object = JsonUtil.writeValueAsString(object); + } obj = new JSONParser().parse(object.toString()); } catch (Exception e) { obj = object; @@ -759,8 +775,7 @@ public byte[] extractFaceImageData(byte[] decodedBioValue) { private String getCrdentialSubject(String crdential) { org.json.JSONObject jsonObject = new org.json.JSONObject(crdential); - String credentialSubject = jsonObject.get("credentialSubject").toString(); - return credentialSubject; + return jsonObject.get("credentialSubject").toString(); } private void printStatusUpdate(String requestId, String status) { From c4d188aab604e8b4f94d32f8d473621e3f1988e0 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Mon, 19 Jun 2023 12:10:34 +0530 Subject: [PATCH 04/12] Enabled VC and credential status update --- .../constant/CredentialStatusConstant.java | 11 +- .../io/mosip/print/service/PrintService.java | 2 +- .../mosip/print/service/UinCardGenerator.java | 30 -- .../print/service/impl/PDFGeneratorImpl.java | 328 ------------------ .../print/service/impl/PrintServiceImpl.java | 63 +--- .../service/impl/UinCardGeneratorImpl.java | 139 -------- .../java/io/mosip/print/spi/PDFGenerator.java | 108 ------ .../mosip/print/util/TemplateGenerator.java | 140 -------- .../test/service/impl/PrintServiceTest.java | 2 - .../test/util/UinCardGeneratorImplTest.java | 2 - 10 files changed, 22 insertions(+), 803 deletions(-) delete mode 100644 src/main/java/io/mosip/print/service/UinCardGenerator.java delete mode 100644 src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java delete mode 100644 src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java delete mode 100644 src/main/java/io/mosip/print/spi/PDFGenerator.java delete mode 100644 src/main/java/io/mosip/print/util/TemplateGenerator.java diff --git a/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java b/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java index 41920645..6fe967dd 100644 --- a/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java +++ b/src/main/java/io/mosip/print/constant/CredentialStatusConstant.java @@ -1,10 +1,11 @@ package io.mosip.print.constant; +/** + * An Enum for credential status. + */ public enum CredentialStatusConstant { - RECEIVED, - DOWNLOADED, - VALIDATED, - PRINTED, - ERROR + RECEIVED, + PRINTED, + ERROR } diff --git a/src/main/java/io/mosip/print/service/PrintService.java b/src/main/java/io/mosip/print/service/PrintService.java index 9309ce5e..f25c31c2 100644 --- a/src/main/java/io/mosip/print/service/PrintService.java +++ b/src/main/java/io/mosip/print/service/PrintService.java @@ -12,7 +12,7 @@ public interface PrintService { * @return * @throws Exception */ - public boolean generateCard(EventModel eventModel) throws Exception; + public boolean generateCard(EventModel eventModel); // Map getDocuments(String credentialSubject, String sign, // String cardType, diff --git a/src/main/java/io/mosip/print/service/UinCardGenerator.java b/src/main/java/io/mosip/print/service/UinCardGenerator.java deleted file mode 100644 index 4b36997b..00000000 --- a/src/main/java/io/mosip/print/service/UinCardGenerator.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.mosip.print.service; - -import java.io.InputStream; - -import io.mosip.print.constant.UinCardType; -import io.mosip.print.exception.ApisResourceAccessException; - -/** - * The Interface UinCardGenerator. - * - * @author M1048358 Alok - * - * @param - * the generic type - */ -public interface UinCardGenerator { - - /** - * Generate uin card. - * - * @param in - * the in - * @param type - * the type - * @param password - * the password - * @return the i - */ - public I generateUinCard(InputStream in, UinCardType type, String password) throws ApisResourceAccessException; -} diff --git a/src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java b/src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java deleted file mode 100644 index 5b6dca41..00000000 --- a/src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java +++ /dev/null @@ -1,328 +0,0 @@ -package io.mosip.print.service.impl; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.security.GeneralSecurityException; -import java.security.PrivateKey; -import java.security.Provider; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.List; - -import javax.imageio.ImageIO; - -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.itextpdf.html2pdf.ConverterProperties; -import com.itextpdf.html2pdf.HtmlConverter; -import com.itextpdf.html2pdf.css.media.MediaDeviceDescription; -import com.itextpdf.html2pdf.css.media.MediaType; -import com.itextpdf.html2pdf.css.util.CssUtils; -import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider; -import com.itextpdf.io.image.ImageDataFactory; -import com.itextpdf.kernel.geom.PageSize; -import com.itextpdf.kernel.pdf.PdfDocument; -import com.itextpdf.kernel.pdf.PdfWriter; -import com.itextpdf.layout.Document; -import com.itextpdf.layout.element.Image; -import com.itextpdf.text.DocumentException; -import com.itextpdf.text.Rectangle; -import com.itextpdf.text.pdf.PdfCopy; -import com.itextpdf.text.pdf.PdfReader; -import com.itextpdf.text.pdf.PdfSignatureAppearance; -import com.itextpdf.text.pdf.PdfStamper; -import com.itextpdf.text.pdf.security.BouncyCastleDigest; -import com.itextpdf.text.pdf.security.CertificateUtil; -import com.itextpdf.text.pdf.security.CrlClient; -import com.itextpdf.text.pdf.security.CrlClientOnline; -import com.itextpdf.text.pdf.security.ExternalDigest; -import com.itextpdf.text.pdf.security.ExternalSignature; -import com.itextpdf.text.pdf.security.MakeSignature; -import com.itextpdf.text.pdf.security.MakeSignature.CryptoStandard; -import com.itextpdf.text.pdf.security.OcspClient; -import com.itextpdf.text.pdf.security.OcspClientBouncyCastle; -import com.itextpdf.text.pdf.security.PrivateKeySignature; -import com.itextpdf.text.pdf.security.TSAClient; -import com.itextpdf.text.pdf.security.TSAClientBouncyCastle; - -import io.mosip.print.constant.PDFGeneratorExceptionCodeConstant; -import io.mosip.print.exception.PDFGeneratorException; -import io.mosip.print.logger.PrintLogger; -import io.mosip.print.model.CertificateEntry; -import io.mosip.print.spi.PDFGenerator; -import io.mosip.print.util.EmptyCheckUtils; - -/** - * The PdfGeneratorImpl is the class you will use most when converting processed - * Template to PDF. It contains a series of methods that accept processed - * Template as a {@link String}, {@link File}, or {@link InputStream}, and - * convert it to PDF in the form of an {@link OutputStream}, {@link File} - * - * @author Urvil Joshi - * @author Uday Kumar - * @author Neha - * - * @since 1.0.0 - * - */ -@Component -public class PDFGeneratorImpl implements PDFGenerator { - private static final Logger LOGGER = PrintLogger.getLogger(PDFGeneratorImpl.class); - - private static final String SHA256 = "SHA256"; - - private static final String OUTPUT_FILE_EXTENSION = ".pdf"; - - @Value("${mosip.kernel.pdf_owner_password}") - private String pdfOwnerPassword; - - /* - * (non-Javadoc) - * - * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.io. - * InputStream) - */ - @Override - public OutputStream generate(InputStream is) throws IOException { - isValidInputStream(is); - OutputStream os = new ByteArrayOutputStream(); - try { - HtmlConverter.convertToPdf(is, os); - } catch (Exception e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - e.getMessage()); - } - return os; - } - - /* - * (non-Javadoc) - * - * @see - * io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.lang.String) - */ - @Override - public OutputStream generate(String template) throws IOException { - OutputStream os = new ByteArrayOutputStream(); - try { - HtmlConverter.convertToPdf(template, os); - } catch (Exception e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorMessage(), e); - } - return os; - } - - /* - * (non-Javadoc) - * - * @see - * io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.lang.String, - * java.lang.String, java.lang.String) - */ - @Override - public void generate(String templatePath, String outpuFilePath, String outputFileName) throws IOException { - File outputFile = new File(outpuFilePath + outputFileName + OUTPUT_FILE_EXTENSION); - try { - HtmlConverter.convertToPdf(new File(templatePath), outputFile); - } catch (Exception e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorMessage(), e); - } - - } - - /* - * (non-Javadoc) - * - * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.io. - * InputStream, java.lang.String) - */ - @Override - public OutputStream generate(InputStream is, String resourceLoc) throws IOException { - isValidInputStream(is); - OutputStream os = new ByteArrayOutputStream(); - PdfWriter pdfWriter = new PdfWriter(os); - PdfDocument pdfDoc = new PdfDocument(pdfWriter); - ConverterProperties converterProperties = new ConverterProperties(); - pdfDoc.setTagged(); - PageSize pageSize = PageSize.A4.rotate(); - pdfDoc.setDefaultPageSize(pageSize); - float screenWidth = CssUtils.parseAbsoluteLength("" + pageSize.getWidth()); - MediaDeviceDescription mediaDescription = new MediaDeviceDescription(MediaType.SCREEN); - mediaDescription.setWidth(screenWidth); - DefaultFontProvider dfp = new DefaultFontProvider(true, true, false); - converterProperties.setMediaDeviceDescription(mediaDescription); - converterProperties.setFontProvider(dfp); - converterProperties.setBaseUri(resourceLoc); - converterProperties.setCreateAcroForm(true); - try { - HtmlConverter.convertToPdf(is, pdfDoc, converterProperties); - } catch (Exception e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - e.getMessage()); - } - return os; - } - - /* - * (non-Javadoc) - * - * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#asPDF(java.util.List) - */ - @Override - public byte[] asPDF(List bufferedImages) throws IOException { - byte[] scannedPdfFile = null; - - try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { - - PdfWriter pdfWriter = new PdfWriter(byteArrayOutputStream); - Document document = new Document(new PdfDocument(pdfWriter)); - - for (BufferedImage bufferedImage : bufferedImages) { - Image image = new Image(ImageDataFactory.create(getImageBytesFromBufferedImage(bufferedImage))); - image.scaleToFit(600, 750); - document.add(image); - } - - document.close(); - pdfWriter.close(); - scannedPdfFile = byteArrayOutputStream.toByteArray(); - } catch (IOException e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - e.getMessage()); - } - return scannedPdfFile; - } - - private byte[] getImageBytesFromBufferedImage(BufferedImage bufferedImage) throws IOException { - byte[] imageInByte; - - ByteArrayOutputStream imagebyteArray = new ByteArrayOutputStream(); - ImageIO.write(bufferedImage, "jpg", imagebyteArray); - imagebyteArray.flush(); - imageInByte = imagebyteArray.toByteArray(); - imagebyteArray.close(); - - return imageInByte; - } - - /* - * (non-Javadoc) - * - * @see - * io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#mergePDF(java.util.List) - */ - @Override - public byte[] mergePDF(List pdfFiles) throws IOException { - try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { - com.itextpdf.text.Document document = new com.itextpdf.text.Document(); - PdfCopy pdfCopy = new PdfCopy(document, byteArrayOutputStream); - document.open(); - for (URL file : pdfFiles) { - PdfReader reader = new PdfReader(file); - pdfCopy.addDocument(reader); - pdfCopy.freeReader(reader); - reader.close(); - } - document.close(); - return byteArrayOutputStream.toByteArray(); - } catch (IOException | DocumentException e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - e.getMessage()); - } - } - - @Override - public OutputStream signAndEncryptPDF(byte[] pdf, io.mosip.print.model.Rectangle rectangle, - String reason, int pageNumber, Provider provider, - CertificateEntry certificateEntry, String password) - throws IOException, GeneralSecurityException { - OutputStream outputStream = new ByteArrayOutputStream(); - PdfReader pdfReader = null; - PdfStamper pdfStamper = null; - try { - pdfReader = new PdfReader(pdf); - pdfStamper = PdfStamper.createSignature(pdfReader, outputStream, '\0'); - - if (password != null && !password.trim().isEmpty()) { - pdfStamper.setEncryption(password.getBytes(), pdfOwnerPassword.getBytes(), - com.itextpdf.text.pdf.PdfWriter.ALLOW_PRINTING, - com.itextpdf.text.pdf.PdfWriter.ENCRYPTION_AES_256); - } - PdfSignatureAppearance signAppearance = pdfStamper.getSignatureAppearance(); - - signAppearance.setReason(reason); - // comment next line to have an invisible signature - signAppearance.setVisibleSignature( - new Rectangle(rectangle.getLlx(), rectangle.getLly(), rectangle.getUrx(), rectangle.getUry()), - pageNumber, null); - - OcspClient ocspClient = new OcspClientBouncyCastle(null); - TSAClient tsaClient = null; - for (X509Certificate certificate : certificateEntry.getChain()) { - String tsaUrl = CertificateUtil.getTSAURL(certificate); - if (tsaUrl != null) { - tsaClient = new TSAClientBouncyCastle(tsaUrl); - break; - } - signAppearance.setCertificate(certificate); - } - - List crlList = new ArrayList<>(); - crlList.add(new CrlClientOnline(certificateEntry.getChain())); - - ExternalSignature pks = new PrivateKeySignature(certificateEntry.getPrivateKey(), "SHA256", - provider.getName()); - ExternalDigest digest = new BouncyCastleDigest(); - - // Sign the document using the detached mode, CMS or CAdES equivalent. - MakeSignature.signDetached(signAppearance, digest, pks, certificateEntry.getChain(), crlList, ocspClient, - tsaClient, 0, CryptoStandard.CMS); - - pdfStamper.close(); - - } catch (DocumentException e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - e.getMessage(), e); - } finally { - outputStream.close(); - if (pdfStamper != null) { - closeQuietly(pdfStamper); - } - if (pdfReader != null) { - pdfReader.close(); - } - } - return outputStream; - } - - /* - - */ - - // Quietly close the pdfStamper. - private void closeQuietly(final PdfStamper pdfStamper) throws IOException { - try { - pdfStamper.close(); - } catch (DocumentException e) { - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - e.getMessage(), e); - } - } - - private void isValidInputStream(InputStream dataInputStream) { - if (EmptyCheckUtils.isNullEmpty(dataInputStream)) { - throw new PDFGeneratorException( - PDFGeneratorExceptionCodeConstant.INPUTSTREAM_NULL_EMPTY_EXCEPTION.getErrorCode(), - PDFGeneratorExceptionCodeConstant.INPUTSTREAM_NULL_EMPTY_EXCEPTION.getErrorMessage()); - } - } -} diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index 7bf84602..9525e6c7 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -7,11 +7,9 @@ import io.mosip.print.constant.*; import io.mosip.print.dto.CryptoWithPinRequestDto; import io.mosip.print.dto.CryptoWithPinResponseDto; -import io.mosip.print.dto.DataShare; import io.mosip.print.dto.JsonValue; import io.mosip.print.entity.MspCardEntity; import io.mosip.print.exception.*; -import io.mosip.print.idrepo.dto.IdResponseDTO1; import io.mosip.print.logger.LogDescription; import io.mosip.print.logger.PrintLogger; import io.mosip.print.model.CredentialStatusEvent; @@ -19,7 +17,6 @@ import io.mosip.print.model.StatusEvent; import io.mosip.print.repository.MspCardRepository; import io.mosip.print.service.PrintService; -import io.mosip.print.service.UinCardGenerator; import io.mosip.print.spi.CbeffUtil; import io.mosip.print.spi.QrCodeGenerator; import io.mosip.print.util.*; @@ -60,7 +57,7 @@ import java.util.*; @Service -public class PrintServiceImpl implements PrintService{ +public class PrintServiceImpl implements PrintService { private String topic="CREDENTIAL_STATUS_UPDATE"; @@ -68,10 +65,7 @@ public class PrintServiceImpl implements PrintService{ private WebSubSubscriptionHelper webSubSubscriptionHelper; @Autowired - private DataShareUtil dataShareUtil; - - @Autowired - CryptoUtil cryptoUtil; + private CryptoUtil cryptoUtil; @Autowired private RestApiClient restApiClient; @@ -101,24 +95,12 @@ public class PrintServiceImpl implements PrintService{ private static final String UINCARDPASSWORD = "mosip.registration.processor.print.service.uincard.password"; /** The print logger. */ - Logger printLogger = PrintLogger.getLogger(PrintServiceImpl.class); - - /** The core audit request builder. */ - @Autowired - private AuditLogRequestBuilder auditLogRequestBuilder; - - /** The template generator. */ - @Autowired - private TemplateGenerator templateGenerator; + private Logger printLogger = PrintLogger.getLogger(PrintServiceImpl.class); /** The utilities. */ @Autowired private Utilities utilities; - /** The uin card generator. */ - @Autowired - private UinCardGenerator uinCardGenerator; - /** The qr code generator. */ @Autowired private QrCodeGenerator qrCodeGenerator; @@ -145,12 +127,6 @@ public class PrintServiceImpl implements PrintService{ @Autowired private Environment env; - @Value("${mosip.datashare.partner.id}") - private String partnerId; - - @Value("${mosip.datashare.policy.id}") - private String policyId; - @Value("${mosip.template-language}") private String templateLang; @@ -160,9 +136,6 @@ public class PrintServiceImpl implements PrintService{ @Value("${mosip.print.verify.credentials.flag:true}") private boolean verifyCredentialsFlag; - @Value("${token.request.clientId}") - private String clientId; - @Value("${mosip.print.default.infant.photo:null}") private String defaultBabyPhoto; @@ -183,12 +156,10 @@ public boolean generateCard(EventModel eventModel) { try { printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.RECEIVED.name()); credential = getCredential(eventModel); - printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.DOWNLOADED.name()); String encryptionPin = eventModel.getEvent().getData().get("protectionKey").toString(); String decodedCredential = cryptoCoreUtil.decrypt(credential); printLogger.debug("vc is printed security valuation.... : {}", decodedCredential); if (!hasPrintCredentialVerified(eventModel, decodedCredential)) return false; - printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.VALIDATED.name()); Map proofMap = new HashMap(); proofMap = (Map) eventModel.getEvent().getData().get("proof"); String sign = proofMap.get("signature").toString(); @@ -229,18 +200,24 @@ public boolean generateCard(EventModel eventModel) { MspCardEntity mspCardEntity = new MspCardEntity(); mspCardEntity.setJsonData(woenc); - mspCardEntity.setRequestId(printid); + mspCardEntity.setRequestId(eventModel.getEvent().getTransactionId()); mspCardEntity.setRegistrationDate(DateUtils.getUTCCurrentDateTime()); mspCardEntity.setStatus(90); UUID uuid=UUID.randomUUID(); mspCardEntity.setId(uuid.toString()); mspCardRepository.create(mspCardEntity); isPrinted=true; - } catch (Exception e) { - printLogger.error(e.getMessage() , e); - isPrinted = false; + } catch (Exception e) { + printLogger.error(e.getMessage() , e); + isPrinted = false; + } finally { + if (isPrinted) { + printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.PRINTED.name()); + } else { + printStatusUpdate(eventModel.getEvent().getTransactionId(), CredentialStatusConstant.ERROR.name()); } - return isPrinted; + } + return isPrinted; } /** @@ -297,12 +274,10 @@ private Map getDocuments(String credential, String credentialTyp Map byteMap = new HashMap<>(); String uin = null; LogDescription description = new LogDescription(); - String password = null; boolean isPhotoSet=false; String individualBio = null; Map attributes = new LinkedHashMap<>(); boolean isTransactionSuccessful = false; - IdResponseDTO1 response = null; byte[] pdfbytes = null; try { @@ -318,9 +293,6 @@ private Map getDocuments(String credential, String credentialTyp } uin = decryptedJson.getString("UIN"); - if (isPasswordProtected) { - password = getPassword(uin); - } if (!isPhotoSet) { printLogger.debug(LoggerFileConstant.SESSIONID.toString(), @@ -435,12 +407,7 @@ private Map getDocuments(String credential, String credentialTyp eventName = EventName.EXCEPTION.toString(); eventType = EventType.SYSTEM.toString(); } - /** Module-Id can be Both Success/Error code */ - String moduleId = isTransactionSuccessful ? PlatformSuccessMessages.RPR_PRINT_SERVICE_SUCCESS.getCode() - : description.getCode(); - String moduleName = ModuleName.PRINT_SERVICE.toString(); - auditLogRequestBuilder.createAuditRequestBuilder(description.getMessage(), eventId, eventName, eventType, - moduleId, moduleName, uin); + } printLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), "", "PrintServiceImpl::getDocuments()::exit"); diff --git a/src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java b/src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java deleted file mode 100644 index 1cfef21c..00000000 --- a/src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -package io.mosip.print.service.impl; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.env.Environment; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import io.mosip.print.constant.ApiName; -import io.mosip.print.constant.PDFGeneratorExceptionCodeConstant; -import io.mosip.print.constant.UinCardType; -import io.mosip.print.core.http.RequestWrapper; -import io.mosip.print.core.http.ResponseWrapper; -import io.mosip.print.dto.ErrorDTO; -import io.mosip.print.dto.PDFSignatureRequestDto; -import io.mosip.print.dto.SignatureResponseDto; -import io.mosip.print.exception.ApisResourceAccessException; -import io.mosip.print.exception.PDFGeneratorException; -import io.mosip.print.exception.PDFSignatureException; -import io.mosip.print.exception.PlatformErrorMessages; -import io.mosip.print.logger.PrintLogger; -import io.mosip.print.service.PrintRestClientService; -import io.mosip.print.service.UinCardGenerator; -import io.mosip.print.spi.PDFGenerator; -import io.mosip.print.util.DateUtils; -import io.mosip.print.util.RestApiClient; - -/** - * The Class UinCardGeneratorImpl. - * - * @author M1048358 Alok - */ -@Component -public class UinCardGeneratorImpl implements UinCardGenerator { - - /** The pdf generator. */ - @Autowired - private PDFGenerator pdfGenerator; - - /** The print logger. */ - private Logger printLogger = PrintLogger.getLogger(UinCardGeneratorImpl.class); - - private static final String DATETIME_PATTERN = "mosip.print.datetime.pattern"; - - - @Value("${mosip.print.service.uincard.lowerleftx}") - private int lowerLeftX; - - @Value("${mosip.print.service.uincard.lowerlefty}") - private int lowerLeftY; - - @Value("${mosip.print.service.uincard.upperrightx}") - private int upperRightX; - - @Value("${mosip.print.service.uincard.upperrighty}") - private int upperRightY; - - @Value("${mosip.print.service.uincard.signature.reason}") - private String reason; - - - @Autowired - private PrintRestClientService restClientService; - - @Autowired - private Environment env; - - - ObjectMapper mapper = new ObjectMapper(); - - - @Autowired - private RestApiClient restApiClient; - - - @Override - public byte[] generateUinCard(InputStream in, UinCardType type, String password) - throws ApisResourceAccessException { - printLogger.debug("UinCardGeneratorImpl::generateUinCard()::entry"); - byte[] pdfSignatured=null; - ByteArrayOutputStream out = null; - try { - out = (ByteArrayOutputStream) pdfGenerator.generate(in); - PDFSignatureRequestDto request = new PDFSignatureRequestDto(lowerLeftX, lowerLeftY, upperRightX, - upperRightY, reason, 1, password); - request.setApplicationId("KERNEL"); - request.setReferenceId("SIGN"); - request.setData(Base64.encodeBase64String(out.toByteArray())); - DateTimeFormatter format = DateTimeFormatter.ofPattern(env.getProperty(DATETIME_PATTERN)); - LocalDateTime localdatetime = LocalDateTime - .parse(DateUtils.getUTCCurrentDateTimeString(env.getProperty(DATETIME_PATTERN)), format); - - request.setTimeStamp(DateUtils.getUTCCurrentDateTimeString()); - RequestWrapper requestWrapper = new RequestWrapper<>(); - - requestWrapper.setRequest(request); - requestWrapper.setRequesttime(localdatetime); - ResponseWrapper responseWrapper; - SignatureResponseDto signatureResponseDto; - - responseWrapper= (ResponseWrapper)restClientService.postApi(ApiName.PDFSIGN, null, null, - requestWrapper, ResponseWrapper.class,MediaType.APPLICATION_JSON); - - - if (responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) { - ErrorDTO error = responseWrapper.getErrors().get(0); - throw new PDFSignatureException(error.getMessage()); - } - signatureResponseDto = mapper.readValue(mapper.writeValueAsString(responseWrapper.getResponse()), - SignatureResponseDto.class); - - pdfSignatured = Base64.decodeBase64(signatureResponseDto.getData()); - - } catch (IOException | PDFGeneratorException e) { - printLogger.error( e.getMessage(),e); - throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), - PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorMessage() ,e); - } - catch (ApisResourceAccessException e) { - printLogger.error(PlatformErrorMessages.PRT_PRT_PDF_SIGNATURE_EXCEPTION.name() , e.getMessage() - ,e); - throw new PDFSignatureException(e); } - - printLogger.debug("UinCardGeneratorImpl::generateUinCard()::exit"); - - return pdfSignatured; - } - -} diff --git a/src/main/java/io/mosip/print/spi/PDFGenerator.java b/src/main/java/io/mosip/print/spi/PDFGenerator.java deleted file mode 100644 index 8d4b558b..00000000 --- a/src/main/java/io/mosip/print/spi/PDFGenerator.java +++ /dev/null @@ -1,108 +0,0 @@ -package io.mosip.print.spi; - -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.security.GeneralSecurityException; -import java.security.PrivateKey; -import java.security.Provider; -import java.security.cert.X509Certificate; -import java.util.List; - -import io.mosip.print.model.CertificateEntry; -import io.mosip.print.model.Rectangle; - -/** - * This interface is has specifications for PDF generation from different types. - * - * The user of this interface will have basic functionalities related to PDF. - * - * @author Urvil Joshi - * @author Uday Kumar - * @author Neha - * - * @since 1.0.0 - */ -public interface PDFGenerator { - /** - * Converts HTML obtained from an {@link InputStream} to a PDF written to an - * {@link OutputStream}. - * - * @param htmlStream the processedTemplate in the form of a {@link InputStream} - * @throws IOException Signals that an I/O exception has occurred. - * @return outpustStream PDF Output Stream (PDF stream) - */ - public OutputStream generate(InputStream htmlStream) throws IOException; - - /** - * This method will convert process Template as String to outpustStream - * - * @param template the processedTemplate in the form of a {@link String} - * @return OutputStream PDF Output Stream (PDF stream) - * @throws IOException Signals that an I/O exception has occurred. - */ - public OutputStream generate(String template) throws IOException; - - /** - * This method will take input as template file and convert template to PDF and - * save to the given path with given fileName. - * - * @param templatePath the processedTemplate in the form of a {@link String} - * @param outputFilePath Output File Path - * @param outputFileName Output File Name - * @throws IOException Signals that an I/O exception has occurred. - */ - public void generate(String templatePath, String outputFilePath, String outputFileName) throws IOException; - - /** - * This method will convert InputStream to OutputStream. - * - * @param dataStream the processedTemplate in the form of a - * {@link InputStream}. - * @param resourceLoc resourceLoction {@link String}. - * @throws IOException Signals that an I/O exception has occurred. - * @return outpustStream PDF Output Stream (PDF stream). - */ - public OutputStream generate(InputStream dataStream, String resourceLoc) throws IOException; - - /** - * This method will convert BufferedImage list to Byte Array. - * - * @param bufferedImages the input image to convert as PDF. - * @return array comprising PDF. - * @throws IOException Signals that an I/O exception has occurred. - */ - public byte[] asPDF(List bufferedImages) throws IOException; - - /** - * This method will merge all the PDF files. - * - * @param pdfLists the URL list of PDF files. - * @return the byte array comprising merged file. - * @throws IOException Signals that an I/O exception has occurred. - */ - public byte[] mergePDF(List pdfLists) throws IOException; - - /** - * Signs a PDF and protect it with password - * - * @param pdf byte array of pdf. - * @param rectangle {@link Rectangle} class to enclose signing - * @param reason reason of signing. - * @param pageNumber page number of rectangle. - * @param provider {@link Provider}. - * @param certificateEntry {@link CertificateEntry} class for certificate and - * private key as Input; - * @param password password for protecting pdf. - * @return {@link OutputStream} of signed PDF. - * @throws IOException Signals that an I/O exception has occurred. - * @throws GeneralSecurityException Signals general security exception while - * signing. - */ - OutputStream signAndEncryptPDF(byte[] pdf, Rectangle rectangle, String reason, int pageNumber, Provider provider, - CertificateEntry certificateEntry, String password) - throws IOException, GeneralSecurityException; - -} diff --git a/src/main/java/io/mosip/print/util/TemplateGenerator.java b/src/main/java/io/mosip/print/util/TemplateGenerator.java deleted file mode 100644 index e6e40d48..00000000 --- a/src/main/java/io/mosip/print/util/TemplateGenerator.java +++ /dev/null @@ -1,140 +0,0 @@ -package io.mosip.print.util; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.runtime.RuntimeConstants; -import org.apache.velocity.runtime.log.NullLogChute; -import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; -import org.apache.velocity.runtime.resource.loader.FileResourceLoader; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import io.mosip.kernel.core.templatemanager.exception.TemplateMethodInvocationException; -import io.mosip.kernel.core.templatemanager.exception.TemplateParsingException; -import io.mosip.kernel.core.templatemanager.exception.TemplateResourceNotFoundException; -import io.mosip.print.constant.ApiName; -import io.mosip.print.constant.LoggerFileConstant; -import io.mosip.print.core.http.ResponseWrapper; -import io.mosip.print.dto.TemplateResponseDto; -import io.mosip.print.exception.ApisResourceAccessException; -import io.mosip.print.exception.PlatformErrorMessages; -import io.mosip.print.exception.TemplateProcessingFailureException; -import io.mosip.print.logger.PrintLogger; -import io.mosip.print.service.PrintRestClientService; -import io.mosip.print.service.impl.TemplateManagerImpl; -import io.mosip.print.spi.TemplateManager; - -/** - * The Class TemplateGenerator. - * - * @author M1048358 Alok - */ -@Component -public class TemplateGenerator { - - /** The reg proc logger. */ - private static Logger printLogger = PrintLogger.getLogger(TemplateGenerator.class); - - /** The resource loader. */ - private String resourceLoader = "classpath"; - - /** The template path. */ - private String templatePath = "."; - - /** The cache. */ - private boolean cache = Boolean.TRUE; - - /** The default encoding. */ - private String defaultEncoding = StandardCharsets.UTF_8.name(); - - /** The rest client service. */ - @Autowired - private PrintRestClientService restClientService; - - @Autowired - private ObjectMapper mapper; - - /** - * Gets the template. - * - * @param templateTypeCode - * the template type code - * @param attributes - * the attributes - * @param langCode - * the lang code - * @return the template - * @throws IOException - * Signals that an I/O exception has occurred. - * @throws ApisResourceAccessException - * the apis resource access exception - */ - public InputStream getTemplate(String templateTypeCode, Map attributes, String langCode) - throws IOException, ApisResourceAccessException { - - ResponseWrapper responseWrapper; - TemplateResponseDto template; - printLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "", - "TemplateGenerator::getTemplate()::entry"); - - try { - List pathSegments = new ArrayList<>(); - pathSegments.add(langCode); - pathSegments.add(templateTypeCode); - - responseWrapper = (ResponseWrapper) restClientService.getApi(ApiName.TEMPLATES, pathSegments, "", "", - ResponseWrapper.class); - template = mapper.readValue(mapper.writeValueAsString(responseWrapper.getResponse()), - TemplateResponseDto.class); - - InputStream fileTextStream = null; - if (template != null) { - InputStream stream = new ByteArrayInputStream( - template.getTemplates().iterator().next().getFileText().getBytes()); - fileTextStream = getTemplateManager().merge(stream, attributes); - } - printLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "", - "TemplateGenerator::getTemplate()::exit"); - return fileTextStream; - - } catch (TemplateResourceNotFoundException | TemplateParsingException | TemplateMethodInvocationException e) { - printLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), - null, PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.name() + e.getMessage() - + ExceptionUtils.getStackTrace(e)); - throw new TemplateProcessingFailureException(PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.getCode()); - } - } - - /** - * Gets the template manager. - * - * @return the template manager - */ - public TemplateManager getTemplateManager() { - final Properties properties = new Properties(); - properties.put(RuntimeConstants.INPUT_ENCODING, defaultEncoding); - properties.put(RuntimeConstants.OUTPUT_ENCODING, defaultEncoding); - properties.put(RuntimeConstants.ENCODING_DEFAULT, defaultEncoding); - properties.put(RuntimeConstants.RESOURCE_LOADER, resourceLoader); - properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath); - properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, cache); - properties.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName()); - properties.put("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); - properties.put("file.resource.loader.class", FileResourceLoader.class.getName()); - VelocityEngine engine = new VelocityEngine(properties); - engine.init(); - return new TemplateManagerImpl(engine); - } -} diff --git a/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java b/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java index 6908edf3..c3c1d924 100644 --- a/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java +++ b/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java @@ -25,14 +25,12 @@ import io.mosip.print.dto.ResponseDTO; import io.mosip.print.model.EventModel; import io.mosip.print.service.PrintRestClientService; -import io.mosip.print.service.UinCardGenerator; import io.mosip.print.service.impl.PrintServiceImpl; import io.mosip.print.spi.CbeffUtil; import io.mosip.print.spi.QrCodeGenerator; import io.mosip.print.test.TestBootApplication; import io.mosip.print.util.CryptoCoreUtil; import io.mosip.print.util.JsonUtil; -import io.mosip.print.util.TemplateGenerator; import io.mosip.print.util.Utilities; diff --git a/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java b/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java index e3ba6af1..21e0662f 100644 --- a/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java +++ b/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java @@ -33,8 +33,6 @@ import io.mosip.print.exception.PDFGeneratorException; import io.mosip.print.exception.PDFSignatureException; import io.mosip.print.service.PrintRestClientService; -import io.mosip.print.service.impl.UinCardGeneratorImpl; -import io.mosip.print.spi.PDFGenerator; import io.mosip.print.test.TestBootApplication; @SpringBootTest(classes = TestBootApplication.class) From d6b76b494d7358345440afe84d2a1e728fe194d5 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Mon, 19 Jun 2023 15:29:09 +0530 Subject: [PATCH 05/12] Adding the deleted files --- .../mosip/print/service/UinCardGenerator.java | 30 ++ .../print/service/impl/PDFGeneratorImpl.java | 310 ++++++++++++++++++ .../service/impl/UinCardGeneratorImpl.java | 137 ++++++++ .../java/io/mosip/print/spi/PDFGenerator.java | 108 ++++++ .../mosip/print/util/TemplateGenerator.java | 138 ++++++++ .../resources/application-local1.properties | 41 +-- .../test/service/impl/PrintServiceTest.java | 3 +- .../test/util/UinCardGeneratorImplTest.java | 2 + 8 files changed, 738 insertions(+), 31 deletions(-) create mode 100644 src/main/java/io/mosip/print/service/UinCardGenerator.java create mode 100644 src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java create mode 100644 src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java create mode 100644 src/main/java/io/mosip/print/spi/PDFGenerator.java create mode 100644 src/main/java/io/mosip/print/util/TemplateGenerator.java diff --git a/src/main/java/io/mosip/print/service/UinCardGenerator.java b/src/main/java/io/mosip/print/service/UinCardGenerator.java new file mode 100644 index 00000000..32b38767 --- /dev/null +++ b/src/main/java/io/mosip/print/service/UinCardGenerator.java @@ -0,0 +1,30 @@ +package io.mosip.print.service; + +import io.mosip.print.constant.UinCardType; +import io.mosip.print.exception.ApisResourceAccessException; + +import java.io.InputStream; + +/** + * The Interface UinCardGenerator. + * + * @author M1048358 Alok + * + * @param + * the generic type + */ +public interface UinCardGenerator { + + /** + * Generate uin card. + * + * @param in + * the in + * @param type + * the type + * @param password + * the password + * @return the i + */ + public I generateUinCard(InputStream in, UinCardType type, String password) throws ApisResourceAccessException; +} diff --git a/src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java b/src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java new file mode 100644 index 00000000..2a07ff0c --- /dev/null +++ b/src/main/java/io/mosip/print/service/impl/PDFGeneratorImpl.java @@ -0,0 +1,310 @@ +package io.mosip.print.service.impl; + +import com.itextpdf.html2pdf.ConverterProperties; +import com.itextpdf.html2pdf.HtmlConverter; +import com.itextpdf.html2pdf.css.media.MediaDeviceDescription; +import com.itextpdf.html2pdf.css.media.MediaType; +import com.itextpdf.html2pdf.css.util.CssUtils; +import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider; +import com.itextpdf.io.image.ImageDataFactory; +import com.itextpdf.kernel.geom.PageSize; +import com.itextpdf.kernel.pdf.PdfDocument; +import com.itextpdf.kernel.pdf.PdfWriter; +import com.itextpdf.layout.Document; +import com.itextpdf.layout.element.Image; +import com.itextpdf.text.DocumentException; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.PdfCopy; +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.PdfSignatureAppearance; +import com.itextpdf.text.pdf.PdfStamper; +import com.itextpdf.text.pdf.security.*; +import com.itextpdf.text.pdf.security.MakeSignature.CryptoStandard; +import io.mosip.print.constant.PDFGeneratorExceptionCodeConstant; +import io.mosip.print.exception.PDFGeneratorException; +import io.mosip.print.logger.PrintLogger; +import io.mosip.print.model.CertificateEntry; +import io.mosip.print.spi.PDFGenerator; +import io.mosip.print.util.EmptyCheckUtils; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; + +/** + * The PdfGeneratorImpl is the class you will use most when converting processed + * Template to PDF. It contains a series of methods that accept processed + * Template as a {@link String}, {@link File}, or {@link InputStream}, and + * convert it to PDF in the form of an {@link OutputStream}, {@link File} + * + * @author Urvil Joshi + * @author Uday Kumar + * @author Neha + * + * @since 1.0.0 + * + */ +@Component +public class PDFGeneratorImpl implements PDFGenerator { + private static final Logger LOGGER = PrintLogger.getLogger(PDFGeneratorImpl.class); + + private static final String SHA256 = "SHA256"; + + private static final String OUTPUT_FILE_EXTENSION = ".pdf"; + + @Value("${mosip.kernel.pdf_owner_password}") + private String pdfOwnerPassword; + + /* + * (non-Javadoc) + * + * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.io. + * InputStream) + */ + @Override + public OutputStream generate(InputStream is) throws IOException { + isValidInputStream(is); + OutputStream os = new ByteArrayOutputStream(); + try { + HtmlConverter.convertToPdf(is, os); + } catch (Exception e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + e.getMessage()); + } + return os; + } + + /* + * (non-Javadoc) + * + * @see + * io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.lang.String) + */ + @Override + public OutputStream generate(String template) throws IOException { + OutputStream os = new ByteArrayOutputStream(); + try { + HtmlConverter.convertToPdf(template, os); + } catch (Exception e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorMessage(), e); + } + return os; + } + + /* + * (non-Javadoc) + * + * @see + * io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.lang.String, + * java.lang.String, java.lang.String) + */ + @Override + public void generate(String templatePath, String outpuFilePath, String outputFileName) throws IOException { + File outputFile = new File(outpuFilePath + outputFileName + OUTPUT_FILE_EXTENSION); + try { + HtmlConverter.convertToPdf(new File(templatePath), outputFile); + } catch (Exception e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorMessage(), e); + } + + } + + /* + * (non-Javadoc) + * + * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.io. + * InputStream, java.lang.String) + */ + @Override + public OutputStream generate(InputStream is, String resourceLoc) throws IOException { + isValidInputStream(is); + OutputStream os = new ByteArrayOutputStream(); + PdfWriter pdfWriter = new PdfWriter(os); + PdfDocument pdfDoc = new PdfDocument(pdfWriter); + ConverterProperties converterProperties = new ConverterProperties(); + pdfDoc.setTagged(); + PageSize pageSize = PageSize.A4.rotate(); + pdfDoc.setDefaultPageSize(pageSize); + float screenWidth = CssUtils.parseAbsoluteLength("" + pageSize.getWidth()); + MediaDeviceDescription mediaDescription = new MediaDeviceDescription(MediaType.SCREEN); + mediaDescription.setWidth(screenWidth); + DefaultFontProvider dfp = new DefaultFontProvider(true, true, false); + converterProperties.setMediaDeviceDescription(mediaDescription); + converterProperties.setFontProvider(dfp); + converterProperties.setBaseUri(resourceLoc); + converterProperties.setCreateAcroForm(true); + try { + HtmlConverter.convertToPdf(is, pdfDoc, converterProperties); + } catch (Exception e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + e.getMessage()); + } + return os; + } + + /* + * (non-Javadoc) + * + * @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#asPDF(java.util.List) + */ + @Override + public byte[] asPDF(List bufferedImages) throws IOException { + byte[] scannedPdfFile = null; + + try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { + + PdfWriter pdfWriter = new PdfWriter(byteArrayOutputStream); + Document document = new Document(new PdfDocument(pdfWriter)); + + for (BufferedImage bufferedImage : bufferedImages) { + Image image = new Image(ImageDataFactory.create(getImageBytesFromBufferedImage(bufferedImage))); + image.scaleToFit(600, 750); + document.add(image); + } + + document.close(); + pdfWriter.close(); + scannedPdfFile = byteArrayOutputStream.toByteArray(); + } catch (IOException e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + e.getMessage()); + } + return scannedPdfFile; + } + + private byte[] getImageBytesFromBufferedImage(BufferedImage bufferedImage) throws IOException { + byte[] imageInByte; + + ByteArrayOutputStream imagebyteArray = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, "jpg", imagebyteArray); + imagebyteArray.flush(); + imageInByte = imagebyteArray.toByteArray(); + imagebyteArray.close(); + + return imageInByte; + } + + /* + * (non-Javadoc) + * + * @see + * io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#mergePDF(java.util.List) + */ + @Override + public byte[] mergePDF(List pdfFiles) throws IOException { + try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { + com.itextpdf.text.Document document = new com.itextpdf.text.Document(); + PdfCopy pdfCopy = new PdfCopy(document, byteArrayOutputStream); + document.open(); + for (URL file : pdfFiles) { + PdfReader reader = new PdfReader(file); + pdfCopy.addDocument(reader); + pdfCopy.freeReader(reader); + reader.close(); + } + document.close(); + return byteArrayOutputStream.toByteArray(); + } catch (IOException | DocumentException e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + e.getMessage()); + } + } + + @Override + public OutputStream signAndEncryptPDF(byte[] pdf, io.mosip.print.model.Rectangle rectangle, + String reason, int pageNumber, Provider provider, + CertificateEntry certificateEntry, String password) + throws IOException, GeneralSecurityException { + OutputStream outputStream = new ByteArrayOutputStream(); + PdfReader pdfReader = null; + PdfStamper pdfStamper = null; + try { + pdfReader = new PdfReader(pdf); + pdfStamper = PdfStamper.createSignature(pdfReader, outputStream, '\0'); + + if (password != null && !password.trim().isEmpty()) { + pdfStamper.setEncryption(password.getBytes(), pdfOwnerPassword.getBytes(), + com.itextpdf.text.pdf.PdfWriter.ALLOW_PRINTING, + com.itextpdf.text.pdf.PdfWriter.ENCRYPTION_AES_256); + } + PdfSignatureAppearance signAppearance = pdfStamper.getSignatureAppearance(); + + signAppearance.setReason(reason); + // comment next line to have an invisible signature + signAppearance.setVisibleSignature( + new Rectangle(rectangle.getLlx(), rectangle.getLly(), rectangle.getUrx(), rectangle.getUry()), + pageNumber, null); + + OcspClient ocspClient = new OcspClientBouncyCastle(null); + TSAClient tsaClient = null; + for (X509Certificate certificate : certificateEntry.getChain()) { + String tsaUrl = CertificateUtil.getTSAURL(certificate); + if (tsaUrl != null) { + tsaClient = new TSAClientBouncyCastle(tsaUrl); + break; + } + signAppearance.setCertificate(certificate); + } + + List crlList = new ArrayList<>(); + crlList.add(new CrlClientOnline(certificateEntry.getChain())); + + ExternalSignature pks = new PrivateKeySignature(certificateEntry.getPrivateKey(), "SHA256", + provider.getName()); + ExternalDigest digest = new BouncyCastleDigest(); + + // Sign the document using the detached mode, CMS or CAdES equivalent. + MakeSignature.signDetached(signAppearance, digest, pks, certificateEntry.getChain(), crlList, ocspClient, + tsaClient, 0, CryptoStandard.CMS); + + pdfStamper.close(); + + } catch (DocumentException e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + e.getMessage(), e); + } finally { + outputStream.close(); + if (pdfStamper != null) { + closeQuietly(pdfStamper); + } + if (pdfReader != null) { + pdfReader.close(); + } + } + return outputStream; + } + + /* + + */ + + // Quietly close the pdfStamper. + private void closeQuietly(final PdfStamper pdfStamper) throws IOException { + try { + pdfStamper.close(); + } catch (DocumentException e) { + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + e.getMessage(), e); + } + } + + private void isValidInputStream(InputStream dataInputStream) { + if (EmptyCheckUtils.isNullEmpty(dataInputStream)) { + throw new PDFGeneratorException( + PDFGeneratorExceptionCodeConstant.INPUTSTREAM_NULL_EMPTY_EXCEPTION.getErrorCode(), + PDFGeneratorExceptionCodeConstant.INPUTSTREAM_NULL_EMPTY_EXCEPTION.getErrorMessage()); + } + } +} diff --git a/src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java b/src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java new file mode 100644 index 00000000..619e1195 --- /dev/null +++ b/src/main/java/io/mosip/print/service/impl/UinCardGeneratorImpl.java @@ -0,0 +1,137 @@ +package io.mosip.print.service.impl; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.print.constant.ApiName; +import io.mosip.print.constant.PDFGeneratorExceptionCodeConstant; +import io.mosip.print.constant.UinCardType; +import io.mosip.print.core.http.RequestWrapper; +import io.mosip.print.core.http.ResponseWrapper; +import io.mosip.print.dto.ErrorDTO; +import io.mosip.print.dto.PDFSignatureRequestDto; +import io.mosip.print.dto.SignatureResponseDto; +import io.mosip.print.exception.ApisResourceAccessException; +import io.mosip.print.exception.PDFGeneratorException; +import io.mosip.print.exception.PDFSignatureException; +import io.mosip.print.exception.PlatformErrorMessages; +import io.mosip.print.logger.PrintLogger; +import io.mosip.print.service.PrintRestClientService; +import io.mosip.print.service.UinCardGenerator; +import io.mosip.print.spi.PDFGenerator; +import io.mosip.print.util.DateUtils; +import io.mosip.print.util.RestApiClient; +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * The Class UinCardGeneratorImpl. + * + * @author M1048358 Alok + */ +@Component +public class UinCardGeneratorImpl implements UinCardGenerator { + + /** The pdf generator. */ + @Autowired + private PDFGenerator pdfGenerator; + + /** The print logger. */ + private Logger printLogger = PrintLogger.getLogger(UinCardGeneratorImpl.class); + + private static final String DATETIME_PATTERN = "mosip.print.datetime.pattern"; + + + @Value("${mosip.print.service.uincard.lowerleftx}") + private int lowerLeftX; + + @Value("${mosip.print.service.uincard.lowerlefty}") + private int lowerLeftY; + + @Value("${mosip.print.service.uincard.upperrightx}") + private int upperRightX; + + @Value("${mosip.print.service.uincard.upperrighty}") + private int upperRightY; + + @Value("${mosip.print.service.uincard.signature.reason}") + private String reason; + + + @Autowired + private PrintRestClientService restClientService; + + @Autowired + private Environment env; + + + ObjectMapper mapper = new ObjectMapper(); + + + @Autowired + private RestApiClient restApiClient; + + + @Override + public byte[] generateUinCard(InputStream in, UinCardType type, String password) + throws ApisResourceAccessException { + printLogger.debug("UinCardGeneratorImpl::generateUinCard()::entry"); + byte[] pdfSignatured=null; + ByteArrayOutputStream out = null; + try { + out = (ByteArrayOutputStream) pdfGenerator.generate(in); + PDFSignatureRequestDto request = new PDFSignatureRequestDto(lowerLeftX, lowerLeftY, upperRightX, + upperRightY, reason, 1, password); + request.setApplicationId("KERNEL"); + request.setReferenceId("SIGN"); + request.setData(Base64.encodeBase64String(out.toByteArray())); + DateTimeFormatter format = DateTimeFormatter.ofPattern(env.getProperty(DATETIME_PATTERN)); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString(env.getProperty(DATETIME_PATTERN)), format); + + request.setTimeStamp(DateUtils.getUTCCurrentDateTimeString()); + RequestWrapper requestWrapper = new RequestWrapper<>(); + + requestWrapper.setRequest(request); + requestWrapper.setRequesttime(localdatetime); + ResponseWrapper responseWrapper; + SignatureResponseDto signatureResponseDto; + + responseWrapper= (ResponseWrapper)restClientService.postApi(ApiName.PDFSIGN, null, null, + requestWrapper, ResponseWrapper.class,MediaType.APPLICATION_JSON); + + + if (responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) { + ErrorDTO error = responseWrapper.getErrors().get(0); + throw new PDFSignatureException(error.getMessage()); + } + signatureResponseDto = mapper.readValue(mapper.writeValueAsString(responseWrapper.getResponse()), + SignatureResponseDto.class); + + pdfSignatured = Base64.decodeBase64(signatureResponseDto.getData()); + + } catch (IOException | PDFGeneratorException e) { + printLogger.error( e.getMessage(),e); + throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), + PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorMessage() ,e); + } + catch (ApisResourceAccessException e) { + printLogger.error(PlatformErrorMessages.PRT_PRT_PDF_SIGNATURE_EXCEPTION.name() , e.getMessage() + ,e); + throw new PDFSignatureException(e); } + + printLogger.debug("UinCardGeneratorImpl::generateUinCard()::exit"); + + return pdfSignatured; + } + +} diff --git a/src/main/java/io/mosip/print/spi/PDFGenerator.java b/src/main/java/io/mosip/print/spi/PDFGenerator.java new file mode 100644 index 00000000..27b57d0e --- /dev/null +++ b/src/main/java/io/mosip/print/spi/PDFGenerator.java @@ -0,0 +1,108 @@ +package io.mosip.print.spi; + +import io.mosip.print.model.CertificateEntry; +import io.mosip.print.model.Rectangle; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.cert.X509Certificate; +import java.util.List; + +/** + * This interface is has specifications for PDF generation from different types. + * + * The user of this interface will have basic functionalities related to PDF. + * + * @author Urvil Joshi + * @author Uday Kumar + * @author Neha + * + * @since 1.0.0 + */ +public interface PDFGenerator { + /** + * Converts HTML obtained from an {@link InputStream} to a PDF written to an + * {@link OutputStream}. + * + * @param htmlStream the processedTemplate in the form of a {@link InputStream} + * @throws IOException Signals that an I/O exception has occurred. + * @return outpustStream PDF Output Stream (PDF stream) + */ + public OutputStream generate(InputStream htmlStream) throws IOException; + + /** + * This method will convert process Template as String to outpustStream + * + * @param template the processedTemplate in the form of a {@link String} + * @return OutputStream PDF Output Stream (PDF stream) + * @throws IOException Signals that an I/O exception has occurred. + */ + public OutputStream generate(String template) throws IOException; + + /** + * This method will take input as template file and convert template to PDF and + * save to the given path with given fileName. + * + * @param templatePath the processedTemplate in the form of a {@link String} + * @param outputFilePath Output File Path + * @param outputFileName Output File Name + * @throws IOException Signals that an I/O exception has occurred. + */ + public void generate(String templatePath, String outputFilePath, String outputFileName) throws IOException; + + /** + * This method will convert InputStream to OutputStream. + * + * @param dataStream the processedTemplate in the form of a + * {@link InputStream}. + * @param resourceLoc resourceLoction {@link String}. + * @throws IOException Signals that an I/O exception has occurred. + * @return outpustStream PDF Output Stream (PDF stream). + */ + public OutputStream generate(InputStream dataStream, String resourceLoc) throws IOException; + + /** + * This method will convert BufferedImage list to Byte Array. + * + * @param bufferedImages the input image to convert as PDF. + * @return array comprising PDF. + * @throws IOException Signals that an I/O exception has occurred. + */ + public byte[] asPDF(List bufferedImages) throws IOException; + + /** + * This method will merge all the PDF files. + * + * @param pdfLists the URL list of PDF files. + * @return the byte array comprising merged file. + * @throws IOException Signals that an I/O exception has occurred. + */ + public byte[] mergePDF(List pdfLists) throws IOException; + + /** + * Signs a PDF and protect it with password + * + * @param pdf byte array of pdf. + * @param rectangle {@link Rectangle} class to enclose signing + * @param reason reason of signing. + * @param pageNumber page number of rectangle. + * @param provider {@link Provider}. + * @param certificateEntry {@link CertificateEntry} class for certificate and + * private key as Input; + * @param password password for protecting pdf. + * @return {@link OutputStream} of signed PDF. + * @throws IOException Signals that an I/O exception has occurred. + * @throws GeneralSecurityException Signals general security exception while + * signing. + */ + OutputStream signAndEncryptPDF(byte[] pdf, Rectangle rectangle, String reason, int pageNumber, Provider provider, + CertificateEntry certificateEntry, String password) + throws IOException, GeneralSecurityException; + +} diff --git a/src/main/java/io/mosip/print/util/TemplateGenerator.java b/src/main/java/io/mosip/print/util/TemplateGenerator.java new file mode 100644 index 00000000..d7cd26c3 --- /dev/null +++ b/src/main/java/io/mosip/print/util/TemplateGenerator.java @@ -0,0 +1,138 @@ +package io.mosip.print.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.kernel.core.templatemanager.exception.TemplateMethodInvocationException; +import io.mosip.kernel.core.templatemanager.exception.TemplateParsingException; +import io.mosip.kernel.core.templatemanager.exception.TemplateResourceNotFoundException; +import io.mosip.print.constant.ApiName; +import io.mosip.print.constant.LoggerFileConstant; +import io.mosip.print.core.http.ResponseWrapper; +import io.mosip.print.dto.TemplateResponseDto; +import io.mosip.print.exception.ApisResourceAccessException; +import io.mosip.print.exception.PlatformErrorMessages; +import io.mosip.print.exception.TemplateProcessingFailureException; +import io.mosip.print.logger.PrintLogger; +import io.mosip.print.service.PrintRestClientService; +import io.mosip.print.service.impl.TemplateManagerImpl; +import io.mosip.print.spi.TemplateManager; +import org.apache.commons.lang.exception.ExceptionUtils; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.log.NullLogChute; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; +import org.apache.velocity.runtime.resource.loader.FileResourceLoader; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * The Class TemplateGenerator. + * + * @author M1048358 Alok + */ +@Component +public class TemplateGenerator { + + /** The reg proc logger. */ + private static Logger printLogger = PrintLogger.getLogger(TemplateGenerator.class); + + /** The resource loader. */ + private String resourceLoader = "classpath"; + + /** The template path. */ + private String templatePath = "."; + + /** The cache. */ + private boolean cache = Boolean.TRUE; + + /** The default encoding. */ + private String defaultEncoding = StandardCharsets.UTF_8.name(); + + /** The rest client service. */ + @Autowired + private PrintRestClientService restClientService; + + @Autowired + private ObjectMapper mapper; + + /** + * Gets the template. + * + * @param templateTypeCode + * the template type code + * @param attributes + * the attributes + * @param langCode + * the lang code + * @return the template + * @throws IOException + * Signals that an I/O exception has occurred. + * @throws ApisResourceAccessException + * the apis resource access exception + */ + public InputStream getTemplate(String templateTypeCode, Map attributes, String langCode) + throws IOException, ApisResourceAccessException { + + ResponseWrapper responseWrapper; + TemplateResponseDto template; + printLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "", + "TemplateGenerator::getTemplate()::entry"); + + try { + List pathSegments = new ArrayList<>(); + pathSegments.add(langCode); + pathSegments.add(templateTypeCode); + + responseWrapper = (ResponseWrapper) restClientService.getApi(ApiName.TEMPLATES, pathSegments, "", "", + ResponseWrapper.class); + template = mapper.readValue(mapper.writeValueAsString(responseWrapper.getResponse()), + TemplateResponseDto.class); + + InputStream fileTextStream = null; + if (template != null) { + InputStream stream = new ByteArrayInputStream( + template.getTemplates().iterator().next().getFileText().getBytes()); + fileTextStream = getTemplateManager().merge(stream, attributes); + } + printLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "", + "TemplateGenerator::getTemplate()::exit"); + return fileTextStream; + + } catch (TemplateResourceNotFoundException | TemplateParsingException | TemplateMethodInvocationException e) { + printLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + null, PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.name() + e.getMessage() + + ExceptionUtils.getStackTrace(e)); + throw new TemplateProcessingFailureException(PlatformErrorMessages.PRT_TEM_PROCESSING_FAILURE.getCode()); + } + } + + /** + * Gets the template manager. + * + * @return the template manager + */ + public TemplateManager getTemplateManager() { + final Properties properties = new Properties(); + properties.put(RuntimeConstants.INPUT_ENCODING, defaultEncoding); + properties.put(RuntimeConstants.OUTPUT_ENCODING, defaultEncoding); + properties.put(RuntimeConstants.ENCODING_DEFAULT, defaultEncoding); + properties.put(RuntimeConstants.RESOURCE_LOADER, resourceLoader); + properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath); + properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, cache); + properties.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName()); + properties.put("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + properties.put("file.resource.loader.class", FileResourceLoader.class.getName()); + VelocityEngine engine = new VelocityEngine(properties); + engine.init(); + return new TemplateManagerImpl(engine); + } +} diff --git a/src/main/resources/application-local1.properties b/src/main/resources/application-local1.properties index 23444a21..c5b20768 100644 --- a/src/main/resources/application-local1.properties +++ b/src/main/resources/application-local1.properties @@ -1,31 +1,12 @@ -mosip.event.hubURL=https://dev2.mosip.net/hub/ -mosip.partner.id=mpartner-default-print -mosip.datashare.partner.id=mpartner-default-resident -mosip.datashare.policy.id=mpolicy-default-resident -mosip.event.callBackUrl=https://4674-2409-4043-49d-d218-b7d1-c644-b1a2-a16b.ngrok.io/v1/print/print/callback/notifyPrint +mosip.event.hubURL=http://localhost:9191/websub/hub +mosip.partner.id=mpartner-msp-cardprint +mosip.event.callBackUrl=https://ac5a-2409-4072-191-6192-1c18-4dc9-87a2-8ff6.in.ngrok.io/v1/print/print/callback/notifyPrint mosip.event.topic=${mosip.partner.id}/CREDENTIAL_ISSUED csrf.disabled=true mosip.event.delay-millisecs=60000 print-websub-resubscription-delay-millisecs=1000000 mosip.event.secret=Kslk30SNF2AChs2 registration.processor.print.textfile=registration-processor-print-text-file.json -#-------------TOKEN GENERATION---------------- -#Token generation request id -token.request.id=io.mosip.registration.processor -#Token generation app id -token.request.appid=regproc -#Token generation username -token.request.username=registrationprocessor -#Token generation password -token.request.password=abc123 -#Token generation version -token.request.version=1.0 -#Token generation Client Id -token.request.clientId=mosip-regproc-client -#Token generation secret key -token.request.secretKey=abc123 -#Token generation issuer url -token.request.issuerUrl=http://keycloak/auth/realms/mosip #Audit Service AUDIT=https://dev2.mosip.net/v1/auditmanager/audits @@ -134,12 +115,12 @@ mosip.kernel.auth.appids.realm.map={prereg:'preregistration',ida:'mosip',registr #-----------------DATABASE Configuration --------------------------# mosip.database.ip=postgres-postgresql.postgres.svc.cluster.local mosip.database.port=5432 -hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect -hibernate.hbm2ddl.auto: none -hibernate.jdbc.lob.non_contextual_creation: true -hibernate.show_sql: false -javax.persistence.jdbc.driver: org.postgresql.Driver -javax.persistence.jdbc.password: password +hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect +hibernate.hbm2ddl.auto= none +hibernate.jdbc.lob.non_contextual_creation= true +hibernate.show_sql= false +javax.persistence.jdbc.driver= org.postgresql.Driver +javax.persistence.jdbc.password= password javax.persistence.jdbc.url=jdbc:postgresql://dev2.mosip.net:5432/mosip_print?useSSL=false -javax.persistence.jdbc.user: postgres -mosip.application.id=io.mosip.print +javax.persistence.jdbc.user= postgres +mosip.application.id=io.mosip.print \ No newline at end of file diff --git a/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java b/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java index c3c1d924..a60eeb13 100644 --- a/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java +++ b/src/test/java/io/mosip/print/test/service/impl/PrintServiceTest.java @@ -20,6 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner; import io.mosip.kernel.core.util.CryptoUtil; +import io.mosip.print.service.UinCardGenerator; import io.mosip.print.constant.QrVersion; import io.mosip.print.dto.IdResponseDTO1; import io.mosip.print.dto.ResponseDTO; @@ -32,7 +33,7 @@ import io.mosip.print.util.CryptoCoreUtil; import io.mosip.print.util.JsonUtil; import io.mosip.print.util.Utilities; - +import io.mosip.print.util.TemplateGenerator; @SpringBootTest(classes = TestBootApplication.class) @RunWith(SpringRunner.class) diff --git a/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java b/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java index 21e0662f..7099b8d3 100644 --- a/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java +++ b/src/test/java/io/mosip/print/test/util/UinCardGeneratorImplTest.java @@ -26,6 +26,8 @@ import org.springframework.test.util.ReflectionTestUtils; import io.mosip.print.constant.UinCardType; +import io.mosip.print.service.impl.UinCardGeneratorImpl; +import io.mosip.print.spi.PDFGenerator; import io.mosip.print.core.http.ResponseWrapper; import io.mosip.print.dto.ErrorDTO; import io.mosip.print.dto.SignatureResponseDto; From e1edc184c2823d6a27ce974681a2e4021afeae18 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Mon, 26 Jun 2023 10:09:19 +0530 Subject: [PATCH 06/12] Additional repo added for VC --- .github/workflows/manual_push_trigger.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manual_push_trigger.yml b/.github/workflows/manual_push_trigger.yml index 9ff18054..16bdbaea 100644 --- a/.github/workflows/manual_push_trigger.yml +++ b/.github/workflows/manual_push_trigger.yml @@ -1,4 +1,4 @@ -name: Cardprinter trigger for maven install +name: MSP Print-Service trigger for maven install on: workflow_dispatch @@ -43,7 +43,7 @@ jobs: ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml + run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false danubetech-maven-public https://repo.danubetech.com/repository/maven-public/ sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - name: Build with Maven From 53b17c946aaa72e4b87d3f5eb141f9194aa66367 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Mon, 11 Sep 2023 16:31:24 +0530 Subject: [PATCH 07/12] Certificate re-generated --- src/main/resources/partner.p12 | Bin 2572 -> 2692 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/main/resources/partner.p12 b/src/main/resources/partner.p12 index 64be780801f2ed968a65fc4d4df25e22dce8c4d0..877563512154c1c3fedd311350def8535bbf9ccb 100644 GIT binary patch literal 2692 zcmY+EXE+-Q7sr!GLWl}tG-ikzxz!kr6?*MawQ5zWMGolUXHyVR0N8^6dX2NFkUE$^V73e^n-w?e8l%D-cvbhW!2u5^%2nTtL`yS8&Sz zj&K|nj2x*;5g?m{YeMyv`yPb(6LKBw3qc@B1PCaKgF{*V`w;|#0B}N3m_wWa(1i&M zlmR1J&qoQc-SM1E(NN-}Ujb`^$>32#-7!THs@fMhG}dhnNC)F%ZgeATs>($xFKIo@ z+ie>@l6}bZ$3ia`+?M6H8cKsnvuaAcI8SS&cePOo{%%6m3I}(a-37F_I2CqQLY2^C zXaQOnRFm87Hs*d?|HEXdGYw#3SLZHjAyTV@_OP`Sc_o5#Yt6TsY>J57v0`6q-e!NO zbc3DDAw<+z%zbi8%9wA_hZg>Jr)=`n>bzE^EBFMX~HO%hSqxPEN`^ zY}!L}N?x_&>V(Fs!HqzurdE2i)S65W$3>r`02^F)U|X-0n3d&R50Ibf6bLXcH@INr1zH=BktW!~9Y zwPOgT$9Z5YPmC39-UJ|s4Q*zsE%ozU84&%!iE*XbRU+t{MJp^|lstKn)Q1+2&vPd> zi7h^w7V@V$n2L>DFR!)@*kp;3Gsz$i(CU;qmwl%SF`m*vz~Y>&o&ZYxI`eX_+aSw3 zn3&#!1DLXzQQhmgyxUSd-YB=?#U>6H)Tbz7sAfi3O&lb#Jg0V_Xqdq+UpadnVw{5-a;iHwnJlBopWjM?EX4B$(mHe;nH1Vt?JiE5=2ssMPwB3qa>5;k|d#$>} zM)Zvx)6d5dioIHDhipu%(eWU3$V30*`}`#n8c*71-!y~Zbe$Y6B}D~4< zVNL1x+Pfc?(#$M1#YJOi*US#DNCB?m^#86Q~1))F}j!%?1Oe0Q1hn3g9jWi zdF7#Dz`}*&+B{O&V(>eicWDnw=T}5bMph-?FW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SEGq>rrSi4o(XJI z`h5K@N)*C@1v*qH*=!Yrqg*iAPb@ik$KODdT=}^)AhY?x|$}4a7ub|oaKV5)->w+w};Llf8$p2dx5C$|tTlW6s z;}`Ho+3m`7&yV?PHB`j2YD;Izl4VYC$_)fP`am5d=__?Q6|g#5K#;yM#75hdu4AR( zy?VKA7aL!D5#l%??BzITe8Q^qpaeHi$C>K6#edt&hZw4H9e7k@ye{R%8xk>aNK?MV zq}-CdC@4S0y37ToX*+WyxykIW+i4_29k!%byvloxSQ~o$@|4A^Lbn3*VKobaZdxnC z6>#>Qeb153ru1gF+1)ig95g>FZK&n8gJNvP-)_*KJ~4w+UHDnX%i2?Ixmo1U?XFCX*tChwG$LX|zl zb}RAj5%+}~_m1#idS}1KKG*_s#Wm^G1vT*Uu?^4~xxsx;y3-SfLN^R9`JB|6}gN282+vF7XW zS0iUiLGk<|t-6V@iLpg{>fnvVzz{Qxcj8v*psgTes#kUCeNAP$Raxp87Bqhn>(U z`fXscXiv~NF)D2SsI2ne}Mer@$Msq>z>u8Z(36*!XSf#dqg?8c5oTJpmn zq<^ChPwU2Pkp*lnUC}*-$49$PP8hi4+v*}VnF-T4SJIH0l9$vqLQjySlq(JKxzSV-*FhByuGdXvX~>g&UTl(BzaQp||HX4yNQ@UWucwpem7qX9bPmTOu1> z{|MALn1Y4uASYd|m6b7im1k??dB>A;;QVs+kEgf!0an*$@>twPsn3^cOw z*hihbnlsy)f$myBck&R7mE-sA5YZOLi#E-&;jcdNsN)t-Q)Ea@0Tk>DiR^le$OSU( zsN9==!dS)o+&KGsT81qey)|oTZ8+b5b%d}q1XummHJk{b*Fv2p!&e6hgZU6gK!K<&Bc WM_qa~z6Q}`!o6oRk5H9=Bl;Hx0mgIy From e6e8c799b9bd9db88539673dae364e42aed027b5 Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Wed, 20 Sep 2023 10:55:36 +0530 Subject: [PATCH 08/12] Fullname attribute change. --- .../io/mosip/print/service/impl/PrintServiceImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index 9525e6c7..424a27dd 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -183,13 +183,14 @@ public boolean generateCard(EventModel eventModel) { obj.put("photo", photo); obj.put("qrCode", attributes.get(QRCODE)); String fullAddress = getFullAddress(attributes); + String fullName = getFullName(attributes); obj.put("address", (fullAddress.length() > 0) ? fullAddress : " "); obj.put("locality", ((attributes.get("locality") != null && !attributes.get("locality").equals("")) ? attributes.get("locality").toString() : " ")); obj.put("city", ((attributes.get("city") != null && !attributes.get("city").equals("")) ? attributes.get("city").toString() : " ")); obj.put("state", ((attributes.get("state") != null && !attributes.get("state").equals("")) ? attributes.get("state").toString() : " ")); obj.put("postalCode", ((attributes.get("postalCode") != null && !attributes.get("postalCode").equals("")) ? attributes.get("postalCode").toString() : " ")); obj.put("gender", ((attributes.get("gender") != null && !attributes.get("gender").equals("")) ? attributes.get("gender").toString() : " ")); - obj.put("fullName", ((attributes.get("fullName") != null && !attributes.get("fullName").equals("")) ? attributes.get("fullName").toString() : " ")); + obj.put("fullName", (fullName.length() > 0) ? fullName : " "); obj.put("dateOfBirth", ((attributes.get("dateOfBirth") != null && !attributes.get("dateOfBirth").equals("")) ? attributes.get("dateOfBirth").toString() : " ")); obj.put("phone", ((attributes.get("phone") != null && !attributes.get("phone").equals("")) ? attributes.get("phone").toString() : " ")); obj.put("vid", ((attributes.get("VID") != null && !attributes.get("VID").equals("")) ? attributes.get("VID").toString() : " ")); @@ -256,6 +257,14 @@ private String getFullAddress(Map attributes) { return StringUtils.arrayToCommaDelimitedString(fullAddress); } + private String getFullName(Map attributes) { + Object fullName[] = new Object[]{ attributes.get("firstName"), attributes.get("middleName"), attributes.get("lastName")}; + fullName = Arrays.stream(fullName) + .filter(s -> (s != null && !s.equals(""))) + .toArray(Object[]::new); + return fullName.toString(); + } + private String getSignature(String sign, String crdential) { String signHeader = sign.split("\\.")[0]; String signData = sign.split("\\.")[2]; From e1ac06e116b50fc6dbc13e99f51f1d51e768a37f Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Wed, 20 Sep 2023 11:18:58 +0530 Subject: [PATCH 09/12] Fullname attribute change. --- .../java/io/mosip/print/service/impl/PrintServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index 424a27dd..1d3c2ef2 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import javax.crypto.BadPaddingException; @@ -262,7 +263,7 @@ private String getFullName(Map attributes) { fullName = Arrays.stream(fullName) .filter(s -> (s != null && !s.equals(""))) .toArray(Object[]::new); - return fullName.toString(); + return ObjectUtils.nullSafeToString(fullName); } private String getSignature(String sign, String crdential) { From 408f58e984f5c20a445cab7a96021836fe428d8e Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Fri, 22 Sep 2023 09:10:14 +0530 Subject: [PATCH 10/12] Fullname attribute change. --- .../java/io/mosip/print/service/impl/PrintServiceImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index 1d3c2ef2..565a4d93 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -37,7 +37,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; -import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import javax.crypto.BadPaddingException; @@ -263,15 +262,15 @@ private String getFullName(Map attributes) { fullName = Arrays.stream(fullName) .filter(s -> (s != null && !s.equals(""))) .toArray(Object[]::new); - return ObjectUtils.nullSafeToString(fullName); + return StringUtils.arrayToDelimitedString(fullName, " "); } private String getSignature(String sign, String crdential) { String signHeader = sign.split("\\.")[0]; String signData = sign.split("\\.")[2]; - String signature = signHeader + "." + crdential + "." + signData; - return signature; + return signHeader + "." + crdential + "." + signData; } + private Map getDocuments(String credential, String credentialType, String encryptionPin, String requestId, String sign, String cardType, From ce49d7ef5d97f72e73d58b5759020e7cbe111abf Mon Sep 17 00:00:00 2001 From: Muralitharan K Date: Fri, 13 Sep 2024 12:30:12 +0530 Subject: [PATCH 11/12] certificate update due to expiry --- src/main/resources/partner.p12 | Bin 2692 -> 2692 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/main/resources/partner.p12 b/src/main/resources/partner.p12 index 877563512154c1c3fedd311350def8535bbf9ccb..ed4abc6f3f8313974a72021dfdfe5b8c483f61b3 100644 GIT binary patch delta 2479 zcmV;g2~hTg6@(R#b`;g?7AyqYU3tQ(?U(WezmepVNpO*hB!4hjBb$xG+vs2|@)WkHlr>C5Lf1U+1!;+sY~g# zJ~Q|#F=W)94C3DFbm9&mcY~!`M9Wx>(l0gz7A%yagRE#9%|AJrzPk|(3W{N9zNNz5 znL}OI-QoaZb^E%Y!VSh|qq7B(a2q4m04D{IV~LP?`+uN8W;>**0-J21x$epY<@dyy z!^nUR)=453!dKfVq-9B~-WS*xS>s6C0mgUay9FSB-F-s@E7Yji# ziak+h`|GICe+=bgUICDu&E}Ks?E*FWu}cf zHA!#mDd9CL5*}j{%^ZE#Cc1MKS7WKhTA^3PGJlk$wq$%#t>?6XhCZ2U)ZPGaz1Lx6 zB{z0qnn{P4-YF*rBJW_&7{i>zU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1q6=th<9TWIax+F-b%Aw`<~;=v>WA+hk7d#KcBKU04^ znvyXa9dzCRJc?#07jUn{XW%HFTcYuk$&-)MWiFx?R`}n7j)59c8>{XUwG4)FV9BzB zW^c@Fz4tvfJjlsmBjEJDF+(Ka?P~(*m!oBHd(Da5lf7!cj82Up;O087Djk*I&x7Hk z$o=1M`lX;y)@*DrHfJFMnY7HA)kk|%mk<_t!HDc{*f*1--CMpFz_XZOsGZA>q Date: Fri, 13 Sep 2024 12:39:19 +0530 Subject: [PATCH 12/12] VC verifier version changed --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 80db8d15..69f8637b 100644 --- a/pom.xml +++ b/pom.xml @@ -260,7 +260,7 @@ io.mosip.vercred vcverifier - 1.0-SNAPSHOT + 1.0.0