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 3bc8d047a66..bdb5fe50466 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 @@ -88,6 +88,7 @@ public class OTPManager { /** The logger. */ private static Logger logger = IdaLogger.getLogger(OTPManager.class); + /** * Generate OTP with information of {@link MediaType } and OTP generation * time-out. 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 599d93bcef5..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 @@ -513,12 +513,13 @@ 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; + 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 3296187aafd..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()); @@ -158,7 +159,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); 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);