From e101f5e8dbadc864ccf0ab4cdf70bb617c0b7c75 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Tue, 6 Feb 2024 15:24:29 +0530 Subject: [PATCH 1/2] MOSIP-30687 partner data changed Signed-off-by: Neha Farheen --- .../impl/OndemandTemplateEventPublisher.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java index 3bc49b4e2b9..1d2818747bf 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java @@ -11,7 +11,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import io.mosip.authentication.common.service.entity.PartnerData; import io.mosip.authentication.common.service.helper.WebSubHelper; +import io.mosip.authentication.common.service.repository.PartnerDataRepository; import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; import io.mosip.authentication.core.constant.IdAuthCommonConstants; import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; @@ -59,6 +61,9 @@ public class OndemandTemplateEventPublisher extends BaseWebSubEventsInitializer /** The on demand template extraction topic. */ @Value("${" + ON_DEMAND_TEMPLATE_EXTRACTION_TOPIC + "}") private String onDemadTemplateExtractionTopic; + + @Value("${mosip.ida.ondemand.template.extraction.partner.id}") + private String partnerId; /** The web sub event publish helper. */ @Autowired @@ -66,6 +71,9 @@ public class OndemandTemplateEventPublisher extends BaseWebSubEventsInitializer @Autowired private IdAuthSecurityManager securityManager; + + @Autowired + private PartnerDataRepository partnerDataRepo; /** * Do subscribe. @@ -114,13 +122,16 @@ public void notify(BaseRequestDTO baserequestdto, String headerSignature, Option private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, Optional partner, IdAuthenticationBusinessException e, Map metadata) { + logger.info("Inside partner data to get certificate for ondemand extraction encryption"); + Optional partnerDataCert = partnerDataRepo.findByPartnerId(partnerId); + logger.info("End process to get partner data certificate for ondemand extraction encryption"); logger.info("Inside sendEvents ondemand extraction"); Map eventData = new HashMap<>(); eventData.put(ERROR_CODE, e.getErrorCode()); eventData.put(ERROR_MESSAGE, e.getErrorText()); eventData.put(REQUESTDATETIME, DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime())); eventData.put(INDIVIDUAL_ID, encryptIndividualId(baserequestdto.getIndividualId(), - metadata.get(IdAuthCommonConstants.PARTNER_CERTIFICATE).toString())); + partnerDataCert.get().getCertificateData())); eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId()); eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType()); eventData.put(ENTITY_NAME, partner.get().getPartnerName()); @@ -146,6 +157,7 @@ private EventModel createEventModel(String topic, Map eventData) private byte[] encryptIndividualId(String id, String partnerCertificate) { try { + logger.info("Inside the method of encryptIndividualId using partner certificate "); return securityManager.asymmetricEncryption(id.getBytes(), partnerCertificate); } catch (IdAuthenticationBusinessException e) { // TODO Auto-generated catch block From 0838f41d1a70c8379240e55ac735b3fbf1425c25 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Tue, 6 Feb 2024 16:08:44 +0530 Subject: [PATCH 2/2] MOSIP-30687 partner data changed Signed-off-by: Neha Farheen --- .../impl/OndemandTemplateEventPublisher.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java index 1d2818747bf..3296187aafd 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java @@ -122,22 +122,25 @@ public void notify(BaseRequestDTO baserequestdto, String headerSignature, Option private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, Optional partner, IdAuthenticationBusinessException e, Map metadata) { + logger.info("Inside sendEvents ondemand extraction"); logger.info("Inside partner data to get certificate for ondemand extraction encryption"); Optional partnerDataCert = partnerDataRepo.findByPartnerId(partnerId); - logger.info("End process to get partner data certificate for ondemand extraction encryption"); - logger.info("Inside sendEvents ondemand extraction"); - Map eventData = new HashMap<>(); - eventData.put(ERROR_CODE, e.getErrorCode()); - eventData.put(ERROR_MESSAGE, e.getErrorText()); - eventData.put(REQUESTDATETIME, DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime())); - eventData.put(INDIVIDUAL_ID, encryptIndividualId(baserequestdto.getIndividualId(), - partnerDataCert.get().getCertificateData())); - eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId()); - eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType()); - eventData.put(ENTITY_NAME, partner.get().getPartnerName()); - eventData.put(REQUEST_SIGNATURE, headerSignature); - EventModel eventModel = createEventModel(onDemadTemplateExtractionTopic, eventData); - publishEvent(eventModel); + if (partnerDataCert.isEmpty()) { + logger.info("Partner is not configured for on demand extraction."); + } else { + Map eventData = new HashMap<>(); + eventData.put(ERROR_CODE, e.getErrorCode()); + eventData.put(ERROR_MESSAGE, e.getErrorText()); + eventData.put(REQUESTDATETIME, DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime())); + eventData.put(INDIVIDUAL_ID, + encryptIndividualId(baserequestdto.getIndividualId(), partnerDataCert.get().getCertificateData())); + eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId()); + eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType()); + eventData.put(ENTITY_NAME, partner.get().getPartnerName()); + eventData.put(REQUEST_SIGNATURE, headerSignature); + EventModel eventModel = createEventModel(onDemadTemplateExtractionTopic, eventData); + publishEvent(eventModel); + } } private EventModel createEventModel(String topic, Map eventData) {