From e101f5e8dbadc864ccf0ab4cdf70bb617c0b7c75 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Tue, 6 Feb 2024 15:24:29 +0530 Subject: [PATCH 01/18] 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 02/18] 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) { From 94f4f035e37f287ff9c0971d1de090aed821cfe7 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 7 Feb 2024 12:47:25 +0530 Subject: [PATCH 03/18] MOSIP-30687 changes done for ondemand Signed-off-by: Neha Farheen --- .../service/controller/AuthController.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index ea8f8e57f4d..4448597ac5a 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -165,12 +165,10 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); - throw new IdAuthenticationBusinessException( - IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorCode(), - String.format( - IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage(), - authrequestdto.getIndividualIdType()), - e); + e.addInfo(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorCode(), + String.format(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage(), + authrequestdto.getIndividualIdType())); + throw e; } From c123c3b8847c2d13bcd2b73f0264260dbb54ade7 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 7 Feb 2024 17:47:31 +0530 Subject: [PATCH 04/18] MOSIP-30687 changes done for exception Signed-off-by: Neha Farheen --- .../core/constant/IdAuthenticationErrorConstants.java | 4 +--- .../otp/service/controller/OTPController.java | 5 ----- .../service/controller/AuthController.java | 6 ------ .../service/kyc/controller/KycAuthController.java | 10 ---------- 4 files changed, 1 insertion(+), 24 deletions(-) diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java index 7985dd48e67..cf9127b331c 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java @@ -52,7 +52,7 @@ public enum IdAuthenticationErrorConstants { IDENTITYTYPE_NOT_ALLOWED("IDA-MLC-015", "Identity Type - %s not configured for the country"), INVALID_TXNID_BIO("IDA-MLC-016", "Transaction ID parameters in the request does not match"), INVALID_USERID( "IDA-MLC-017","Invalid UserID"), - ID_NOT_AVAILABLE("IDA-MLC-018", "%s not available in database"), + ID_NOT_AVAILABLE("IDA-MLC-018", "Unable to identify the entered %s. Please try after few minutes"), AUTH_TYPE_LOCKED("IDA-MLC-019", "%s Auth Type is Locked for the UIN"), FAILED_TO_ENCRYPT("IDA-MLC-020", "Unable to encrypt data"), FAILED_TO_FETCH_KEY("IDA-MLC-021", "Failed to fetch key from HSM"), @@ -66,8 +66,6 @@ public enum IdAuthenticationErrorConstants { INVALID_BIO_DIGITALID_TIMESTAMP("IDA-MLC-031", "DigitalId of Biometrics not captured within %s seconds of previous biometrics", "Please capture DigitalId of biometrics within %s seconds of previous biometric capture"), - UNABLE_TO_IDENTIFY_ID("IDA-MLC-032", "Unable to identify the entered %s. Please try after few minutes"), - DEMOGRAPHIC_DATA_MISMATCH_LANG("IDA-DEA-001", "Demographic data %s in %s did not match", "Please re-enter your %s in %s"), DEMO_DATA_MISMATCH("IDA-DEA-001", "Demographic data %s did not match", "Please re-enter your %s"), diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java index 6e3712eef9c..b0cb871ab94 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java @@ -162,11 +162,6 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(otpRequestDto, request.getHeader("signature"), partner, e, otpRequestDto.getMetadata()); - throw new IdAuthenticationBusinessException( - IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorCode(), - String.format(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage(), - otpRequestDto.getIndividualIdType()), - e); } auditHelper.audit(AuditModules.OTP_REQUEST, AuditEvents.OTP_TRIGGER_REQUEST_RESPONSE , otpRequestDto.getTransactionID(), IdType.getIDTypeOrDefault(otpRequestDto.getIndividualIdType()), e); diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 4448597ac5a..43445882a42 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -165,13 +165,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); - e.addInfo(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorCode(), - String.format(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage(), - authrequestdto.getIndividualIdType())); - throw e; - } - auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWithMetadata, e); e.putMetadata(IdAuthCommonConstants.TRANSACTION_ID, authrequestdto.getTransactionID()); diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java index a8ffe0862f0..624883cc882 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java @@ -201,11 +201,6 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), partner, e, ekycAuthRequestDTO.getMetadata()); - throw new IdAuthenticationBusinessException( - IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorCode(), - String.format(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage(), - ekycAuthRequestDTO.getIndividualIdType()), - e); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.EKYC_REQUEST_RESPONSE, ekycAuthRequestDTO, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWrapperWithMetadata, e); @@ -288,11 +283,6 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authRequestDTO, request.getHeader("signature"), partner, e, authRequestDTO.getMetadata()); - throw new IdAuthenticationBusinessException( - IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorCode(), - String.format(IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage(), - authRequestDTO.getIndividualIdType()), - e); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.KYC_REQUEST_RESPONSE, authRequestDTO, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWrapperWithMetadata, e); From 13a585028676b78d829e0dcfd179732118885bb8 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Thu, 8 Feb 2024 11:39:49 +0530 Subject: [PATCH 05/18] Changes in error message Signed-off-by: Neha Farheen --- .../core/constant/IdAuthenticationErrorConstants.java | 4 +++- .../authentication/service/controller/AuthController.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java index cf9127b331c..7985dd48e67 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthenticationErrorConstants.java @@ -52,7 +52,7 @@ public enum IdAuthenticationErrorConstants { IDENTITYTYPE_NOT_ALLOWED("IDA-MLC-015", "Identity Type - %s not configured for the country"), INVALID_TXNID_BIO("IDA-MLC-016", "Transaction ID parameters in the request does not match"), INVALID_USERID( "IDA-MLC-017","Invalid UserID"), - ID_NOT_AVAILABLE("IDA-MLC-018", "Unable to identify the entered %s. Please try after few minutes"), + ID_NOT_AVAILABLE("IDA-MLC-018", "%s not available in database"), AUTH_TYPE_LOCKED("IDA-MLC-019", "%s Auth Type is Locked for the UIN"), FAILED_TO_ENCRYPT("IDA-MLC-020", "Unable to encrypt data"), FAILED_TO_FETCH_KEY("IDA-MLC-021", "Failed to fetch key from HSM"), @@ -66,6 +66,8 @@ public enum IdAuthenticationErrorConstants { INVALID_BIO_DIGITALID_TIMESTAMP("IDA-MLC-031", "DigitalId of Biometrics not captured within %s seconds of previous biometrics", "Please capture DigitalId of biometrics within %s seconds of previous biometric capture"), + UNABLE_TO_IDENTIFY_ID("IDA-MLC-032", "Unable to identify the entered %s. Please try after few minutes"), + DEMOGRAPHIC_DATA_MISMATCH_LANG("IDA-DEA-001", "Demographic data %s in %s did not match", "Please re-enter your %s in %s"), DEMO_DATA_MISMATCH("IDA-DEA-001", "Demographic data %s did not match", "Please re-enter your %s"), diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 43445882a42..c142de6323a 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -165,6 +165,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); + e.getErrorTexts().add(0, IdAuthenticationErrorConstants.UNABLE_TO_IDENTIFY_ID.getErrorMessage()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWithMetadata, e); From 012fb36174065b0236df8519e483c0986f5008cf Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Thu, 8 Feb 2024 12:04:56 +0530 Subject: [PATCH 06/18] Changes in error message Signed-off-by: Neha Farheen --- .../mosip/authentication/service/controller/AuthController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 33175aa0e20..38ed5926fcc 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -165,7 +165,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); - e.getErrorTexts().add(0, IdAuthCommonConstants.UNABLE_TO_IDENTIFY_ID); + e.getErrorTexts().add(0, String.format(IdAuthCommonConstants.UNABLE_TO_IDENTIFY_ID, authrequestdto.getIndividualIdType())); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWithMetadata, e); From f01219a7237f4d5c0e5fe70b14823c94543255ab Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Thu, 8 Feb 2024 19:46:03 +0530 Subject: [PATCH 07/18] REmoved the error message related changes Signed-off-by: Neha Farheen --- .../mosip/authentication/service/controller/AuthController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 38ed5926fcc..43445882a42 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -165,7 +165,6 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); - e.getErrorTexts().add(0, String.format(IdAuthCommonConstants.UNABLE_TO_IDENTIFY_ID, authrequestdto.getIndividualIdType())); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWithMetadata, e); From 26cf182f912dbcd0426c72b36b4b81f60a868141 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Fri, 9 Feb 2024 11:52:06 +0530 Subject: [PATCH 08/18] MOSIP-31517 On demand changes error message removal Signed-off-by: Neha Farheen --- .../mosip/authentication/service/controller/AuthController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 38ed5926fcc..43445882a42 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -165,7 +165,6 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); - e.getErrorTexts().add(0, String.format(IdAuthCommonConstants.UNABLE_TO_IDENTIFY_ID, authrequestdto.getIndividualIdType())); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWithMetadata, e); From 21cda205faa0d2e11396467fcebaedf8480ef3b9 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Fri, 9 Feb 2024 12:58:45 +0530 Subject: [PATCH 09/18] Changes done Signed-off-by: Neha Farheen --- .../authentication/core/constant/IdAuthCommonConstants.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java index 6dce37e4764..96ec2319a51 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthCommonConstants.java @@ -468,8 +468,6 @@ public final class IdAuthCommonConstants { public static final String POLICY_DATA = "policy_data"; public static final String MISP_LIC_DATA = "misp_lic_data"; - - public static final String UNABLE_TO_IDENTIFY_ID = "Unable to identify the entered %s. Please try after few minutes"; private IdAuthCommonConstants() { } From 5cbcd9b9d74a760af0efeb29f554812436a418a6 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Fri, 9 Feb 2024 15:04:08 +0530 Subject: [PATCH 10/18] otp controller changes Signed-off-by: Neha Farheen --- .../authentication/otp/service/controller/OTPController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java index b0cb871ab94..847aca099f3 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java @@ -134,8 +134,9 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt Optional partner = partnerService.getPartner(partnerId, otpRequestDto.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper .createAndSetAuthTxnBuilderMetadataToRequest(otpRequestDto, !isPartnerReq, partner); - String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); + try { + String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); String idType = Objects.nonNull(otpRequestDto.getIndividualIdType()) ? otpRequestDto.getIndividualIdType() : idTypeUtil.getIdType(otpRequestDto.getIndividualId()).getType(); otpRequestDto.setIndividualIdType(idType); From f42e1c0036a49565084d76703db3cb99d9bb6620 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Fri, 9 Feb 2024 15:22:22 +0530 Subject: [PATCH 11/18] OTP repo changes Signed-off-by: Neha Farheen --- .../common/service/repository/OtpTxnRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OtpTxnRepository.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OtpTxnRepository.java index 49792bdbc94..390da32c83b 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OtpTxnRepository.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/repository/OtpTxnRepository.java @@ -14,11 +14,11 @@ public interface OtpTxnRepository extends BaseRepository { /** - * Find first element by ref_id ordered by generated_dtimes in descending order. + * Find first element by ref_id ordered by generated_dtimes in descending order and for the given status codes. * * @param refIdHash the ref id hash * @return the optional */ - Optional findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(String refIdHash, List statusCodes); + Optional findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(String refIdHash, List statusCodes); } From 0e35e62396c5b0e3cbd0d8417661f5b63d605780 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Fri, 9 Feb 2024 15:40:29 +0530 Subject: [PATCH 12/18] OTP repo changes Signed-off-by: Neha Farheen --- .../service/integration/OTPManager.java | 4 +- .../service/integration/OTPManagerTest.java | 52 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java index 3508889e87a..8da66c8f2cb 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java @@ -105,7 +105,7 @@ public boolean sendOtp(OtpRequestDTO otpRequestDTO, String idvid, String idvidTy throws IdAuthenticationBusinessException { String refIdHash = securityManager.hash(idvid); - Optional otpEntityOpt = otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(refIdHash, QUERIED_STATUS_CODES); + Optional otpEntityOpt = otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(refIdHash, QUERIED_STATUS_CODES); if(otpEntityOpt.isPresent()) { OtpTransaction otpEntity = otpEntityOpt.get(); @@ -210,7 +210,7 @@ private String generateOTP(String uin) throws IdAuthUncheckedException { */ public boolean validateOtp(String pinValue, String otpKey, String individualId) throws IdAuthenticationBusinessException { String refIdHash = securityManager.hash(individualId); - Optional otpEntityOpt = otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(refIdHash, QUERIED_STATUS_CODES); + Optional otpEntityOpt = otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(refIdHash, QUERIED_STATUS_CODES); if (otpEntityOpt.isEmpty()) { throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.OTP_REQUEST_REQUIRED); diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/integration/OTPManagerTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/integration/OTPManagerTest.java index 21272227a00..f679e354765 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/integration/OTPManagerTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/integration/OTPManagerTest.java @@ -168,7 +168,7 @@ public void sendOtpTest_frozen_within30mins() throws RestServiceException, IdAut OtpTransaction entity = new OtpTransaction(); entity.setStatusCode(IdAuthCommonConstants.FROZEN); entity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(30, ChronoUnit.MINUTES)); - when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); + when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); try { otpManager.sendOtp(otpRequestDTO, "426789089018", "UIN", valueMap, templateLanguages); } catch(IdAuthenticationBusinessException ex) { @@ -196,7 +196,7 @@ public void sendOtpTest_frozen_In31mins() throws RestServiceException, IdAuthent OtpTransaction entity = new OtpTransaction(); entity.setStatusCode(IdAuthCommonConstants.FROZEN); entity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(31, ChronoUnit.MINUTES)); - when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); + when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); try { when(otpRepo.save(Mockito.any())).thenAnswer(invocation -> { assertEquals(IdAuthCommonConstants.ACTIVE_STATUS, ((OtpTransaction)invocation.getArguments()[0]).getStatusCode()); @@ -228,7 +228,7 @@ public void sendOtpTest_USED_entry() throws RestServiceException, IdAuthenticati OtpTransaction entity = new OtpTransaction(); entity.setStatusCode(IdAuthCommonConstants.USED_STATUS); entity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(31, ChronoUnit.MINUTES)); - when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); + when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); try { when(otpRepo.save(Mockito.any())).thenAnswer(invocation -> { assertEquals(IdAuthCommonConstants.ACTIVE_STATUS, ((OtpTransaction)invocation.getArguments()[0]).getStatusCode()); @@ -260,7 +260,7 @@ public void sendOtpTest_frozen_within25mins() throws RestServiceException, IdAut OtpTransaction entity = new OtpTransaction(); entity.setStatusCode(IdAuthCommonConstants.FROZEN); entity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(25, ChronoUnit.MINUTES)); - when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); + when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(entity)); try { otpManager.sendOtp(otpRequestDTO, "426789089018", "UIN", valueMap, templateLanguages); } catch(IdAuthenticationBusinessException ex) { @@ -543,7 +543,7 @@ public void TestOtpAuthFailure() otpEntity.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); boolean expactedOTP = otpManager.validateOtp("Test123", "123456", "426789089018"); assertFalse(expactedOTP); @@ -765,7 +765,7 @@ public void TestInvalidAttemptWith_UsedEntity() otpEntity.setStatusCode(IdAuthCommonConstants.USED_STATUS); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -786,7 +786,7 @@ public void TestInvalidAttemptWith_nullUpdateCount() otpEntity.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { boolean result = otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -812,7 +812,7 @@ public void TestInvalidAttemptWith_1UpdateCount() otpEntity.setValidationRetryCount(1); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { boolean result = otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -838,7 +838,7 @@ public void TestInvalidAttemptWith_4UpdateCount() otpEntity.setValidationRetryCount(4); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { boolean result = otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -865,7 +865,7 @@ public void TestInvalidAttemptWith_FrozenStatus() otpEntity.setValidationRetryCount(5); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -893,7 +893,7 @@ public void TestInvalidAttemptWith_FrozenStatusWithin25Mins() otpEntity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(25, ChronoUnit.MINUTES)); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -921,7 +921,7 @@ public void TestInvalidAttemptWith_FrozenStatusWithin29Mins() otpEntity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(29, ChronoUnit.MINUTES)); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -949,7 +949,7 @@ public void TestInvalidAttemptWith_FrozenStatusWithin31Mins() otpEntity.setUpdDTimes(DateUtils.getUTCCurrentDateTime().minus(31, ChronoUnit.MINUTES)); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -975,7 +975,7 @@ public void TestValidAttemptWith_nullUpdateCount() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { boolean result = otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1001,7 +1001,7 @@ public void TestValidAttemptWith_1UpdateCount() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { boolean result = otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1027,7 +1027,7 @@ public void TestValidAttemptWith_4UpdateCount() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { boolean result = otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1054,7 +1054,7 @@ public void TestValidAttemptWith_FrozenStatus() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1083,7 +1083,7 @@ public void TestValidAttemptWith_FrozenStatusWithin25Mins() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1112,7 +1112,7 @@ public void TestValidAttemptWith_FrozenStatusWithin29Mins() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1141,7 +1141,7 @@ public void TestValidAttemptWith_FrozenStatusWithin31Mins() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().plus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1168,7 +1168,7 @@ public void TestValidAttemptWith_FrozenStatusWithin31Mins_expiredOtp() otpEntity.setOtpHash("313233343536234B45595F53504C49545445522354657374313233"); otpEntity.setExpiryDtimes(DateUtils.getUTCCurrentDateTime().minus(1, ChronoUnit.MINUTES)); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1201,7 +1201,7 @@ public void TestThrowOtpException_UINLocked() otpEntity.setOtpHash("otphash"); otpEntity.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1229,7 +1229,7 @@ public void TestThrowOtpException_OtpExpired() throws RestServiceException, IdAu otpEntity.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); @@ -1257,7 +1257,7 @@ public void TestThrowOtpException_ValidationUnsuccessful() otpEntity.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); otpEntity.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntity )); try { otpManager.validateOtp("Test123", "123456", "426789089018"); } catch (IdAuthenticationBusinessException ex) { @@ -1284,7 +1284,7 @@ public void TestThrowOtpException_OtpPresent_Expired() Mockito.when(securityManager.hash(Mockito.anyString())).thenReturn("hash"); otpEntry.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); otpEntry.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntry)); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntry)); try { otpManager.validateOtp("Test123", "123456", "426789089018"); } catch (IdAuthenticationBusinessException ex) { @@ -1311,7 +1311,7 @@ public void TestThrowOtpException_OtpPresent_NotExpired_Valid() Mockito.when(securityManager.hash(Mockito.anyString())).thenReturn("hash"); otpEntry.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); otpEntry.setOtpHash("otphash"); - Mockito.when(otpRepo.findFirstByRefIdInStatusCodesOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntry)); + Mockito.when(otpRepo.findFirstByRefIdAndStatusCodeInOrderByGeneratedDtimesDesc(Mockito.anyString(), Mockito.anyList())).thenReturn(Optional.of(otpEntry)); try { otpManager.validateOtp("Test123", "123456", "426789089018"); } catch (IdAuthenticationBusinessException ex) { From 1ca6f06af1e2fd7856f6701bd9c0cf4a8f969a0c Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Fri, 9 Feb 2024 19:14:38 +0530 Subject: [PATCH 13/18] OTP manager changes done Signed-off-by: Neha Farheen --- .../service/integration/OTPManager.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java index 8da66c8f2cb..6494dfd8538 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/integration/OTPManager.java @@ -118,26 +118,18 @@ public boolean sendOtp(OtpRequestDTO otpRequestDTO, String idvid, String idvidTy + EnvUtil.getKeySplitter() + otpRequestDTO.getTransactionID() + EnvUtil.getKeySplitter() + otp).getBytes()); - OtpTransaction otpTxn; - if (otpEntityOpt.isPresent() - && (otpTxn = otpEntityOpt.get()).getStatusCode().equals(IdAuthCommonConstants.ACTIVE_STATUS)) { - otpTxn.setOtpHash(otpHash); - otpTxn.setUpdBy(securityManager.getUser()); - otpTxn.setUpdDTimes(otpGenerationTime); - otpTxn.setExpiryDtimes(otpGenerationTime.plusSeconds(EnvUtil.getOtpExpiryTime())); - otpRepo.save(otpTxn); - } else { - OtpTransaction txn = new OtpTransaction(); - txn.setId(UUID.randomUUID().toString()); - txn.setRefId(securityManager.hash(otpRequestDTO.getIndividualId())); - txn.setOtpHash(otpHash); - txn.setCrBy(securityManager.getUser()); - txn.setCrDtimes(otpGenerationTime); - txn.setExpiryDtimes(otpGenerationTime.plusSeconds( - EnvUtil.getOtpExpiryTime())); - txn.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); - otpRepo.save(txn); - } + OtpTransaction txn = new OtpTransaction(); + txn.setId(UUID.randomUUID().toString()); + txn.setRefId(securityManager.hash(otpRequestDTO.getIndividualId())); + txn.setOtpHash(otpHash); + txn.setCrBy(securityManager.getUser()); + txn.setGeneratedDtimes(otpGenerationTime); + txn.setCrDtimes(otpGenerationTime); + txn.setExpiryDtimes(otpGenerationTime.plusSeconds( + EnvUtil.getOtpExpiryTime())); + txn.setStatusCode(IdAuthCommonConstants.ACTIVE_STATUS); + otpRepo.save(txn); + String notificationProperty = null; notificationProperty = otpRequestDTO .getOtpChannel().stream().map(channel -> NotificationType.getNotificationTypeForChannel(channel) From c0c77780e285bcc2d552ccb1da37f5fa22f3c713 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Mon, 19 Feb 2024 13:37:00 +0530 Subject: [PATCH 14/18] encoded the encrypted data Signed-off-by: Neha Farheen --- .../service/transaction/manager/IdAuthSecurityManager.java | 4 ++-- .../service/websub/impl/OndemandTemplateEventPublisher.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java index 776de14e12e..9680725cac6 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java @@ -513,12 +513,12 @@ public Tuple3 encryptData(byte[] data, String partnerCer return Tuples.of(CryptoUtil.encodeBase64Url(encryptedData.getT1()), CryptoUtil.encodeBase64Url(encryptedData.getT2()), digestAsPlainText(certificateThumbprint)); } - public byte[] asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate) + public String asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate) throws IdAuthenticationBusinessException { X509Certificate x509Certificate = getX509Certificate(partnerCertificate); PublicKey publicKey = x509Certificate.getPublicKey(); byte[] encryptedData = cryptoCore.asymmetricEncrypt(publicKey, dataToEncrypt); - return encryptedData; + return CryptoUtil.encodeBase64Url(encryptedData); } /** 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 3296187aafd..2288db5bc69 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 @@ -158,7 +158,7 @@ private EventModel createEventModel(String topic, Map eventData) return model; } - private byte[] encryptIndividualId(String id, String partnerCertificate) { + private String encryptIndividualId(String id, String partnerCertificate) { try { logger.info("Inside the method of encryptIndividualId using partner certificate "); return securityManager.asymmetricEncryption(id.getBytes(), partnerCertificate); From 257e70874d73871fc7342cccb70cc4f2e3bd10fc Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Mon, 19 Feb 2024 18:24:38 +0530 Subject: [PATCH 15/18] ondemand changes Signed-off-by: Neha Farheen --- .../transaction/manager/IdAuthSecurityManager.java | 1 + .../websub/impl/OndemandTemplateEventPublisher.java | 9 +++++---- .../otp/service/controller/OTPController.java | 5 +++-- .../service/controller/AuthController.java | 6 +++--- .../service/kyc/controller/KycAuthController.java | 12 ++++++------ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java index fa012ed20c1..d08ca2d36fc 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java @@ -518,6 +518,7 @@ public String asymmetricEncryption(byte[] dataToEncrypt, String partnerCertifica X509Certificate x509Certificate = getX509Certificate(partnerCertificate); PublicKey publicKey = x509Certificate.getPublicKey(); byte[] encryptedData = cryptoCore.asymmetricEncrypt(publicKey, dataToEncrypt); + mosipLogger.info("AssymetricEncrypted data -- Start" + encryptedData+ " End--AssymetricEncrypted data" ); return CryptoUtil.encodeBase64Url(encryptedData); } 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 2288db5bc69..7888c15c406 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 @@ -17,6 +17,7 @@ import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; import io.mosip.authentication.core.constant.IdAuthCommonConstants; import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.indauth.dto.BaseAuthResponseDTO; import io.mosip.authentication.core.indauth.dto.BaseRequestDTO; import io.mosip.authentication.core.logger.IdaLogger; import io.mosip.authentication.core.partner.dto.PartnerDTO; @@ -110,17 +111,17 @@ public void publishEvent(EventModel eventModel) { webSubHelper.publishEvent(onDemadTemplateExtractionTopic, eventModel); } - public void notify(BaseRequestDTO baserequestdto, String headerSignature, Optional partner, + public void notify(BaseRequestDTO baserequestdto, String apiresponsedate, String headerSignature, Optional partner, IdAuthenticationBusinessException e, Map metadata) { try { - sendEvents(baserequestdto, headerSignature, partner, e, metadata); + sendEvents(baserequestdto,apiresponsedate, headerSignature, partner, e, metadata); } catch (Exception exception) { logger.error(IdRepoSecurityManager.getUser(), "On demand template extraction", "notify", exception.getMessage()); } } - private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, Optional partner, + private void sendEvents(BaseRequestDTO baserequestdto, String apiresponsedate, 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"); @@ -131,7 +132,7 @@ private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, O 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(REQUESTDATETIME, apiresponsedate); eventData.put(INDIVIDUAL_ID, encryptIndividualId(baserequestdto.getIndividualId(), partnerDataCert.get().getCertificateData())); eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId()); diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java index 847aca099f3..d445bb5fa5c 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java @@ -130,6 +130,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt if(request instanceof ObjectWithMetadata) { ObjectWithMetadata requestWithMetadata = (ObjectWithMetadata) request; + OtpResponseDTO otpResponseDTO=null; boolean isPartnerReq = true; Optional partner = partnerService.getPartner(partnerId, otpRequestDto.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper @@ -142,7 +143,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt otpRequestDto.setIndividualIdType(idType); otpRequestValidator.validateIdvId(otpRequestDto.getIndividualId(), idType, errors, IdAuthCommonConstants.IDV_ID); DataValidationUtil.validate(errors); - OtpResponseDTO otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata); + otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata); logger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), GENERATE_OTP, otpResponseDTO.getResponseTime()); @@ -161,7 +162,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt } catch (IdAuthenticationBusinessException e) { logger.error(IdAuthCommonConstants.SESSION_ID, e.getClass().toString(), e.getErrorCode(), e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(otpRequestDto, request.getHeader("signature"), partner, e, + ondemandTemplateEventPublisher.notify(otpRequestDto, otpResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e, otpRequestDto.getMetadata()); } auditHelper.audit(AuditModules.OTP_REQUEST, AuditEvents.OTP_TRIGGER_REQUEST_RESPONSE , otpRequestDto.getTransactionID(), diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 43445882a42..765e2bc4d7e 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -131,7 +131,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if(request instanceof ObjectWithMetadata) { ObjectWithMetadata requestWithMetadata = (ObjectWithMetadata) request; - + AuthResponseDTO authResponsedto = null; boolean isAuth = true; Optional partner = partnerService.getPartner(partnerId, authrequestdto.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper @@ -146,7 +146,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques authRequestValidator.validateDeviceDetails(authrequestdto, errors); } DataValidationUtil.validate(errors); - AuthResponseDTO authResponsedto = authFacade.authenticateIndividual(authrequestdto, true, partnerId, + authResponsedto = authFacade.authenticateIndividual(authrequestdto, true, partnerId, partnerApiKey, IdAuthCommonConstants.CONSUME_VID_DEFAULT, requestWithMetadata); // Note: Auditing of success or failure status of each authentication (but not // the exception) is handled in respective authentication invocations in the facade @@ -163,7 +163,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "authenticateApplication", e.getErrorCode() + " : " + e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, + ondemandTemplateEventPublisher.notify(authrequestdto, authResponsedto.getResponseTime(), request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java index 624883cc882..4cd342165af 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java @@ -159,7 +159,8 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO throws IdAuthenticationBusinessException, IdAuthenticationAppException, IdAuthenticationDaoException { if(request instanceof ObjectWithMetadata) { ObjectWithMetadata requestWrapperWithMetadata = (ObjectWithMetadata) request; - + + AuthResponseDTO authResponseDTO= null; boolean isAuth = true; Optional partner = partnerService.getPartner(partnerId, ekycAuthRequestDTO.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper @@ -175,7 +176,7 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO } DataValidationUtil.validate(errors); boolean externalAuthRequest = true; - AuthResponseDTO authResponseDTO = kycFacade.authenticateIndividual(ekycAuthRequestDTO, externalAuthRequest, + authResponseDTO = kycFacade.authenticateIndividual(ekycAuthRequestDTO, externalAuthRequest, partnerId, partnerApiKey, requestWrapperWithMetadata); EKycAuthResponseDTO kycAuthResponseDTO = new EKycAuthResponseDTO(); Map metadata = requestWrapperWithMetadata.getMetadata(); @@ -199,7 +200,7 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO e.getErrorTexts().isEmpty() ? "" : e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), partner, + ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO,authResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e, ekycAuthRequestDTO.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.EKYC_REQUEST_RESPONSE, ekycAuthRequestDTO, e); @@ -246,7 +247,7 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD Optional partner = partnerService.getPartner(partnerId, authRequestDTO.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper .createAndSetAuthTxnBuilderMetadataToRequest(authRequestDTO, !isAuth, partner); - + KycAuthResponseDTO kycAuthResponseDTO = new KycAuthResponseDTO(); try { String idType = Objects.nonNull(authRequestDTO.getIndividualIdType()) ? authRequestDTO.getIndividualIdType() : idTypeUtil.getIdType(authRequestDTO.getIndividualId()).getType(); @@ -259,7 +260,6 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD boolean externalAuthRequest = true; AuthResponseDTO authResponseDTO = kycFacade.authenticateIndividual(authRequestDTO, externalAuthRequest, partnerId, oidcClientId, requestWrapperWithMetadata, IdAuthCommonConstants.KYC_AUTH_CONSUME_VID_DEFAULT); - KycAuthResponseDTO kycAuthResponseDTO = new KycAuthResponseDTO(); Map metadata = requestWrapperWithMetadata.getMetadata(); if (authResponseDTO != null && metadata != null && @@ -281,7 +281,7 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD e.getErrorTexts().isEmpty() ? "" : e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(authRequestDTO, request.getHeader("signature"), partner, e, + ondemandTemplateEventPublisher.notify(authRequestDTO, kycAuthResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e, authRequestDTO.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.KYC_REQUEST_RESPONSE, authRequestDTO, e); From 65a24017a352d03e40c900a922b157d3adf2abe2 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 21 Feb 2024 10:54:04 +0530 Subject: [PATCH 16/18] changes in encoding Signed-off-by: Neha Farheen --- .../service/transaction/manager/IdAuthSecurityManager.java | 2 +- .../authentication/otp/service/controller/OTPController.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java index d08ca2d36fc..596b1cea56a 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/transaction/manager/IdAuthSecurityManager.java @@ -519,7 +519,7 @@ public String asymmetricEncryption(byte[] dataToEncrypt, String partnerCertifica PublicKey publicKey = x509Certificate.getPublicKey(); byte[] encryptedData = cryptoCore.asymmetricEncrypt(publicKey, dataToEncrypt); mosipLogger.info("AssymetricEncrypted data -- Start" + encryptedData+ " End--AssymetricEncrypted data" ); - return CryptoUtil.encodeBase64Url(encryptedData); + return CryptoUtil.encodeBase64(encryptedData); } /** diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java index d445bb5fa5c..a294ea93880 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java @@ -140,6 +140,8 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); String idType = Objects.nonNull(otpRequestDto.getIndividualIdType()) ? otpRequestDto.getIndividualIdType() : idTypeUtil.getIdType(otpRequestDto.getIndividualId()).getType(); + logger.debug(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), GENERATE_OTP, + idType); otpRequestDto.setIndividualIdType(idType); otpRequestValidator.validateIdvId(otpRequestDto.getIndividualId(), idType, errors, IdAuthCommonConstants.IDV_ID); DataValidationUtil.validate(errors); From 7ee8a79a2c5b4ab68524ed76a37d18a23dc182aa Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 21 Feb 2024 11:02:13 +0530 Subject: [PATCH 17/18] logger changes Signed-off-by: Neha Farheen --- .../authentication/otp/service/controller/OTPController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java index a294ea93880..b3a9e75af09 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java @@ -141,7 +141,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt String idType = Objects.nonNull(otpRequestDto.getIndividualIdType()) ? otpRequestDto.getIndividualIdType() : idTypeUtil.getIdType(otpRequestDto.getIndividualId()).getType(); logger.debug(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), GENERATE_OTP, - idType); + "IdType...."+ idType); otpRequestDto.setIndividualIdType(idType); otpRequestValidator.validateIdvId(otpRequestDto.getIndividualId(), idType, errors, IdAuthCommonConstants.IDV_ID); DataValidationUtil.validate(errors); From 8eb03fe64430189c8251e1db2335dfd22b13be40 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 21 Feb 2024 12:50:42 +0530 Subject: [PATCH 18/18] Reverted response time changes Signed-off-by: Neha Farheen --- .../websub/impl/OndemandTemplateEventPublisher.java | 8 ++++---- .../otp/service/controller/OTPController.java | 7 +++---- .../service/controller/AuthController.java | 6 +++--- .../service/kyc/controller/KycAuthController.java | 9 ++++----- 4 files changed, 14 insertions(+), 16 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 7888c15c406..29dd07cd52a 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 @@ -111,17 +111,17 @@ public void publishEvent(EventModel eventModel) { webSubHelper.publishEvent(onDemadTemplateExtractionTopic, eventModel); } - public void notify(BaseRequestDTO baserequestdto, String apiresponsedate, String headerSignature, Optional partner, + public void notify(BaseRequestDTO baserequestdto, String headerSignature, Optional partner, IdAuthenticationBusinessException e, Map metadata) { try { - sendEvents(baserequestdto,apiresponsedate, headerSignature, partner, e, metadata); + sendEvents(baserequestdto, headerSignature, partner, e, metadata); } catch (Exception exception) { logger.error(IdRepoSecurityManager.getUser(), "On demand template extraction", "notify", exception.getMessage()); } } - private void sendEvents(BaseRequestDTO baserequestdto, String apiresponsedate, String headerSignature, Optional partner, + 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"); @@ -132,7 +132,7 @@ private void sendEvents(BaseRequestDTO baserequestdto, String apiresponsedate, S Map eventData = new HashMap<>(); eventData.put(ERROR_CODE, e.getErrorCode()); eventData.put(ERROR_MESSAGE, e.getErrorText()); - eventData.put(REQUESTDATETIME, apiresponsedate); + 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()); diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java index b3a9e75af09..f9baef81853 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller/OTPController.java @@ -130,22 +130,21 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt if(request instanceof ObjectWithMetadata) { ObjectWithMetadata requestWithMetadata = (ObjectWithMetadata) request; - OtpResponseDTO otpResponseDTO=null; boolean isPartnerReq = true; Optional partner = partnerService.getPartner(partnerId, otpRequestDto.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper .createAndSetAuthTxnBuilderMetadataToRequest(otpRequestDto, !isPartnerReq, partner); try { - String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); String idType = Objects.nonNull(otpRequestDto.getIndividualIdType()) ? otpRequestDto.getIndividualIdType() : idTypeUtil.getIdType(otpRequestDto.getIndividualId()).getType(); logger.debug(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), GENERATE_OTP, "IdType...."+ idType); otpRequestDto.setIndividualIdType(idType); + String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); otpRequestValidator.validateIdvId(otpRequestDto.getIndividualId(), idType, errors, IdAuthCommonConstants.IDV_ID); DataValidationUtil.validate(errors); - otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata); + OtpResponseDTO otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata); logger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), GENERATE_OTP, otpResponseDTO.getResponseTime()); @@ -164,7 +163,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt } catch (IdAuthenticationBusinessException e) { logger.error(IdAuthCommonConstants.SESSION_ID, e.getClass().toString(), e.getErrorCode(), e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(otpRequestDto, otpResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e, + ondemandTemplateEventPublisher.notify(otpRequestDto, request.getHeader("signature"), partner, e, otpRequestDto.getMetadata()); } auditHelper.audit(AuditModules.OTP_REQUEST, AuditEvents.OTP_TRIGGER_REQUEST_RESPONSE , otpRequestDto.getTransactionID(), diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java index 765e2bc4d7e..a653e0917b0 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller/AuthController.java @@ -131,7 +131,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques if(request instanceof ObjectWithMetadata) { ObjectWithMetadata requestWithMetadata = (ObjectWithMetadata) request; - AuthResponseDTO authResponsedto = null; + boolean isAuth = true; Optional partner = partnerService.getPartner(partnerId, authrequestdto.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper @@ -146,7 +146,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques authRequestValidator.validateDeviceDetails(authrequestdto, errors); } DataValidationUtil.validate(errors); - authResponsedto = authFacade.authenticateIndividual(authrequestdto, true, partnerId, + AuthResponseDTO authResponsedto = authFacade.authenticateIndividual(authrequestdto, true, partnerId, partnerApiKey, IdAuthCommonConstants.CONSUME_VID_DEFAULT, requestWithMetadata); // Note: Auditing of success or failure status of each authentication (but not // the exception) is handled in respective authentication invocations in the facade @@ -163,7 +163,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "authenticateApplication", e.getErrorCode() + " : " + e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(authrequestdto, authResponsedto.getResponseTime(), request.getHeader("signature"), partner, e, + ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, authrequestdto.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java index 4cd342165af..eada0439155 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/controller/KycAuthController.java @@ -160,7 +160,6 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO if(request instanceof ObjectWithMetadata) { ObjectWithMetadata requestWrapperWithMetadata = (ObjectWithMetadata) request; - AuthResponseDTO authResponseDTO= null; boolean isAuth = true; Optional partner = partnerService.getPartner(partnerId, ekycAuthRequestDTO.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper @@ -176,7 +175,7 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO } DataValidationUtil.validate(errors); boolean externalAuthRequest = true; - authResponseDTO = kycFacade.authenticateIndividual(ekycAuthRequestDTO, externalAuthRequest, + AuthResponseDTO authResponseDTO = kycFacade.authenticateIndividual(ekycAuthRequestDTO, externalAuthRequest, partnerId, partnerApiKey, requestWrapperWithMetadata); EKycAuthResponseDTO kycAuthResponseDTO = new EKycAuthResponseDTO(); Map metadata = requestWrapperWithMetadata.getMetadata(); @@ -200,7 +199,7 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO e.getErrorTexts().isEmpty() ? "" : e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO,authResponseDTO.getResponseTime(), request.getHeader("signature"), partner, + ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), partner, e, ekycAuthRequestDTO.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.EKYC_REQUEST_RESPONSE, ekycAuthRequestDTO, e); @@ -247,7 +246,6 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD Optional partner = partnerService.getPartner(partnerId, authRequestDTO.getMetadata()); AuthTransactionBuilder authTxnBuilder = authTransactionHelper .createAndSetAuthTxnBuilderMetadataToRequest(authRequestDTO, !isAuth, partner); - KycAuthResponseDTO kycAuthResponseDTO = new KycAuthResponseDTO(); try { String idType = Objects.nonNull(authRequestDTO.getIndividualIdType()) ? authRequestDTO.getIndividualIdType() : idTypeUtil.getIdType(authRequestDTO.getIndividualId()).getType(); @@ -260,6 +258,7 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD boolean externalAuthRequest = true; AuthResponseDTO authResponseDTO = kycFacade.authenticateIndividual(authRequestDTO, externalAuthRequest, partnerId, oidcClientId, requestWrapperWithMetadata, IdAuthCommonConstants.KYC_AUTH_CONSUME_VID_DEFAULT); + KycAuthResponseDTO kycAuthResponseDTO = new KycAuthResponseDTO(); Map metadata = requestWrapperWithMetadata.getMetadata(); if (authResponseDTO != null && metadata != null && @@ -281,7 +280,7 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD e.getErrorTexts().isEmpty() ? "" : e.getErrorText()); if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - ondemandTemplateEventPublisher.notify(authRequestDTO, kycAuthResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e, + ondemandTemplateEventPublisher.notify(authRequestDTO, request.getHeader("signature"), partner, e, authRequestDTO.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.KYC_REQUEST_RESPONSE, authRequestDTO, e);