Skip to content

Commit

Permalink
Merge pull request #1071 from LoganathanSekar7627/PSA-171-IDA-allow-a…
Browse files Browse the repository at this point in the history
…ny-one-channel-fix-release-1.2.0.1-B5

PSA-171 IDA allow any one channel fix release 1.2.0.1 b5
  • Loading branch information
mahammedtaheer authored Aug 22, 2023
2 parents 4504575 + 48577e6 commit 1caf8d3
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 48 deletions.
4 changes: 2 additions & 2 deletions authentication/authentication-authtypelockfilter-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>authentication-authtypelockfilter-impl</artifactId>
<name>authentication-authtypelockfilter-impl</name>
<description>ID Authentication Filter Implementation for Auth Type Lock validation</description>
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>authentication-common</artifactId>
<name>authentication-common</name>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ private OtpResponseDTO doGenerateOTP(OtpRequestDTO otpRequestDto, String partner
valueMap.put(IdAuthCommonConstants.PHONE_NUMBER, phoneNumber);
valueMap.put(IdAuthCommonConstants.EMAIL, email);

List<String> 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()
+ ". Both Phone Number and Email ID are not found in identity data.");
}

boolean isOtpGenerated = otpManager.sendOtp(otpRequestDto, individualId, individualIdType, valueMap,
templateLanguages);

Expand Down Expand Up @@ -321,9 +343,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.");
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,23 +216,19 @@ 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<String> channelList = new ArrayList<String>();
List<String> 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<String, Object> valueMap = new HashMap<>();
Map<String, List<IdentityInfoDTO>> idInfo = new HashMap<>();
List<IdentityInfoDTO> mailList = new ArrayList<>();
IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO();
identityInfoDTO.setValue("[email protected]");
mailList.add(identityInfoDTO);
idInfo.put("email", mailList);
Map<String, Object> idInfo = new HashMap<>();
idInfo.put("email", "[email protected]");
valueMap.put("response", idInfo);
Mockito.when(idAuthService.processIdType(Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anySet()))
.thenReturn(valueMap);
Expand All @@ -246,41 +243,141 @@ 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());
Assert.fail();
}
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() + ". 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<String> channelList = new ArrayList<String>();
List<String> 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<String, Object> valueMap = new HashMap<>();
Map<String, Object> idInfo = new HashMap<>();
idInfo.put("email", "[email protected]");
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<Map> response = new ResponseWrapper<>();
Map<String, Object> 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<String> 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<String, Object> valueMap = new HashMap<>();
Map<String, Object> 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<Map> response = new ResponseWrapper<>();
Map<String, Object> 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<String> 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<String, Object> valueMap = new HashMap<>();
Map<String, Object> 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<Map> response = new ResponseWrapper<>();
Map<String, Object> 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<String> 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<String, Object> valueMap = new HashMap<>();
Map<String, List<IdentityInfoDTO>> idInfo = new HashMap<>();
List<IdentityInfoDTO> mailList = new ArrayList<>();
IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO();
identityInfoDTO.setValue("[email protected]");
mailList.add(identityInfoDTO);
List<IdentityInfoDTO> 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);
Expand All @@ -303,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)
Expand Down Expand Up @@ -363,7 +466,7 @@ private OtpRequestDTO getOtpRequestDTO() {
// otpRequestDto.setRequestTime(new SimpleDateFormat(env.getDateTimePattern()).format(new Date()));
otpRequestDto.setTransactionID("1234567890");
ArrayList<String> channelList = new ArrayList<String>();
channelList.add("MOBILE");
channelList.add("PHONE");
channelList.add("EMAIL");
otpRequestDto.setOtpChannel(channelList);
otpRequestDto.setIndividualId("2345678901234");
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>

<artifactId>authentication-core</artifactId>
<packaging>jar</packaging>
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-filter-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>authentication-filter-api</artifactId>
<name>authentication-filter-api</name>
<description>ID Authentication Filter API</description>
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-hotlistfilter-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>authentication-hotlistfilter-impl</artifactId>
<name>authentication-hotlistfilter-impl</name>
<description>ID Authentication Filter Implementation for Hotlist validation</description>
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-internal-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>authentication-internal-service</artifactId>
<name>authentication-internal-service</name>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-otp-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>authentication-otp-service</artifactId>
<name>authentication-otp-service</name>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions authentication/authentication-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>

<artifactId>authentication-service</artifactId>
<packaging>jar</packaging>
Expand Down
4 changes: 2 additions & 2 deletions authentication/esignet-integration-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<parent>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>

<version>1.2.0.1-B5-SNAPSHOT</version>
<artifactId>esignet-integration-impl</artifactId>
<name>esignet-integration-impl</name>
<description>e-Signet Integration Implementation Library</description>
Expand Down
2 changes: 1 addition & 1 deletion authentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-parent</artifactId>
<version>1.2.0.1-B4</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
<packaging>pom</packaging>

<name>id-authentication</name>
Expand Down

0 comments on commit 1caf8d3

Please sign in to comment.