From 74f117c71108a0d147e86fd6ce4bf982b7c2b8e3 Mon Sep 17 00:00:00 2001 From: Loganathan Sekar <42532387+LoganathanSekar7627@users.noreply.github.com> Date: Thu, 3 Aug 2023 19:17:19 +0530 Subject: [PATCH 1/8] Reverted dependencies snapshot versions (#1059) Co-authored-by: Loganathan Sekar --- authentication/esignet-integration-impl/pom.xml | 2 +- authentication/pom.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/authentication/esignet-integration-impl/pom.xml b/authentication/esignet-integration-impl/pom.xml index 297401e0d2e..bcf53f9bf1c 100644 --- a/authentication/esignet-integration-impl/pom.xml +++ b/authentication/esignet-integration-impl/pom.xml @@ -42,7 +42,7 @@ io.mosip.kernel kernel-keymanager-service - 1.2.0.1-SNAPSHOT + ${kernel-keymanager-service.version} provided lib diff --git a/authentication/pom.xml b/authentication/pom.xml index a31f895ed1c..80bbfad0de0 100644 --- a/authentication/pom.xml +++ b/authentication/pom.xml @@ -89,9 +89,9 @@ UTF-8 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B1 ${kernel.parent.version} - 1.2.0.1-SNAPSHOT + 1.2.0.1-B2 ${kernel.parent.version} ${kernel.parent.version} ${kernel.parent.version} @@ -101,10 +101,10 @@ ${kernel.parent.version} ${kernel.parent.version} ${kernel.parent.version} - 1.2.0.1-SNAPSHOT + ${kernel.parent.version} ${kernel.parent.version} ${kernel.parent.version} - 1.2.0.1-SNAPSHOT + 1.2.0.1-B1 20180130 ${kernel.parent.version} ${kernel.parent.version} From f82bc6a58da60556e38206172e20f2b87045bb06 Mon Sep 17 00:00:00 2001 From: Loganathan Sekar <42532387+LoganathanSekar7627@users.noreply.github.com> Date: Thu, 3 Aug 2023 20:39:16 +0530 Subject: [PATCH 2/8] Fix compilation issue after snapshot version revert. (#1060) * Reverted dependencies snapshot versions * Fixed compilation issue --------- Co-authored-by: Loganathan Sekar --- .../service/InternalAuthenticationApplication.java | 5 ++--- .../mosip/authentication/otp/service/OtpApplication.java | 5 ++--- .../service/IdAuthenticationApplication.java | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/InternalAuthenticationApplication.java b/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/InternalAuthenticationApplication.java index a604969cb44..8569c5b04eb 100644 --- a/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/InternalAuthenticationApplication.java +++ b/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/InternalAuthenticationApplication.java @@ -28,9 +28,9 @@ import io.mosip.authentication.common.service.impl.DemoAuthServiceImpl; import io.mosip.authentication.common.service.impl.IdInfoFetcherImpl; import io.mosip.authentication.common.service.impl.IdServiceImpl; +import io.mosip.authentication.common.service.impl.KeyBindedTokenAuthServiceImpl; import io.mosip.authentication.common.service.impl.OTPAuthServiceImpl; import io.mosip.authentication.common.service.impl.OTPServiceImpl; -import io.mosip.authentication.common.service.impl.KeyBindedTokenAuthServiceImpl; import io.mosip.authentication.common.service.impl.hotlist.HotlistServiceImpl; import io.mosip.authentication.common.service.impl.idevent.CredentialStoreServiceImpl; import io.mosip.authentication.common.service.impl.idevent.IdChangeEventHandlerServiceImpl; @@ -83,7 +83,6 @@ import io.mosip.kernel.cryptomanager.util.CryptomanagerUtils; import io.mosip.kernel.dataaccess.hibernate.config.HibernateDaoConfig; import io.mosip.kernel.keygenerator.bouncycastle.KeyGenerator; -import io.mosip.kernel.keymanager.hsm.health.HSMHealthCheck; import io.mosip.kernel.keymanager.hsm.impl.KeyStoreImpl; import io.mosip.kernel.keymanagerservice.controller.KeymanagerController; import io.mosip.kernel.keymanagerservice.entity.CACertificateStore; @@ -134,7 +133,7 @@ io.mosip.kernel.keymanagerservice.dto.AuthorizedRolesDTO.class, io.mosip.kernel.partnercertservice.dto.AuthorizedRolesDTO.class, io.mosip.kernel.signature.dto.AuthorizedRolesDTO.class, - EnvUtil.class, KeyBindedTokenMatcherUtil.class, HSMHealthCheck.class }) + EnvUtil.class, KeyBindedTokenMatcherUtil.class }) @ComponentScan(basePackages = { "io.mosip.authentication.internal.service.*", "${mosip.auth.adapter.impl.basepackage}", "io.mosip.kernel.core.logger.config", "io.mosip.authentication.common.service.config" }, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = { 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 331c480ca9c..1c80b631a5a 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 @@ -27,9 +27,9 @@ import io.mosip.authentication.common.service.impl.AuthtypeStatusImpl; import io.mosip.authentication.common.service.impl.IdInfoFetcherImpl; import io.mosip.authentication.common.service.impl.IdServiceImpl; +import io.mosip.authentication.common.service.impl.KeyBindedTokenAuthServiceImpl; import io.mosip.authentication.common.service.impl.OTPAuthServiceImpl; import io.mosip.authentication.common.service.impl.OTPServiceImpl; -import io.mosip.authentication.common.service.impl.KeyBindedTokenAuthServiceImpl; import io.mosip.authentication.common.service.impl.hotlist.HotlistServiceImpl; import io.mosip.authentication.common.service.impl.masterdata.MasterDataCacheUpdateServiceImpl; import io.mosip.authentication.common.service.impl.notification.NotificationServiceImpl; @@ -66,7 +66,6 @@ import io.mosip.kernel.cryptomanager.util.CryptomanagerUtils; import io.mosip.kernel.dataaccess.hibernate.config.HibernateDaoConfig; import io.mosip.kernel.keygenerator.bouncycastle.KeyGenerator; -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.SessionKeyDecrytorHelper; @@ -106,7 +105,7 @@ MasterDataUpdateEventInitializer.class, IdAuthFraudAnalysisEventManager.class, IdAuthFraudAnalysisEventPublisher.class, LangComparatorConfig.class, OpenApiProperties.class, SessionKeyDecrytorHelper.class, ExternalRestHelperConfig.class, IdaRequestResponsConsumerUtil.class, PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class, - IdAuthWebSubInitializer.class, AuthAnonymousEventPublisher.class, EnvUtil.class, KeyBindedTokenMatcherUtil.class, HSMHealthCheck.class }) + IdAuthWebSubInitializer.class, AuthAnonymousEventPublisher.class, EnvUtil.class, KeyBindedTokenMatcherUtil.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-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/IdAuthenticationApplication.java index be16e111801..4a80ce98ed4 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 @@ -1,6 +1,5 @@ package io.mosip.authentication.service; -import io.mosip.authentication.common.service.util.KeyBindedTokenMatcherUtil; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; @@ -31,8 +30,8 @@ import io.mosip.authentication.common.service.impl.DemoAuthServiceImpl; import io.mosip.authentication.common.service.impl.IdInfoFetcherImpl; import io.mosip.authentication.common.service.impl.IdServiceImpl; -import io.mosip.authentication.common.service.impl.OTPAuthServiceImpl; import io.mosip.authentication.common.service.impl.KeyBindedTokenAuthServiceImpl; +import io.mosip.authentication.common.service.impl.OTPAuthServiceImpl; import io.mosip.authentication.common.service.impl.hotlist.HotlistServiceImpl; import io.mosip.authentication.common.service.impl.masterdata.MasterDataCacheUpdateServiceImpl; import io.mosip.authentication.common.service.impl.notification.NotificationServiceImpl; @@ -49,6 +48,7 @@ import io.mosip.authentication.common.service.util.BioMatcherUtil; import io.mosip.authentication.common.service.util.EnvUtil; import io.mosip.authentication.common.service.util.IdaRequestResponsConsumerUtil; +import io.mosip.authentication.common.service.util.KeyBindedTokenMatcherUtil; import io.mosip.authentication.common.service.validator.AuthFiltersValidator; import io.mosip.authentication.common.service.validator.AuthRequestValidator; import io.mosip.authentication.common.service.websub.IdAuthWebSubInitializer; @@ -88,7 +88,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.keymanager.hsm.health.HSMHealthCheck; /** * Spring-boot class for ID Authentication Application. @@ -117,7 +116,7 @@ MasterDataUpdateEventInitializer.class, DemoNormalizer.class, DemoMatcherUtil.class, IdAuthFraudAnalysisEventManager.class, IdAuthFraudAnalysisEventPublisher.class, AuthFiltersValidator.class, AuthAnonymousProfileServiceImpl.class, AuthAnonymousEventPublisher.class, SessionKeyDecrytorHelper.class, ExternalRestHelperConfig.class, IdaRequestResponsConsumerUtil.class, - PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class, EnvUtil.class, KeyBindedTokenMatcherUtil.class, HSMHealthCheck.class }) + PartnerCACertEventServiceImpl.class, PartnerCACertEventInitializer.class, EnvUtil.class, KeyBindedTokenMatcherUtil.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.*" })) From a4c36757e9e805a269ddf2c69b9c4cb156dff504 Mon Sep 17 00:00:00 2001 From: Keshav Mishra Date: Fri, 18 Aug 2023 17:37:16 +0530 Subject: [PATCH 3/8] Release changes (#1063) * Release Bot Pre-release changes * Update README.md Signed-off-by: Keshav Mishra --------- Signed-off-by: Keshav Mishra Co-authored-by: ckm007 --- .github/workflows/push_trigger.yml | 2 +- authentication/authentication-authtypelockfilter-impl/pom.xml | 4 ++-- authentication/authentication-common/pom.xml | 4 ++-- authentication/authentication-core/pom.xml | 4 ++-- authentication/authentication-filter-api/pom.xml | 4 ++-- authentication/authentication-hotlistfilter-impl/pom.xml | 4 ++-- authentication/authentication-internal-service/pom.xml | 4 ++-- authentication/authentication-otp-service/pom.xml | 4 ++-- authentication/authentication-service/pom.xml | 4 ++-- authentication/esignet-integration-impl/pom.xml | 2 +- authentication/pom.xml | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/push_trigger.yml b/.github/workflows/push_trigger.yml index 527a292428d..06dc9e54c85 100644 --- a/.github/workflows/push_trigger.yml +++ b/.github/workflows/push_trigger.yml @@ -121,7 +121,7 @@ jobs: - name: Publish the maven package run: | - cd authentication && mvn deploy -DaltDeploymentRepository=ossrh::default::${{ secrets.OSSRH_SNAPSHOT_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml + cd authentication && mvn deploy -DaltDeploymentRepository=ossrh::default::${{ secrets.RELEASE_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} GPG_TTY: $(tty) diff --git a/authentication/authentication-authtypelockfilter-impl/pom.xml b/authentication/authentication-authtypelockfilter-impl/pom.xml index ae96c9ee7be..014a94ed228 100644 --- a/authentication/authentication-authtypelockfilter-impl/pom.xml +++ b/authentication/authentication-authtypelockfilter-impl/pom.xml @@ -4,9 +4,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-authtypelockfilter-impl authentication-authtypelockfilter-impl ID Authentication Filter Implementation for Auth Type Lock validation diff --git a/authentication/authentication-common/pom.xml b/authentication/authentication-common/pom.xml index b2b005e83d4..14631ac07fd 100644 --- a/authentication/authentication-common/pom.xml +++ b/authentication/authentication-common/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-common authentication-common diff --git a/authentication/authentication-core/pom.xml b/authentication/authentication-core/pom.xml index c0213966427..a196bbd7de1 100644 --- a/authentication/authentication-core/pom.xml +++ b/authentication/authentication-core/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-core jar diff --git a/authentication/authentication-filter-api/pom.xml b/authentication/authentication-filter-api/pom.xml index 0812ac79ab3..bbb7acd4119 100644 --- a/authentication/authentication-filter-api/pom.xml +++ b/authentication/authentication-filter-api/pom.xml @@ -4,9 +4,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-filter-api authentication-filter-api ID Authentication Filter API diff --git a/authentication/authentication-hotlistfilter-impl/pom.xml b/authentication/authentication-hotlistfilter-impl/pom.xml index 3d3b1e833ac..ffde65b2e93 100644 --- a/authentication/authentication-hotlistfilter-impl/pom.xml +++ b/authentication/authentication-hotlistfilter-impl/pom.xml @@ -4,9 +4,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-hotlistfilter-impl authentication-hotlistfilter-impl ID Authentication Filter Implementation for Hotlist validation diff --git a/authentication/authentication-internal-service/pom.xml b/authentication/authentication-internal-service/pom.xml index 86e252e2399..2c48adec6b0 100644 --- a/authentication/authentication-internal-service/pom.xml +++ b/authentication/authentication-internal-service/pom.xml @@ -7,9 +7,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-internal-service authentication-internal-service diff --git a/authentication/authentication-otp-service/pom.xml b/authentication/authentication-otp-service/pom.xml index a3e41799a59..ffb017f5171 100644 --- a/authentication/authentication-otp-service/pom.xml +++ b/authentication/authentication-otp-service/pom.xml @@ -7,9 +7,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-otp-service authentication-otp-service diff --git a/authentication/authentication-service/pom.xml b/authentication/authentication-service/pom.xml index d68b575897b..e0f1882c870 100644 --- a/authentication/authentication-service/pom.xml +++ b/authentication/authentication-service/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 authentication-service jar diff --git a/authentication/esignet-integration-impl/pom.xml b/authentication/esignet-integration-impl/pom.xml index bcf53f9bf1c..57c7083efe0 100644 --- a/authentication/esignet-integration-impl/pom.xml +++ b/authentication/esignet-integration-impl/pom.xml @@ -6,7 +6,7 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 esignet-integration-impl diff --git a/authentication/pom.xml b/authentication/pom.xml index 80bbfad0de0..51e354d9fa4 100644 --- a/authentication/pom.xml +++ b/authentication/pom.xml @@ -5,7 +5,7 @@ io.mosip.authentication authentication-parent - 1.2.0.1-SNAPSHOT + 1.2.0.1-B4 pom id-authentication From 4504575c13eac598acdb1b1c277fad4d50e83a54 Mon Sep 17 00:00:00 2001 From: Keshav Mishra Date: Tue, 22 Aug 2023 13:49:01 +0530 Subject: [PATCH 4/8] Update push_trigger.yml Signed-off-by: Keshav Mishra --- .github/workflows/push_trigger.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_trigger.yml b/.github/workflows/push_trigger.yml index 06dc9e54c85..527a292428d 100644 --- a/.github/workflows/push_trigger.yml +++ b/.github/workflows/push_trigger.yml @@ -121,7 +121,7 @@ jobs: - name: Publish the maven package run: | - cd authentication && mvn deploy -DaltDeploymentRepository=ossrh::default::${{ secrets.RELEASE_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml + cd authentication && mvn deploy -DaltDeploymentRepository=ossrh::default::${{ secrets.OSSRH_SNAPSHOT_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} GPG_TTY: $(tty) From 6a13ab4d457ef1416c38229efa3bc06ef4341bbc Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Fri, 18 Aug 2023 20:16:47 +0530 Subject: [PATCH 5/8] WIP-Changes to allow available otp channel --- .../common/service/impl/OTPServiceImpl.java | 19 +++++++++++++++++-- .../service/impl/OTPServiceImplTest.java | 12 +++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java index 905d2b5371c..e6a89075dcb 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java @@ -224,6 +224,13 @@ private OtpResponseDTO doGenerateOTP(OtpRequestDTO otpRequestDto, String partner valueMap.put(IdAuthCommonConstants.PHONE_NUMBER, phoneNumber); valueMap.put(IdAuthCommonConstants.EMAIL, email); + if((phoneNumber == null || phoneNumber.isEmpty()) && (email == null || email.isEmpty())) { + throw new IdAuthenticationBusinessException( + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + + ". Both Phone Number and Email ID are not found in identity data."); + } + boolean isOtpGenerated = otpManager.sendOtp(otpRequestDto, individualId, individualIdType, valueMap, templateLanguages); @@ -321,9 +328,17 @@ private boolean isOtpFlooded(String token, String requestTime) throws IdAuthenti private void processChannel(String value, String phone, String email, MaskedResponseDTO maskedResponseDTO) throws IdAuthenticationBusinessException { if (value.equalsIgnoreCase(NotificationType.SMS.getChannel())) { - maskedResponseDTO.setMaskedMobile(MaskUtil.maskMobile(phone)); + if(phone != null && !phone.isEmpty()) { + maskedResponseDTO.setMaskedMobile(MaskUtil.maskMobile(phone)); + } else { + mosipLogger.warn("Phone Number is not available in identity data. But PHONE channel is requested for OTP."); + } } else if (value.equalsIgnoreCase(NotificationType.EMAIL.getChannel())) { - maskedResponseDTO.setMaskedEmail(MaskUtil.maskEmail(email)); + if(email != null && !email.isEmpty()) { + maskedResponseDTO.setMaskedEmail(MaskUtil.maskEmail(email)); + } else { + mosipLogger.warn("Email ID is not available in identity data. But email channel is requested for OTP."); + } } } diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java index 174ebec013f..2687322ba8f 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java @@ -226,12 +226,8 @@ public void TestPhonenumberisNull() throws IdAuthenticationBusinessException, Re otpRequestDto.setIndividualIdType(IdType.UIN.getType()); otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); Map valueMap = new HashMap<>(); - Map> idInfo = new HashMap<>(); - List mailList = new ArrayList<>(); - IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO(); - identityInfoDTO.setValue("abc@test.com"); - mailList.add(identityInfoDTO); - idInfo.put("email", mailList); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); valueMap.put("response", idInfo); Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) .thenReturn(valueMap); @@ -246,12 +242,14 @@ public void TestPhonenumberisNull() throws IdAuthenticationBusinessException, Re map.put("otp", "123456"); response.setResponse(map); Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); try { otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); } catch(IdAuthenticationBusinessException ex) { assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); - assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage(), ex.getErrorText()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); } } From 111f8b788e9dbfb0ab0d04052fc28ae760efc7b0 Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Mon, 21 Aug 2023 18:10:56 +0530 Subject: [PATCH 6/8] PSA-171 fix for allowing one of the available channels when both channels specified. --- .../common/service/impl/OTPServiceImpl.java | 17 +- .../service/impl/OTPServiceImplTest.java | 147 +++++++++++++++--- 2 files changed, 142 insertions(+), 22 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java index e6a89075dcb..69c057eda35 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java @@ -224,7 +224,22 @@ private OtpResponseDTO doGenerateOTP(OtpRequestDTO otpRequestDto, String partner valueMap.put(IdAuthCommonConstants.PHONE_NUMBER, phoneNumber); valueMap.put(IdAuthCommonConstants.EMAIL, email); - if((phoneNumber == null || phoneNumber.isEmpty()) && (email == null || email.isEmpty())) { + List otpChannel = otpRequestDto.getOtpChannel(); + if ((phoneNumber == null || phoneNumber.isEmpty()) && otpChannel.contains(PHONE) && !otpChannel.contains(EMAIL)) { + throw new IdAuthenticationBusinessException( + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + + ". Phone Number is not found in identity data."); + } + + if ((email == null || email.isEmpty()) && otpChannel.contains(EMAIL) && !otpChannel.contains(PHONE)) { + throw new IdAuthenticationBusinessException( + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), + IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + + ". Email ID is not found in identity data."); + } + + if((phoneNumber == null || phoneNumber.isEmpty()) && (email == null || email.isEmpty()) && (otpChannel.contains(PHONE) && otpChannel.contains(EMAIL))) { throw new IdAuthenticationBusinessException( IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java index 2687322ba8f..ceba1209f56 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -215,12 +216,12 @@ public void TestgenerateOtp() throws IdAuthenticationBusinessException, RestServ @SuppressWarnings("rawtypes") @Test - public void TestPhonenumberisNull() throws IdAuthenticationBusinessException, RestServiceException { + public void TestPhonenumberisNull_Phone_Channel_Alone() throws IdAuthenticationBusinessException, RestServiceException { OtpRequestDTO otpRequestDto = new OtpRequestDTO(); otpRequestDto.setId("id"); otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); otpRequestDto.setTransactionID("1234567890"); - ArrayList channelList = new ArrayList(); + List channelList = List.of("PHONE"); otpRequestDto.setOtpChannel(channelList); otpRequestDto.setIndividualId("2345678901234"); otpRequestDto.setIndividualIdType(IdType.UIN.getType()); @@ -246,20 +247,130 @@ public void TestPhonenumberisNull() throws IdAuthenticationBusinessException, Re Mockito.any())).thenReturn(true); try { otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); } catch(IdAuthenticationBusinessException ex) { assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); - assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Phone Number is not found in identity data.", ex.getErrorText()); } } - - @Test(expected = IdAuthenticationBusinessException.class) - public void TestPhoneorEmailisNull() throws IdAuthenticationBusinessException, RestServiceException { + + @SuppressWarnings("rawtypes") + @Test + public void TestPhonenumberisNull_bothChannels() throws IdAuthenticationBusinessException, RestServiceException { OtpRequestDTO otpRequestDto = new OtpRequestDTO(); otpRequestDto.setId("id"); otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); otpRequestDto.setTransactionID("1234567890"); - ArrayList channelList = new ArrayList(); + List channelList = List.of("PHONE", "EMAIL"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_Email_Channel_Alone() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("EMAIL"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9292292934"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } + catch(IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Email ID is not found in identity data.", ex.getErrorText()); + } + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_bothChannels() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("PHONE", "EMAIL"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9384848384"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @Test + public void TestPhoneorEmailisNull_both_channels_provided() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("PHONE", "EMAIL"); otpRequestDto.setOtpChannel(channelList); String individualId = "2345678901234"; otpRequestDto.setIndividualId(individualId); @@ -267,18 +378,6 @@ public void TestPhoneorEmailisNull() throws IdAuthenticationBusinessException, R otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); Map valueMap = new HashMap<>(); Map> idInfo = new HashMap<>(); - List mailList = new ArrayList<>(); - IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO(); - identityInfoDTO.setValue("abc@bc.com"); - mailList.add(identityInfoDTO); - List phoneList = new ArrayList<>(); - IdentityInfoDTO identityInfoDTO1 = new IdentityInfoDTO(); - identityInfoDTO1.setValue("9876543210"); - phoneList.add(identityInfoDTO1); - idInfo.put("email", mailList); - idInfo.put("mobile", phoneList); - valueMap.put("uin", "426789089018"); - valueMap.put("phone", "426789089018"); valueMap.put("response", idInfo); Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) .thenReturn(valueMap); @@ -301,7 +400,13 @@ public void TestPhoneorEmailisNull() throws IdAuthenticationBusinessException, R Mockito.when(restHelper.requestSync(Mockito.any())).thenThrow(new RestServiceException( IdRepoErrorConstants.CLIENT_ERROR, response.toString(), response)); - otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } catch (IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); + } } @Test(expected = IdAuthenticationBusinessException.class) @@ -361,7 +466,7 @@ private OtpRequestDTO getOtpRequestDTO() { // otpRequestDto.setRequestTime(new SimpleDateFormat(env.getDateTimePattern()).format(new Date())); otpRequestDto.setTransactionID("1234567890"); ArrayList channelList = new ArrayList(); - channelList.add("MOBILE"); + channelList.add("PHONE"); channelList.add("EMAIL"); otpRequestDto.setOtpChannel(channelList); otpRequestDto.setIndividualId("2345678901234"); From 48577e611b3e0748ce24a82b153a8277fe687bca Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Tue, 22 Aug 2023 15:09:41 +0530 Subject: [PATCH 7/8] Updated the pom versions --- authentication/authentication-authtypelockfilter-impl/pom.xml | 4 ++-- authentication/authentication-common/pom.xml | 4 ++-- authentication/authentication-core/pom.xml | 4 ++-- authentication/authentication-filter-api/pom.xml | 4 ++-- authentication/authentication-hotlistfilter-impl/pom.xml | 4 ++-- authentication/authentication-internal-service/pom.xml | 4 ++-- authentication/authentication-otp-service/pom.xml | 4 ++-- authentication/authentication-service/pom.xml | 4 ++-- authentication/esignet-integration-impl/pom.xml | 4 ++-- authentication/pom.xml | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/authentication/authentication-authtypelockfilter-impl/pom.xml b/authentication/authentication-authtypelockfilter-impl/pom.xml index 014a94ed228..6011019c896 100644 --- a/authentication/authentication-authtypelockfilter-impl/pom.xml +++ b/authentication/authentication-authtypelockfilter-impl/pom.xml @@ -4,9 +4,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-authtypelockfilter-impl authentication-authtypelockfilter-impl ID Authentication Filter Implementation for Auth Type Lock validation diff --git a/authentication/authentication-common/pom.xml b/authentication/authentication-common/pom.xml index 14631ac07fd..b6b70a4c080 100644 --- a/authentication/authentication-common/pom.xml +++ b/authentication/authentication-common/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-common authentication-common diff --git a/authentication/authentication-core/pom.xml b/authentication/authentication-core/pom.xml index a196bbd7de1..59f695eb73a 100644 --- a/authentication/authentication-core/pom.xml +++ b/authentication/authentication-core/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-core jar diff --git a/authentication/authentication-filter-api/pom.xml b/authentication/authentication-filter-api/pom.xml index bbb7acd4119..c8847d569d9 100644 --- a/authentication/authentication-filter-api/pom.xml +++ b/authentication/authentication-filter-api/pom.xml @@ -4,9 +4,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-filter-api authentication-filter-api ID Authentication Filter API diff --git a/authentication/authentication-hotlistfilter-impl/pom.xml b/authentication/authentication-hotlistfilter-impl/pom.xml index ffde65b2e93..99936202d2b 100644 --- a/authentication/authentication-hotlistfilter-impl/pom.xml +++ b/authentication/authentication-hotlistfilter-impl/pom.xml @@ -4,9 +4,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-hotlistfilter-impl authentication-hotlistfilter-impl ID Authentication Filter Implementation for Hotlist validation diff --git a/authentication/authentication-internal-service/pom.xml b/authentication/authentication-internal-service/pom.xml index 2c48adec6b0..168aa0c81ce 100644 --- a/authentication/authentication-internal-service/pom.xml +++ b/authentication/authentication-internal-service/pom.xml @@ -7,9 +7,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-internal-service authentication-internal-service diff --git a/authentication/authentication-otp-service/pom.xml b/authentication/authentication-otp-service/pom.xml index ffb017f5171..fdac93a0dce 100644 --- a/authentication/authentication-otp-service/pom.xml +++ b/authentication/authentication-otp-service/pom.xml @@ -7,9 +7,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-otp-service authentication-otp-service diff --git a/authentication/authentication-service/pom.xml b/authentication/authentication-service/pom.xml index e0f1882c870..93c76b6903c 100644 --- a/authentication/authentication-service/pom.xml +++ b/authentication/authentication-service/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT authentication-service jar diff --git a/authentication/esignet-integration-impl/pom.xml b/authentication/esignet-integration-impl/pom.xml index 57c7083efe0..07767904c57 100644 --- a/authentication/esignet-integration-impl/pom.xml +++ b/authentication/esignet-integration-impl/pom.xml @@ -6,9 +6,9 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT - + 1.2.0.1-B5-SNAPSHOT esignet-integration-impl esignet-integration-impl e-Signet Integration Implementation Library diff --git a/authentication/pom.xml b/authentication/pom.xml index 51e354d9fa4..a0787fd079d 100644 --- a/authentication/pom.xml +++ b/authentication/pom.xml @@ -5,7 +5,7 @@ io.mosip.authentication authentication-parent - 1.2.0.1-B4 + 1.2.0.1-B5-SNAPSHOT pom id-authentication From 96fbe42750453c23384f4c02e5acfe61f80f7e16 Mon Sep 17 00:00:00 2001 From: Loganathan Sekar Date: Thu, 24 Aug 2023 19:19:46 +0530 Subject: [PATCH 8/8] Fix to have case insensitive check for channel attribute --- .../common/service/impl/OTPServiceImpl.java | 17 +- .../service/impl/OTPServiceImplTest.java | 196 ++++++++++++++++++ 2 files changed, 207 insertions(+), 6 deletions(-) diff --git a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java index 69c057eda35..57fc40ffed2 100644 --- a/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java +++ b/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/impl/OTPServiceImpl.java @@ -51,6 +51,7 @@ import io.mosip.kernel.core.exception.ParseException; import io.mosip.kernel.core.logger.spi.Logger; import io.mosip.kernel.core.util.DateUtils; +import io.mosip.kernel.core.util.StringUtils; /** * Service implementation of OtpTriggerService. @@ -165,17 +166,21 @@ public OtpResponseDTO generateOtp(OtpRequestDTO otpRequestDto, String partnerId, private void validateAllowedOtpChannles(String token, List otpChannel) throws IdAuthenticationFilterException { - if(otpChannel.stream().anyMatch(channel -> OTP.equalsIgnoreCase(channel))) { + if(containsChannel(otpChannel, OTP)) { checkAuthLock(token, OTP); } - else if(otpChannel.stream().anyMatch(channel -> PHONE.equalsIgnoreCase(channel))) { + else if(containsChannel(otpChannel, PHONE)) { checkAuthLock(token, OTP_SMS); } - else if(otpChannel.stream().anyMatch(channel -> EMAIL.equalsIgnoreCase(channel))) { + else if(containsChannel(otpChannel, EMAIL)) { checkAuthLock(token, OTP_EMAIL); } } + private static boolean containsChannel(List otpChannel, String channel) { + return otpChannel.stream().anyMatch(channelItem -> channel.equalsIgnoreCase(channelItem)); + } + private void checkAuthLock(String token, String authTypeCode) throws IdAuthenticationFilterException { List authTypeLocks = authLockRepository.findByTokenAndAuthtypecode(token, authTypeCode); for(AuthtypeLock authtypeLock : authTypeLocks) { @@ -225,21 +230,21 @@ private OtpResponseDTO doGenerateOTP(OtpRequestDTO otpRequestDto, String partner valueMap.put(IdAuthCommonConstants.EMAIL, email); List otpChannel = otpRequestDto.getOtpChannel(); - if ((phoneNumber == null || phoneNumber.isEmpty()) && otpChannel.contains(PHONE) && !otpChannel.contains(EMAIL)) { + if (StringUtils.isBlank(phoneNumber) && containsChannel(otpChannel, PHONE) && !containsChannel(otpChannel, EMAIL)) { throw new IdAuthenticationBusinessException( IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Phone Number is not found in identity data."); } - if ((email == null || email.isEmpty()) && otpChannel.contains(EMAIL) && !otpChannel.contains(PHONE)) { + if (StringUtils.isBlank(email) && containsChannel(otpChannel, EMAIL) && !containsChannel(otpChannel, PHONE)) { throw new IdAuthenticationBusinessException( IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Email ID is not found in identity data."); } - if((phoneNumber == null || phoneNumber.isEmpty()) && (email == null || email.isEmpty()) && (otpChannel.contains(PHONE) && otpChannel.contains(EMAIL))) { + if(StringUtils.isBlank(phoneNumber) && StringUtils.isBlank(email) && (containsChannel(otpChannel, PHONE) && containsChannel(otpChannel, EMAIL))) { throw new IdAuthenticationBusinessException( IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java index ceba1209f56..6fd9a568fa2 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/OTPServiceImplTest.java @@ -408,6 +408,202 @@ public void TestPhoneorEmailisNull_both_channels_provided() throws IdAuthenticat assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); } } + + + @SuppressWarnings("rawtypes") + @Test + public void TestPhonenumberisNull_Phone_Channel_Alone_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } + catch(IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Phone Number is not found in identity data.", ex.getErrorText()); + } + } + + @SuppressWarnings("rawtypes") + @Test + public void TestPhonenumberisNull_bothChannels_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone", "email"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("email", "abc@test.com"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_Email_Channel_Alone_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("email"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9292292934"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } + catch(IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Email ID is not found in identity data.", ex.getErrorText()); + } + } + + @SuppressWarnings("rawtypes") + @Test + public void TestEmailIdisNull_bothChannels_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone", "email"); + otpRequestDto.setOtpChannel(channelList); + otpRequestDto.setIndividualId("2345678901234"); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map idInfo = new HashMap<>(); + idInfo.put("phone", "9384848384"); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn("2345678901234"); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + Map map = new HashMap<>(); + map.put("otp", "123456"); + response.setResponse(map); + Mockito.when(restHelper.requestSync(Mockito.any())).thenReturn(response); + Mockito.when(otpManager.sendOtp(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any())).thenReturn(true); + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + } + + @Test + public void TestPhoneorEmailisNull_both_channels_provided_lowercase() throws IdAuthenticationBusinessException, RestServiceException { + OtpRequestDTO otpRequestDto = new OtpRequestDTO(); + otpRequestDto.setId("id"); + otpRequestDto.setRequestTime(new SimpleDateFormat(EnvUtil.getDateTimePattern()).format(new Date())); + otpRequestDto.setTransactionID("1234567890"); + List channelList = List.of("phone", "email"); + otpRequestDto.setOtpChannel(channelList); + String individualId = "2345678901234"; + otpRequestDto.setIndividualId(individualId); + otpRequestDto.setIndividualIdType(IdType.UIN.getType()); + otpRequestDto.setRequestTime("2019-02-18T18:17:48.923+05:30"); + Map valueMap = new HashMap<>(); + Map> idInfo = new HashMap<>(); + valueMap.put("response", idInfo); + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(idAuthService.getToken(Mockito.any())).thenReturn(individualId); + Mockito.when(autntxnrepository.countRequestDTime(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1); + RestRequestDTO value = getRestDto(); + Mockito.when(restRequestFactory.buildRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(value); + ResponseWrapper response = new ResponseWrapper<>(); + List errors = new ArrayList<>(); + ServiceError serviceError = new ServiceError(); + serviceError.setErrorCode(OtpErrorConstants.EMAILPHONENOTREGISTERED.getErrorCode()); + serviceError.setMessage(OtpErrorConstants.EMAILPHONENOTREGISTERED.getErrorMessage()); + errors.add(serviceError); + response.setErrors(errors); + + Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet())) + .thenReturn(valueMap); + Mockito.when(uinHashSaltRepo.retrieveSaltById(Mockito.anyInt())).thenReturn("2344"); + Mockito.when(idAuthSecurityManager.getUser()).thenReturn("ida_app_user"); + + Mockito.when(restHelper.requestSync(Mockito.any())).thenThrow(new RestServiceException( + IdRepoErrorConstants.CLIENT_ERROR, response.toString(), response)); + try { + otpServiceImpl.generateOtp(otpRequestDto, "1234567890", new TestObjectWithMetadata()); + Assert.fail(); + } catch (IdAuthenticationBusinessException ex) { + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorCode(), ex.getErrorCode()); + assertEquals(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED.getErrorMessage() + ". Both Phone Number and Email ID are not found in identity data.", ex.getErrorText()); + } + } @Test(expected = IdAuthenticationBusinessException.class) public void TestOtpFloodException() throws IdAuthenticationBusinessException {