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 e3859443036..b04703f0ea8 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 @@ -7,6 +7,7 @@ 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; @@ -15,6 +16,7 @@ import org.springframework.kafka.support.serializer.JsonSerializer; @Configuration +@ConditionalOnProperty(value = "mosip.ida.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 016bd682c15..3d308763828 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 @@ -9,6 +9,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 +32,7 @@ * @author Neha */ @Component +@ConditionalOnProperty(value = "mosip.ida.authentication.error.eventing.enabled", havingValue = "true", matchIfMissing = false) public class AuthenticationErrorEventingPublisher { private static final String REQUEST_SIGNATURE = "requestSignature"; 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 2bbc40d49d4..1db3f15c4c4 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 @@ -162,9 +162,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 147d8f3a6f8..4e7c1121e04 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,10 +162,12 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques } catch (IdAuthenticationBusinessException e) { mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "authenticateApplication", e.getErrorCode() + " : " + e.getErrorText()); + 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); 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 f2bb0167722..c736d8d84a1 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); @@ -278,10 +279,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);