Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOSIP-31982] Enabling and disabling kafka bean #1250

Merged
merged 17 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class OTPController {
@Autowired
private IdAuthSecurityManager securityManager;

@Autowired
@Autowired(required = false)
private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher;

@InitBinder
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class AuthController {
@Autowired
private PartnerService partnerService;

@Autowired
@Autowired(required = false)
private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher;


Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class KycAuthController {
@Autowired
private KycExchangeRequestValidator kycExchangeValidator;

@Autowired
@Autowired(required = false)
private AuthenticationErrorEventingPublisher authenticationErrorEventingPublisher;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading