Skip to content

Commit

Permalink
Merge pull request #1086 from mosip/release-1.2.0.1-B5
Browse files Browse the repository at this point in the history
[PSA-171] Merge Release-1.2.0.1-B5
  • Loading branch information
mahammedtaheer authored Sep 8, 2023
2 parents 9498f50 + 301d42d commit 8ba1ea0
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 55 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-SNAPSHOT</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-SNAPSHOT</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-SNAPSHOT</version>
<version>1.2.0.1-B5-SNAPSHOT</version>
</parent>
<version>1.2.0.1-SNAPSHOT</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 @@ -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.
Expand Down Expand Up @@ -165,17 +166,21 @@ public OtpResponseDTO generateOtp(OtpRequestDTO otpRequestDto, String partnerId,

private void validateAllowedOtpChannles(String token, List<String> 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<String> otpChannel, String channel) {
return otpChannel.stream().anyMatch(channelItem -> channel.equalsIgnoreCase(channelItem));
}

private void checkAuthLock(String token, String authTypeCode) throws IdAuthenticationFilterException {
List<AuthtypeLock> authTypeLocks = authLockRepository.findByTokenAndAuthtypecode(token, authTypeCode);
for(AuthtypeLock authtypeLock : authTypeLocks) {
Expand Down Expand Up @@ -224,6 +229,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 (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 (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(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()
+ ". 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 +348,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
Loading

0 comments on commit 8ba1ea0

Please sign in to comment.