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 599d93bcef5..d1767fedce5 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 @@ -513,12 +513,12 @@ public Tuple3 encryptData(byte[] data, String partnerCer return Tuples.of(CryptoUtil.encodeBase64Url(encryptedData.getT1()), CryptoUtil.encodeBase64Url(encryptedData.getT2()), digestAsPlainText(certificateThumbprint)); } - public byte[] asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate) + public String asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate) throws IdAuthenticationBusinessException { X509Certificate x509Certificate = getX509Certificate(partnerCertificate); PublicKey publicKey = x509Certificate.getPublicKey(); byte[] encryptedData = cryptoCore.asymmetricEncrypt(publicKey, dataToEncrypt); - return encryptedData; + return CryptoUtil.encodeBase64(encryptedData); } /** 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/websub/impl/OndemandTemplateEventPublisher.java index cb50a458130..32bf942728c 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/websub/impl/OndemandTemplateEventPublisher.java @@ -134,9 +134,9 @@ private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, O 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(AUTH_PARTNER_ID, partner.map(PartnerDTO::getPartnerId).orElse(null)); eventData.put(INDIVIDUAL_ID_TYPE, baserequestdto.getIndividualIdType()); - eventData.put(ENTITY_NAME, partner.get().getPartnerName()); + eventData.put(ENTITY_NAME, partner.map(PartnerDTO::getPartnerName).orElse(null)); eventData.put(REQUEST_SIGNATURE, headerSignature); EventModel eventModel = createEventModel(onDemadTemplateExtractionTopic, eventData); publishEvent(eventModel); @@ -158,7 +158,7 @@ private EventModel createEventModel(String topic, Map eventData) return model; } - private byte[] encryptIndividualId(String id, String partnerCertificate) { + private String encryptIndividualId(String id, String partnerCertificate) { try { logger.info("Inside the method of encryptIndividualId using partner certificate "); return securityManager.asymmetricEncryption(id.getBytes(), partnerCertificate); 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 847aca099f3..2f9b4a5338e 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 @@ -136,10 +136,10 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt .createAndSetAuthTxnBuilderMetadataToRequest(otpRequestDto, !isPartnerReq, partner); try { - String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); String idType = Objects.nonNull(otpRequestDto.getIndividualIdType()) ? otpRequestDto.getIndividualIdType() : idTypeUtil.getIdType(otpRequestDto.getIndividualId()).getType(); otpRequestDto.setIndividualIdType(idType); + String idvidHash = securityManager.hash(otpRequestDto.getIndividualId()); otpRequestValidator.validateIdvId(otpRequestDto.getIndividualId(), idType, errors, IdAuthCommonConstants.IDV_ID); DataValidationUtil.validate(errors); OtpResponseDTO otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata); @@ -178,4 +178,4 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt } } -} +} \ No newline at end of file diff --git a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/KycAuthRequestValidatorTest.java b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/KycAuthRequestValidatorTest.java index 48bff6eb27d..c6fe2f1613d 100644 --- a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/KycAuthRequestValidatorTest.java +++ b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/KycAuthRequestValidatorTest.java @@ -22,6 +22,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContext; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.validation.BeanPropertyBindingResult; @@ -34,10 +35,10 @@ import io.mosip.authentication.common.service.integration.MasterDataManager; import io.mosip.authentication.common.service.util.EnvUtil; import io.mosip.authentication.common.service.validator.AuthRequestValidator; +import io.mosip.authentication.core.indauth.dto.EkycAuthRequestDTO; import io.mosip.authentication.core.indauth.dto.IdType; import io.mosip.authentication.core.indauth.dto.IdentityDTO; import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; -import io.mosip.authentication.core.indauth.dto.EkycAuthRequestDTO; import io.mosip.authentication.core.indauth.dto.RequestDTO; import io.mosip.kernel.logger.logback.appender.RollingFileAppender; import io.mosip.kernel.pinvalidator.impl.PinValidatorImpl; @@ -51,6 +52,7 @@ @WebMvcTest @ContextConfiguration(classes = { TestContext.class, WebApplicationContext.class }) @Import(EnvUtil.class) +@TestPropertySource(locations="classpath:application.properties") public class KycAuthRequestValidatorTest { @Mock diff --git a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/VciExchangeRequestValidatorTest.java b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/VciExchangeRequestValidatorTest.java index 6df5a1ba32b..0a69dd9d754 100644 --- a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/VciExchangeRequestValidatorTest.java +++ b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/VciExchangeRequestValidatorTest.java @@ -1,9 +1,13 @@ package io.mosip.authentication.service.kyc.validator; -import io.mosip.authentication.common.service.util.EnvUtil; -import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO; -import io.mosip.authentication.core.indauth.dto.VciCredentialsDefinitionRequestDTO; -import io.mosip.authentication.core.indauth.dto.VciExchangeRequestDTO; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -13,24 +17,23 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContext; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.Errors; import org.springframework.web.context.WebApplicationContext; -import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import io.mosip.authentication.common.service.util.EnvUtil; +import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO; +import io.mosip.authentication.core.indauth.dto.VciCredentialsDefinitionRequestDTO; +import io.mosip.authentication.core.indauth.dto.VciExchangeRequestDTO; @RunWith(SpringRunner.class) @WebMvcTest @ContextConfiguration(classes = { TestContext.class, WebApplicationContext.class }) @Import(EnvUtil.class) +@TestPropertySource(locations="classpath:application.properties") public class VciExchangeRequestValidatorTest { @InjectMocks