From 0d42ffcd3354898a32d0f90872231b058b91b78f Mon Sep 17 00:00:00 2001 From: Neha2365 <110969715+Neha2365@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:56:58 +0530 Subject: [PATCH] [MOSIP-31982] Enabling and disabling kafka bean (#1250) * MOSIP-32073 design document added (#1223) Signed-off-by: Neha Farheen Co-authored-by: Neha Farheen Signed-off-by: Neha Farheen * POM changes (#1225) Signed-off-by: Neha Farheen Co-authored-by: Neha Farheen Signed-off-by: Neha Farheen * updated the image path Signed-off-by: Neha Farheen * MOSIP-31982 changes done for image Signed-off-by: Neha Farheen * MOSIP-31982 changes done for image Signed-off-by: Neha Farheen * MOSIP-31982 added kafka config in otp application Signed-off-by: Neha Farheen * MOSIP-31982 added kafka config in otp application Signed-off-by: Neha Farheen * MOSIP-31982 Updated the pom and push trigger file Signed-off-by: Neha Farheen * test case issue is resolved Signed-off-by: Neha Farheen * test case issue is resolved with facedata Signed-off-by: Neha Farheen * test case issue is resolved with facedata Signed-off-by: Neha Farheen * kafka bean enable and disable Signed-off-by: Neha Farheen * kafka bean enable and disable Signed-off-by: Neha Farheen --------- Signed-off-by: Neha Farheen Co-authored-by: Neha Farheen --- .../service/config/KafkaProducerConfig.java | 3 +++ .../AuthenticationErrorEventingPublisher.java | 3 +++ .../constant/IdAuthConfigKeyConstants.java | 2 ++ .../otp/service/controller/OTPController.java | 10 ++++++---- .../service/controller/AuthController.java | 10 ++++++---- .../kyc/controller/KycAuthController.java | 20 ++++++++++--------- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/KafkaProducerConfig.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/KafkaProducerConfig.java index f4f45873d98..7612dc557d1 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/KafkaProducerConfig.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/KafkaProducerConfig.java @@ -6,12 +6,14 @@ import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.common.serialization.StringSerializer; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.kafka.core.DefaultKafkaProducerFactory; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.ProducerFactory; import org.springframework.kafka.support.serializer.JsonSerializer; +import static io.mosip.authentication.core.constant.IdAuthConfigKeyConstants.AUTHENTICATION_ERROR_EVENTING_ENABLED; /** * The Class KafkaProducerConfig. @@ -20,6 +22,7 @@ */ @Configuration +@ConditionalOnProperty(value = AUTHENTICATION_ERROR_EVENTING_ENABLED, havingValue = "true", matchIfMissing = false) public class KafkaProducerConfig { @Value(value = "${mosip.ida.kafka.bootstrap.servers}") diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/kafka/impl/AuthenticationErrorEventingPublisher.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/kafka/impl/AuthenticationErrorEventingPublisher.java index 14d589bdefc..52c7a422dc5 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/kafka/impl/AuthenticationErrorEventingPublisher.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/kafka/impl/AuthenticationErrorEventingPublisher.java @@ -1,6 +1,7 @@ package io.mosip.authentication.common.service.kafka.impl; import static io.mosip.authentication.core.constant.IdAuthConfigKeyConstants.AUTHENTICATION_ERROR_EVENTING_TOPIC; +import static io.mosip.authentication.core.constant.IdAuthConfigKeyConstants.AUTHENTICATION_ERROR_EVENTING_ENABLED; import java.util.HashMap; import java.util.Map; @@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.stereotype.Component; @@ -31,6 +33,7 @@ * @author Neha */ @Component +@ConditionalOnProperty(value = AUTHENTICATION_ERROR_EVENTING_ENABLED, havingValue = "true", matchIfMissing = false) public class AuthenticationErrorEventingPublisher { private static final String REQUEST_SIGNATURE = "requestSignature"; diff --git a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java index 4288e4ce7a0..d678bd80262 100644 --- a/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java +++ b/authentication/authentication-core/src/main/java/io/mosip/authentication/core/constant/IdAuthConfigKeyConstants.java @@ -173,4 +173,6 @@ private IdAuthConfigKeyConstants() { public static final String KYC_EXCHANGE_DEFAULT_LANGUAGE = "mosip.ida.kyc.exchange.default.lang"; public static final String IDP_AMR_ACR_IDA_MAPPING_SOURCE = "idp.amr-acr.ida.mapping.property.source"; + + public static final String AUTHENTICATION_ERROR_EVENTING_ENABLED = "mosip.ida.authentication.error.eventing.enabled"; } 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 c384a5f1764..1f3d09bbbfd 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 @@ -92,7 +92,7 @@ public class OTPController { @Autowired private IdAuthSecurityManager securityManager; - @Autowired + @Autowired(required = false) private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher; @InitBinder @@ -160,9 +160,11 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt throw authTransactionHelper.createDataValidationException(authTxnBuilder, e, requestWithMetadata); } catch (IdAuthenticationBusinessException e) { logger.error(IdAuthCommonConstants.SESSION_ID, e.getClass().toString(), e.getErrorCode(), e.getErrorText()); - if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - authenticationErrorEventingPublisher.notify(otpRequestDto, request.getHeader("signature"), partner, e, - otpRequestDto.getMetadata()); + if (authenticationErrorEventingPublisher != null) { + if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { + authenticationErrorEventingPublisher.notify(otpRequestDto, request.getHeader("signature"), + partner, e, otpRequestDto.getMetadata()); + } } 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 2bff768114b..a15be317a04 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 @@ -90,7 +90,7 @@ public class AuthController { @Autowired private PartnerService partnerService; - @Autowired + @Autowired(required = false) private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher; @@ -162,9 +162,11 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques } catch (IdAuthenticationBusinessException e) { mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "authenticateApplication", e.getErrorCode() + " : " + e.getErrorText()); - if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - authenticationErrorEventingPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e, - authrequestdto.getMetadata()); + if (authenticationErrorEventingPublisher != null) { + if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { + authenticationErrorEventingPublisher.notify(authrequestdto, request.getHeader("signature"), + partner, e, authrequestdto.getMetadata()); + } } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWithMetadata, 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 62ecfc537fb..2ea628bd92f 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 @@ -100,7 +100,7 @@ public class KycAuthController { @Autowired private KycExchangeRequestValidator kycExchangeValidator; - @Autowired + @Autowired(required = false) private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher; /** @@ -197,10 +197,11 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO } catch (IdAuthenticationBusinessException e) { mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "processEKyc", e.getErrorTexts().isEmpty() ? "" : e.getErrorText()); - - if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - authenticationErrorEventingPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), partner, - e, ekycAuthRequestDTO.getMetadata()); + if (authenticationErrorEventingPublisher != null) { + if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { + authenticationErrorEventingPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), + partner, e, ekycAuthRequestDTO.getMetadata()); + } } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.EKYC_REQUEST_RESPONSE, ekycAuthRequestDTO, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWrapperWithMetadata, e); @@ -279,10 +280,11 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD } catch (IdAuthenticationBusinessException e) { mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "processKycAuth", e.getErrorTexts().isEmpty() ? "" : e.getErrorText()); - - if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { - authenticationErrorEventingPublisher.notify(authRequestDTO, request.getHeader("signature"), partner, e, - authRequestDTO.getMetadata()); + if (authenticationErrorEventingPublisher != null) { + if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) { + authenticationErrorEventingPublisher.notify(authRequestDTO, request.getHeader("signature"), + partner, e, authRequestDTO.getMetadata()); + } } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.KYC_REQUEST_RESPONSE, authRequestDTO, e); IdaRequestResponsConsumerUtil.setIdVersionToObjectWithMetadata(requestWrapperWithMetadata, e);