From c4e4646057eac9ba84283fa3bccbd48a7b0ea37a Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Mon, 1 Apr 2024 16:11:01 +0530 Subject: [PATCH 1/5] MOSIP-31982 changes done for publishing the data from websub to kafka directly Signed-off-by: Neha Farheen --- authentication/authentication-common/pom.xml | 6 ++ .../service/config/KafkaProducerConfig.java | 36 +++++++++ ...AuthenticationErrorEventingPublisher.java} | 78 ++++++------------- .../manager/IdAuthSecurityManager.java | 1 - .../src/main/resources/bootstrap.properties | 2 + .../constant/IdAuthConfigKeyConstants.java | 3 +- .../otp/service/OtpApplication.java | 4 +- .../otp/service/controller/OTPController.java | 6 +- .../service/IdAuthenticationApplication.java | 4 +- .../service/controller/AuthController.java | 6 +- .../kyc/controller/KycAuthController.java | 8 +- 11 files changed, 82 insertions(+), 72 deletions(-) create mode 100644 authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/KafkaProducerConfig.java rename authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/{websub/impl/OndemandTemplateEventPublisher.java => kafka/impl/AuthenticationErrorEventingPublisher.java} (63%) create mode 100644 authentication/authentication-common/src/main/resources/bootstrap.properties diff --git a/authentication/authentication-common/pom.xml b/authentication/authentication-common/pom.xml index d5f12f33836..e6fd4d6a6a2 100644 --- a/authentication/authentication-common/pom.xml +++ b/authentication/authentication-common/pom.xml @@ -95,6 +95,12 @@ + + org.springframework.kafka + spring-kafka + 3.1.3 + + io.mosip.kernel 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 new file mode 100644 index 00000000000..e3859443036 --- /dev/null +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config/KafkaProducerConfig.java @@ -0,0 +1,36 @@ +package io.mosip.authentication.common.service.config; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.kafka.clients.admin.NewTopic; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringSerializer; +import org.springframework.beans.factory.annotation.Value; +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; + +@Configuration +public class KafkaProducerConfig { + + @Value(value = "${mosip.ida.kafka.bootstrap.servers}") + private String bootstrapAddress; + + @Bean + public ProducerFactory producerFactory() { + Map configProps = new HashMap<>(); + configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress); + configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); + return new DefaultKafkaProducerFactory<>(configProps); + } + + @Bean + public KafkaTemplate kafkaTemplate() { + return new KafkaTemplate<>(producerFactory()); + } +} 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/kafka/impl/AuthenticationErrorEventingPublisher.java similarity index 63% rename from authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/websub/impl/OndemandTemplateEventPublisher.java rename to authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/kafka/impl/AuthenticationErrorEventingPublisher.java index 4bc0178c3bc..016bd682c15 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/kafka/impl/AuthenticationErrorEventingPublisher.java @@ -1,6 +1,6 @@ -package io.mosip.authentication.common.service.websub.impl; +package io.mosip.authentication.common.service.kafka.impl; -import static io.mosip.authentication.core.constant.IdAuthConfigKeyConstants.ON_DEMAND_TEMPLATE_EXTRACTION_TOPIC; +import static io.mosip.authentication.core.constant.IdAuthConfigKeyConstants.AUTHENTICATION_ERROR_EVENTING_TOPIC; import java.util.HashMap; import java.util.Map; @@ -9,15 +9,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.kafka.core.KafkaTemplate; 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; -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; @@ -28,12 +26,12 @@ import io.mosip.kernel.core.websub.model.EventModel; /** - * The Class OnDemandTemplateEventPublisher. + * The Class AuthenticationErrorEventingPublisher. * * @author Neha */ @Component -public class OndemandTemplateEventPublisher extends BaseWebSubEventsInitializer { +public class AuthenticationErrorEventingPublisher { private static final String REQUEST_SIGNATURE = "requestSignature"; @@ -56,19 +54,18 @@ public class OndemandTemplateEventPublisher extends BaseWebSubEventsInitializer /** The Constant logger. */ - private static final Logger logger = IdaLogger.getLogger(OndemandTemplateEventPublisher.class); + private static final Logger logger = IdaLogger.getLogger(AuthenticationErrorEventingPublisher.class); - /** The on demand template extraction topic. */ - @Value("${" + ON_DEMAND_TEMPLATE_EXTRACTION_TOPIC + "}") - private String onDemadTemplateExtractionTopic; + /** The Authenticatrion error eventing topic. */ + @Value("${" + AUTHENTICATION_ERROR_EVENTING_TOPIC + "}") + private String authenticationErrorEventingTopic; - @Value("${mosip.ida.ondemand.template.extraction.partner.id}") + @Value("${mosip.ida.authentication.error.eventing.encrypt.partner.id}") private String partnerId; - - /** The web sub event publish helper. */ + @Autowired - private WebSubHelper webSubHelper; + private KafkaTemplate kafkaTemplate; @Autowired private IdAuthSecurityManager securityManager; @@ -76,58 +73,25 @@ public class OndemandTemplateEventPublisher extends BaseWebSubEventsInitializer @Autowired private PartnerDataRepository partnerDataRepo; - /** - * Do subscribe. - */ - @Override - protected void doSubscribe() { - // Nothing to do here since we are just publishing event for this topic - } - - /** - * Try register topic partner service events. - */ - private void tryRegisterTopicOnDemandEvent() { - try { - logger.debug(IdAuthCommonConstants.SESSION_ID, "tryRegisterOnDemandEvent", "", - "Trying to register topic: " + onDemadTemplateExtractionTopic); - webSubHelper.registerTopic(onDemadTemplateExtractionTopic); - logger.info(IdAuthCommonConstants.SESSION_ID, "tryRegisterOnDemandEvent", "", - "Registered topic: " + onDemadTemplateExtractionTopic); - } catch (Exception e) { - logger.info(IdAuthCommonConstants.SESSION_ID, "tryRegisterOnDemandEvent", e.getClass().toString(), - "Error registering topic: " + onDemadTemplateExtractionTopic + "\n" + e.getMessage()); - } - } - - @Override - protected void doRegister() { - logger.info(IdAuthCommonConstants.SESSION_ID, "doRegister", this.getClass().getSimpleName(), - "On demand template event topic.."); - tryRegisterTopicOnDemandEvent(); - } - - public void publishEvent(EventModel eventModel) { - webSubHelper.publishEvent(onDemadTemplateExtractionTopic, eventModel); - } + public void notify(BaseRequestDTO baserequestdto, String headerSignature, Optional partner, IdAuthenticationBusinessException e, Map metadata) { try { sendEvents(baserequestdto, headerSignature, partner, e, metadata); } catch (Exception exception) { - logger.error(IdRepoSecurityManager.getUser(), "On demand template extraction", "notify", + logger.error(IdRepoSecurityManager.getUser(), "Authentication error eventing", "notify", exception.getMessage()); } } 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"); + logger.info("Inside sendEvents authentication error eventing"); + logger.info("Inside partner data to get certificate for authentication error eventing encryption"); Optional partnerDataCert = partnerDataRepo.findByPartnerId(partnerId); if (partnerDataCert.isEmpty()) { - logger.info("Partner is not configured for on demand extraction."); + logger.info("Partner is not configured for encrypting individual id."); } else { Map eventData = new HashMap<>(); eventData.put(ERROR_CODE, e.getErrorCode()); @@ -139,7 +103,7 @@ private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, O eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType()); eventData.put(ENTITY_NAME, partner.map(PartnerDTO::getPartnerName).orElse(null)); eventData.put(REQUEST_SIGNATURE, headerSignature); - EventModel eventModel = createEventModel(onDemadTemplateExtractionTopic, eventData); + EventModel eventModel = createEventModel(authenticationErrorEventingTopic, eventData); publishEvent(eventModel); } } @@ -158,10 +122,14 @@ private EventModel createEventModel(String topic, Map eventData) model.setTopic(topic); return model; } + + public void publishEvent(EventModel eventModel) { + kafkaTemplate.send(authenticationErrorEventingTopic, eventModel); + } private String encryptIndividualId(String id, String partnerCertificate) { try { - logger.info("Inside the method of encryptIndividualId using partner certificate "); + logger.info("Inside the method of encrypting IndividualId using partner certificate "); return securityManager.asymmetricEncryption(id.getBytes(), partnerCertificate); } catch (IdAuthenticationBusinessException e) { // TODO Auto-generated catch block 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 a81f554cae2..1ef87bdde55 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,7 +518,6 @@ 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.encodeBase64(encryptedData); } diff --git a/authentication/authentication-common/src/main/resources/bootstrap.properties b/authentication/authentication-common/src/main/resources/bootstrap.properties new file mode 100644 index 00000000000..d9749e5e7fc --- /dev/null +++ b/authentication/authentication-common/src/main/resources/bootstrap.properties @@ -0,0 +1,2 @@ +mosip.ida.kafka.bootstrap.servers=kafka-0.kafka-headless.${kafka.profile}:${kafka.port},kafka-1.kafka-headless.${kafka.profile}:${kafka.port},kafka-2.kafka-headless.${kafka.profile}:${kafka.port} +spring.kafka.admin.properties.allow.auto.create.topics=true \ No newline at end of file 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 d3aaebbef02..4288e4ce7a0 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 @@ -134,8 +134,7 @@ private IdAuthConfigKeyConstants() { public static final String AUTH_TRANSACTION_STATUS_TOPIC = "ida-topic-auth-transaction-status"; public static final String AUTH_ANONYMOUS_PROFILE_TOPIC = "ida-topic-auth-anonymous-profile"; public static final String AUTH_FRAUD_ANALYSIS_TOPIC = "ida-topic-fraud-analysis"; - public static final String ON_DEMAND_TEMPLATE_EXTRACTION_TOPIC = "ida-topic-on-demand-template-extraction"; - + public static final String AUTHENTICATION_ERROR_EVENTING_TOPIC = "ida-topic-authentication-error-eventing"; public static final String IDA_MAX_CREDENTIAL_PULL_WINDOW_DAYS = "ida-max-credential-pull-window-days"; public static final String IDA_MAX_WEBSUB_MSG_PULL_WINDOW_DAYS = "ida-max-websub-messages-pull-window-days"; diff --git a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java index c1d4c24781b..aabd10b444d 100644 --- a/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java +++ b/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/OtpApplication.java @@ -44,6 +44,7 @@ import io.mosip.authentication.common.service.integration.PartnerServiceManager; import io.mosip.authentication.common.service.integration.PasswordComparator; import io.mosip.authentication.common.service.integration.TokenIdManager; +import io.mosip.authentication.common.service.kafka.impl.AuthenticationErrorEventingPublisher; import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; import io.mosip.authentication.common.service.util.EnvUtil; import io.mosip.authentication.common.service.util.IdaRequestResponsConsumerUtil; @@ -54,7 +55,6 @@ import io.mosip.authentication.common.service.websub.impl.AuthTransactionStatusEventPublisher; import io.mosip.authentication.common.service.websub.impl.IdAuthFraudAnalysisEventPublisher; import io.mosip.authentication.common.service.websub.impl.MasterDataUpdateEventInitializer; -import io.mosip.authentication.common.service.websub.impl.OndemandTemplateEventPublisher; import io.mosip.authentication.common.service.websub.impl.PartnerCACertEventInitializer; import io.mosip.authentication.common.service.websub.impl.PartnerServiceEventsInitializer; import io.mosip.authentication.core.util.IdTypeUtil; @@ -112,7 +112,7 @@ PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class, IdAuthWebSubInitializer.class, AuthAnonymousEventPublisher.class, EnvUtil.class, KeyBindedTokenMatcherUtil.class, HSMHealthCheck.class, PrivateKeyDecryptorHelper.class, - PasswordAuthServiceImpl.class, PasswordComparator.class, OndemandTemplateEventPublisher.class }) + PasswordAuthServiceImpl.class, PasswordComparator.class, AuthenticationErrorEventingPublisher.class }) @ComponentScan(basePackages = { "io.mosip.authentication.otp.service.*", "io.mosip.kernel.core.logger.config", "${mosip.auth.adapter.impl.basepackage}" }, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = { "io.mosip.idrepository.core.config.IdRepoDataSourceConfig.*" })) 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 f9baef81853..2bbc40d49d4 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 @@ -27,10 +27,10 @@ import io.mosip.authentication.common.service.builder.AuthTransactionBuilder; import io.mosip.authentication.common.service.helper.AuditHelper; import io.mosip.authentication.common.service.helper.AuthTransactionHelper; +import io.mosip.authentication.common.service.kafka.impl.AuthenticationErrorEventingPublisher; import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; import io.mosip.authentication.common.service.util.IdaRequestResponsConsumerUtil; import io.mosip.authentication.common.service.validator.OTPRequestValidator; -import io.mosip.authentication.common.service.websub.impl.OndemandTemplateEventPublisher; import io.mosip.authentication.core.constant.AuditEvents; import io.mosip.authentication.core.constant.AuditModules; import io.mosip.authentication.core.constant.IdAuthCommonConstants; @@ -93,7 +93,7 @@ public class OTPController { private IdAuthSecurityManager securityManager; @Autowired - private OndemandTemplateEventPublisher ondemandTemplateEventPublisher; + private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher; @InitBinder private void initBinder(WebDataBinder binder) { @@ -163,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, request.getHeader("signature"), partner, e, + authenticationErrorEventingPublisher.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/IdAuthenticationApplication.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java index c8314aca958..13d295c4bca 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java @@ -48,6 +48,7 @@ import io.mosip.authentication.common.service.integration.PartnerServiceManager; import io.mosip.authentication.common.service.integration.PasswordComparator; import io.mosip.authentication.common.service.integration.TokenIdManager; +import io.mosip.authentication.common.service.kafka.impl.AuthenticationErrorEventingPublisher; import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; import io.mosip.authentication.common.service.util.BioMatcherUtil; import io.mosip.authentication.common.service.util.EnvUtil; @@ -59,7 +60,6 @@ import io.mosip.authentication.common.service.websub.impl.AuthTransactionStatusEventPublisher; import io.mosip.authentication.common.service.websub.impl.IdAuthFraudAnalysisEventPublisher; import io.mosip.authentication.common.service.websub.impl.MasterDataUpdateEventInitializer; -import io.mosip.authentication.common.service.websub.impl.OndemandTemplateEventPublisher; import io.mosip.authentication.common.service.websub.impl.PartnerCACertEventInitializer; import io.mosip.authentication.common.service.websub.impl.PartnerServiceEventsInitializer; import io.mosip.authentication.core.util.DemoMatcherUtil; @@ -126,7 +126,7 @@ AuthAnonymousProfileServiceImpl.class, AuthAnonymousEventPublisher.class, SessionKeyDecrytorHelper.class, ExternalRestHelperConfig.class, IdaRequestResponsConsumerUtil.class, PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class, EnvUtil.class, KeyBindedTokenMatcherUtil.class, HSMHealthCheck.class, TokenValidationHelper.class, VCSchemaProviderUtil.class, PrivateKeyDecryptorHelper.class, - PasswordAuthServiceImpl.class, PasswordComparator.class, OndemandTemplateEventPublisher.class }) + PasswordAuthServiceImpl.class, PasswordComparator.class, AuthenticationErrorEventingPublisher.class }) @ComponentScan(basePackages = { "io.mosip.authentication.service.*", "io.mosip.kernel.core.logger.config", "io.mosip.authentication.common.service.config", "${mosip.auth.adapter.impl.basepackage}" }, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = { "io.mosip.idrepository.core.config.IdRepoDataSourceConfig.*" })) 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 a653e0917b0..147d8f3a6f8 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 @@ -19,10 +19,10 @@ import io.mosip.authentication.common.service.builder.AuthTransactionBuilder; import io.mosip.authentication.common.service.helper.AuditHelper; import io.mosip.authentication.common.service.helper.AuthTransactionHelper; +import io.mosip.authentication.common.service.kafka.impl.AuthenticationErrorEventingPublisher; import io.mosip.authentication.common.service.util.AuthTypeUtil; import io.mosip.authentication.common.service.util.IdaRequestResponsConsumerUtil; import io.mosip.authentication.common.service.validator.AuthRequestValidator; -import io.mosip.authentication.common.service.websub.impl.OndemandTemplateEventPublisher; import io.mosip.authentication.core.constant.AuditEvents; import io.mosip.authentication.core.constant.IdAuthCommonConstants; import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants; @@ -91,7 +91,7 @@ public class AuthController { private PartnerService partnerService; @Autowired - private OndemandTemplateEventPublisher ondemandTemplateEventPublisher; + private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher; /** @@ -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, + authenticationErrorEventingPublisher.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 eada0439155..f2bb0167722 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 @@ -21,10 +21,10 @@ import io.mosip.authentication.common.service.builder.AuthTransactionBuilder; import io.mosip.authentication.common.service.helper.AuditHelper; import io.mosip.authentication.common.service.helper.AuthTransactionHelper; +import io.mosip.authentication.common.service.kafka.impl.AuthenticationErrorEventingPublisher; import io.mosip.authentication.common.service.util.AuthTypeUtil; import io.mosip.authentication.common.service.util.IdaRequestResponsConsumerUtil; import io.mosip.authentication.common.service.validator.AuthRequestValidator; -import io.mosip.authentication.common.service.websub.impl.OndemandTemplateEventPublisher; import io.mosip.authentication.core.constant.AuditEvents; import io.mosip.authentication.core.constant.IdAuthCommonConstants; import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants; @@ -101,7 +101,7 @@ public class KycAuthController { private KycExchangeRequestValidator kycExchangeValidator; @Autowired - private OndemandTemplateEventPublisher ondemandTemplateEventPublisher; + private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher; /** * @@ -199,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, request.getHeader("signature"), partner, + authenticationErrorEventingPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), partner, e, ekycAuthRequestDTO.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.EKYC_REQUEST_RESPONSE, ekycAuthRequestDTO, e); @@ -280,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, request.getHeader("signature"), partner, e, + authenticationErrorEventingPublisher.notify(authRequestDTO, request.getHeader("signature"), partner, e, authRequestDTO.getMetadata()); } auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.KYC_REQUEST_RESPONSE, authRequestDTO, e); From 46ffaa427f9b3a212bd5a2a7680ee7a40a92e900 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Mon, 1 Apr 2024 17:07:25 +0530 Subject: [PATCH 2/5] MOSIP-31982 build failure resolved Signed-off-by: Neha Farheen --- authentication/authentication-common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authentication/authentication-common/pom.xml b/authentication/authentication-common/pom.xml index e6fd4d6a6a2..ab360ec30ca 100644 --- a/authentication/authentication-common/pom.xml +++ b/authentication/authentication-common/pom.xml @@ -98,7 +98,7 @@ org.springframework.kafka spring-kafka - 3.1.3 + ${spring.boot.version} From c084ac568655ef4be581deae0d7d2914b36e3315 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Tue, 2 Apr 2024 15:50:15 +0530 Subject: [PATCH 3/5] Updated kafka version Signed-off-by: Neha Farheen --- authentication/authentication-common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authentication/authentication-common/pom.xml b/authentication/authentication-common/pom.xml index 4727bb6dd37..d62953bfd9f 100644 --- a/authentication/authentication-common/pom.xml +++ b/authentication/authentication-common/pom.xml @@ -98,7 +98,7 @@ org.springframework.kafka spring-kafka - ${spring.boot.version} + 2.1.7.RELEASE From 74cf114a38e218514d0b5dca25168da9d6898ad2 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 17 Apr 2024 15:58:36 +0530 Subject: [PATCH 4/5] kafka bean enable and disable Signed-off-by: Neha Farheen --- .../service/config/KafkaProducerConfig.java | 2 ++ .../AuthenticationErrorEventingPublisher.java | 2 ++ .../otp/service/controller/OTPController.java | 10 ++++++---- .../service/controller/AuthController.java | 4 +++- .../kyc/controller/KycAuthController.java | 20 ++++++++++--------- 5 files changed, 24 insertions(+), 14 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 e3859443036..e28a0590307 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") 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..170c9e71c16 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") 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); From 7e817b46066b5c5638f0304d178c093745942630 Mon Sep 17 00:00:00 2001 From: Neha Farheen Date: Wed, 17 Apr 2024 16:17:45 +0530 Subject: [PATCH 5/5] kafka bean enable and disable Signed-off-by: Neha Farheen --- .../common/service/config/KafkaProducerConfig.java | 2 +- .../kafka/impl/AuthenticationErrorEventingPublisher.java | 2 +- 2 files changed, 2 insertions(+), 2 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 e28a0590307..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 @@ -16,7 +16,7 @@ import org.springframework.kafka.support.serializer.JsonSerializer; @Configuration -@ConditionalOnProperty(value = "mosip.ida.authentication.error.eventing.enabled", havingValue = "true") +@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 170c9e71c16..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 @@ -32,7 +32,7 @@ * @author Neha */ @Component -@ConditionalOnProperty(value = "mosip.ida.authentication.error.eventing.enabled", havingValue = "true") +@ConditionalOnProperty(value = "mosip.ida.authentication.error.eventing.enabled", havingValue = "true", matchIfMissing = false) public class AuthenticationErrorEventingPublisher { private static final String REQUEST_SIGNATURE = "requestSignature";