Skip to content

Commit

Permalink
Changes done
Browse files Browse the repository at this point in the history
Signed-off-by: Neha Farheen <[email protected]>
  • Loading branch information
Neha Farheen committed Feb 9, 2024
1 parent 3e71a63 commit c2dcb56
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public Tuple3<String, String, String> encryptData(byte[] data, String partnerCer
byte[] certificateThumbprint = cryptomanagerUtils.getCertificateThumbprint(x509Certificate);
return Tuples.of(CryptoUtil.encodeBase64Url(encryptedData.getT1()), CryptoUtil.encodeBase64Url(encryptedData.getT2()), digestAsPlainText(certificateThumbprint));
}

public byte[] asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate)
throws IdAuthenticationBusinessException {
X509Certificate x509Certificate = getX509Certificate(partnerCertificate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.springframework.beans.factory.annotation.Value;
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;
Expand Down Expand Up @@ -52,18 +54,26 @@ public class OndemandTemplateEventPublisher extends BaseWebSubEventsInitializer
private static final String PUBLISHER_IDA = "IDA";

/** The Constant logger. */
private static final Logger logger = IdaLogger.getLogger(CredentialStoreStatusEventPublisher.class);

private static final Logger logger = IdaLogger.getLogger(OndemandTemplateEventPublisher.class);


/** The on demand template extraction topic. */
@Value("${" + ON_DEMAND_TEMPLATE_EXTRACTION_TOPIC + "}")
private String onDemadTemplateExtractionTopic;

@Value("${mosip.ida.ondemand.template.extraction.partner.id}")
private String partnerId;

/** The web sub event publish helper. */
@Autowired
private WebSubHelper webSubHelper;

@Autowired
private IdAuthSecurityManager securityManager;

@Autowired
private PartnerDataRepository partnerDataRepo;

/**
* Do subscribe.
Expand Down Expand Up @@ -113,18 +123,24 @@ public void notify(BaseRequestDTO baserequestdto, String headerSignature, Option
private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, Optional<PartnerDTO> partner,
IdAuthenticationBusinessException e, Map<String, Object> metadata) {
logger.info("Inside sendEvents ondemand extraction");
Map<String, Object> eventData = new HashMap<>();
eventData.put(ERROR_CODE, e.getErrorCode());
eventData.put(ERROR_MESSAGE, e.getErrorText());
eventData.put(REQUESTDATETIME, DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime()));
eventData.put(INDIVIDUAL_ID, encryptIndividualId(baserequestdto.getIndividualId(),
metadata.get(IdAuthCommonConstants.PARTNER_CERTIFICATE).toString()));
eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId());
eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType());
eventData.put(ENTITY_NAME, partner.get().getPartnerName());
eventData.put(REQUEST_SIGNATURE, headerSignature);
EventModel eventModel = createEventModel(onDemadTemplateExtractionTopic, eventData);
publishEvent(eventModel);
logger.info("Inside partner data to get certificate for ondemand extraction encryption");
Optional<PartnerData> partnerDataCert = partnerDataRepo.findByPartnerId(partnerId);
if (partnerDataCert.isEmpty()) {
logger.info("Partner is not configured for on demand extraction.");
} else {
Map<String, Object> eventData = new HashMap<>();
eventData.put(ERROR_CODE, e.getErrorCode());
eventData.put(ERROR_MESSAGE, e.getErrorText());
eventData.put(REQUESTDATETIME, DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime()));
eventData.put(INDIVIDUAL_ID,
encryptIndividualId(baserequestdto.getIndividualId(), partnerDataCert.get().getCertificateData()));
eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId());
eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType());
eventData.put(ENTITY_NAME, partner.get().getPartnerName());
eventData.put(REQUEST_SIGNATURE, headerSignature);
EventModel eventModel = createEventModel(onDemadTemplateExtractionTopic, eventData);
publishEvent(eventModel);
}
}

private EventModel createEventModel(String topic, Map<String, Object> eventData) {
Expand All @@ -144,6 +160,7 @@ private EventModel createEventModel(String topic, Map<String, Object> eventData)

private byte[] encryptIndividualId(String id, String partnerCertificate) {
try {
logger.info("Inside the method of encryptIndividualId using partner certificate ");
return securityManager.asymmetricEncryption(id.getBytes(), partnerCertificate);
} catch (IdAuthenticationBusinessException e) {
// TODO Auto-generated catch block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
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;
Expand All @@ -71,6 +72,7 @@
import io.mosip.kernel.keymanager.hsm.health.HSMHealthCheck;
import io.mosip.kernel.keymanager.hsm.impl.KeyStoreImpl;
import io.mosip.kernel.keymanagerservice.helper.KeymanagerDBHelper;
import io.mosip.kernel.keymanagerservice.helper.PrivateKeyDecryptorHelper;
import io.mosip.kernel.keymanagerservice.helper.SessionKeyDecrytorHelper;
import io.mosip.kernel.keymanagerservice.service.impl.KeymanagerServiceImpl;
import io.mosip.kernel.keymanagerservice.util.KeymanagerUtil;
Expand All @@ -82,7 +84,6 @@
import io.mosip.kernel.tokenidgenerator.generator.TokenIDGenerator;
import io.mosip.kernel.tokenidgenerator.service.impl.TokenIDGeneratorServiceImpl;
import io.mosip.kernel.zkcryptoservice.service.impl.ZKCryptoManagerServiceImpl;
import io.mosip.kernel.keymanagerservice.helper.PrivateKeyDecryptorHelper;

/**
* Spring-boot class for ID Authentication Application.
Expand Down Expand Up @@ -111,7 +112,7 @@
PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class,
IdAuthWebSubInitializer.class, AuthAnonymousEventPublisher.class, EnvUtil.class, KeyBindedTokenMatcherUtil.class,
HSMHealthCheck.class, PrivateKeyDecryptorHelper.class,
PasswordAuthServiceImpl.class, PasswordComparator.class })
PasswordAuthServiceImpl.class, PasswordComparator.class, OndemandTemplateEventPublisher.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.*" }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ 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())) {
ondemandTemplateEventPublisher.notify(otpRequestDto, request.getHeader("signature"), partner, e,
otpRequestDto.getMetadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
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;
Expand Down Expand Up @@ -94,7 +95,7 @@
import io.mosip.kernel.tokenidgenerator.service.impl.TokenIDGeneratorServiceImpl;
import io.mosip.kernel.zkcryptoservice.service.impl.ZKCryptoManagerServiceImpl;
import io.mosip.kernel.keymanager.hsm.health.HSMHealthCheck;
import io.mosip.kernel.keymanagerservice.helper.PrivateKeyDecryptorHelper;


/**
* Spring-boot class for ID Authentication Application.
Expand Down Expand Up @@ -125,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 })
PasswordAuthServiceImpl.class, PasswordComparator.class, OndemandTemplateEventPublisher.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.*" }))
Expand All @@ -142,4 +143,4 @@ public static void main(String[] args) {
SpringApplication.run(IdAuthenticationApplication.class, args);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques
throw authTransactionHelper.createDataValidationException(authTxnBuilder, e, requestWithMetadata);
} catch (IdAuthenticationBusinessException e) {
mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(),
"authenticateApplication", e.getErrorCode() + " : " + e.getErrorText());
"authenticateApplication", e.getErrorCode() + " : " + e.getErrorText());
if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) {
ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e,
authrequestdto.getMetadata());
Expand Down

0 comments on commit c2dcb56

Please sign in to comment.