Skip to content

Commit

Permalink
Merge develop to 1.2.0 rc2 6 (#646)
Browse files Browse the repository at this point in the history
* Added default filter attributes to configuration (#596)

* Added default filter attributes to configuration

* Code updated

* Mosip 18119 auto allow new dynamic attributes for authentication (#598)

* Fixes in demo auth dynamic attributes

* Fixed error message for decoding failure

* Fix in fetching postal code for auth anonym profile

* WIP for dynamic attribute auto match

* Allow new dynamic attrib for auth without mapping

* Removed unwanted comment

* Fix age not match err msg (#599)

* Fixes in demo auth dynamic attributes

* Fixed error message for decoding failure

* Fix in fetching postal code for auth anonym profile

* WIP for dynamic attribute auto match

* Allow new dynamic attrib for auth without mapping

* Removed unwanted comment

* Fix in age not match error msg

* Fix bio auth type check issue due to case sensitive check (#600)

* Fix bio auth type check issue due to case sensitive check

* Minor fix

* junit test cases for AuthAnonymousProfileServiceImpl.java (#604)

* Mosip 18252 dsl bio auth fix (#609)

* Fix bio auth type check issue due to case sensitive check

* Minor fix

* Added missing Face for ekyc request in filter

* Fixed otp kyc filter NPE issue due to null bio (#615)

* Fixed multi modal auth cbeff load issue (#617)

* Fixed ekyc face retrival issue (#619)

* MOSIP-18366,MOSIP-18370 bio type subtype error message correction (#621)

* Fixed biotype,biosubtype related error messages

* Fix NPE for null idtype

* Test fixes

* Revert debug code for idserviceimpl

* test cases updated (#620)

* IdInfoHelper Test cases updated (#623)

* Fix dynamic attribute language code issue (#624)

* KycController updated with test cases (#625)

* Fixed test case failure (#626)

* updated test cases (#627)

* Revert "updated test cases" (#628)

This reverts commit 5cb0b79758ede70509ff7e0cbe864e9589434cff.

* Mosip 18411,MOSIP-17587 fix filter attrip for ekyc (#632)

* Fixed keymanager bean loading issue

* MOSIP-18411 fixed kyc attribute filtered out issue

* MOSIP-17587-Fix status for ekyc auth in anonym profile

* Mosip 18191 fix bio auth segment timestamp validation issue (#633)

* Fix duplicate type code in kyc auth txn entry

* MOSIP-18191 fix segment timestamp validation not working

* Added null check for auth type code duplicate condition

* MOSIP-18265 Added column to key alias table (#638)

* CredentialServiceImplTest (#636)

Co-authored-by: Vipul Dhurve <[email protected]>

* MOSIP-18053-fixed duplicate match inputs for multiple dynamic attrib in auth req (#640)

* MOSIP-18053-fixed duplicate match inputs for multiple dynamic attrib in req

* added jdoc

* [MOSIP-18119] Updated Notification timestamp based on timezone in prop (#641)

* [MOSIP-18119] Updated Notification timestamp based on timezone in prop (#643)

* [MOSIP-18119] Updated Notification timestamp based on timezone in prop

* [MOSIP-18119] Fixed test case failures

* Removed unnecessary db call (#645)

Co-authored-by: Nagarjuna K <[email protected]>
Co-authored-by: mamta-344 <[email protected]>
Co-authored-by: rambhatt1591 <[email protected]>
Co-authored-by: vipuldhurve02 <[email protected]>
Co-authored-by: Vipul Dhurve <[email protected]>
Co-authored-by: Manoj SP <[email protected]>
  • Loading branch information
7 people authored Nov 16, 2021
1 parent cca044f commit 0643be6
Show file tree
Hide file tree
Showing 24 changed files with 1,894 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ public AutnTxn build(Environment env, IdaUinHashSaltRepo uinHashSaltRepo,
autnTxn.setStatusCode(status);

if (!requestTypes.isEmpty()) {
String authTypeCodes = requestTypes.stream().map(RequestType::getRequestType)
String authTypeCodes = requestTypes.stream()
.map(RequestType::getRequestType)
.collect(Collectors.joining(REQ_TYPE_DELIM));
autnTxn.setAuthTypeCode(authTypeCodes);

String requestTypeMessages = requestTypes.stream().map(RequestType::getMessage)
String requestTypeMessages = requestTypes.stream()
.map(RequestType::getMessage)
.collect(Collectors.joining(REQ_TYPE_MSG_DELIM));
String comment = isStatus ? requestTypeMessages + " Success" : requestTypeMessages + " Failed";
autnTxn.setStatusComment(comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public List<MatchInput> buildMatchInput(AuthRequestDTO authRequestDTO, AuthType[

}
return matchInputs.stream();
}).filter(Objects::nonNull).collect(Collectors.toList());
})
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static io.mosip.authentication.core.constant.AuthTokenType.RANDOM;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -46,6 +47,7 @@
import io.mosip.authentication.core.indauth.dto.AuthStatusInfo;
import io.mosip.authentication.core.indauth.dto.IdType;
import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO;
import io.mosip.authentication.core.indauth.dto.KycAuthRequestDTO;
import io.mosip.authentication.core.logger.IdaLogger;
import io.mosip.authentication.core.partner.dto.PartnerPolicyResponseDTO;
import io.mosip.authentication.core.partner.dto.PolicyDTO;
Expand Down Expand Up @@ -147,10 +149,16 @@ public AuthResponseDTO authenticateIndividual(AuthRequestDTO authRequestDTO, boo
Set<String> filterAttributes = new HashSet<>();
filterAttributes.addAll(idInfoHelper.buildDemoAttributeFilters(authRequestDTO));
filterAttributes.addAll(idInfoHelper.buildBioFilters(authRequestDTO));
// In case of ekyc request and photo also needed we need to add face to get it
// filtered
if(idInfoHelper.containsPhotoKYCAttribute(authRequestDTO)) {
filterAttributes.add(CbeffDocType.FACE.getType().value());

if(authRequestDTO instanceof KycAuthRequestDTO) {
KycAuthRequestDTO kycAuthRequestDTO = (KycAuthRequestDTO) authRequestDTO;
// In case of ekyc request and photo also needed we need to add face to get it
// filtered
if(idInfoHelper.isKycAttributeHasPhoto(kycAuthRequestDTO)) {
filterAttributes.add(CbeffDocType.FACE.getType().value());
}

addKycPolicyAttributes(filterAttributes, kycAuthRequestDTO);
}

Map<String, Object> idResDTO = idService.processIdType(idvIdType, idvid, idInfoHelper.isBiometricDataNeeded(authRequestDTO),
Expand Down Expand Up @@ -223,6 +231,20 @@ public AuthResponseDTO authenticateIndividual(AuthRequestDTO authRequestDTO, boo

}

private void addKycPolicyAttributes(Set<String> filterAttributes, KycAuthRequestDTO kycAuthRequestDTO)
throws IdAuthenticationBusinessException {
List<String> allowedKycAttributes = kycAuthRequestDTO.getAllowedKycAttributes();
if(allowedKycAttributes != null && !allowedKycAttributes.isEmpty()) {
for (String attrib : allowedKycAttributes) {
filterAttributes.addAll(getIdSchemaAttributes(attrib));
}
}
}

private Collection<? extends String> getIdSchemaAttributes(String attrib) throws IdAuthenticationBusinessException {
return idInfoHelper.getIdentityAttributesForIdName(attrib);
}

private String getToken(AuthRequestDTO authRequestDTO, String partnerId, String partnerApiKey, String idvid,
String token) throws IdAuthenticationBusinessException {
Optional<PartnerPolicyResponseDTO> policyForPartner = partnerService.getPolicyForPartner(partnerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public Map<String, String> getIdEntityInfoMap(MatchType matchType, Map<String, L
*/
public Map<String, String> getIdEntityInfoMap(MatchType matchType, Map<String, List<IdentityInfoDTO>> identityInfos,
String language, String idName) throws IdAuthenticationBusinessException {
List<String> propertyNames = getPropertyNamesForMatchType(matchType, idName);
List<String> propertyNames = getIdentityAttributesForMatchType(matchType, idName);
Map<String, String> identityValuesMap = new LinkedHashMap<>();
Map<String, String> identityValuesMapWithLang = getIdentityValuesMap(matchType, propertyNames, language, identityInfos);
Map<String, String> identityValuesMapWithoutLang = getIdentityValuesMap(matchType, propertyNames, null, identityInfos);
Expand Down Expand Up @@ -601,7 +601,7 @@ public Set<String> buildDemoAttributeFilters(AuthRequestDTO authRequestDTO)
.collect(Collectors.toList());
for (String attrib : inputMappedAttributes) {
if(!attrib.equals(IdAuthCommonConstants.METADATA)) {
demoAttributesFromReq.addAll(getPropertyNamesForIdName(attrib, false));
demoAttributesFromReq.addAll(getIdentityAttributesForIdName(attrib, false));
}
}

Expand All @@ -611,7 +611,7 @@ public Set<String> buildDemoAttributeFilters(AuthRequestDTO authRequestDTO)
Set<String> inputUnmappedAttributes = dynamicAttributes.keySet();
for (String attrib : inputUnmappedAttributes) {
if(dynamicAttributes.get(attrib) != null) {
demoAttributesFromReq.addAll(getPropertyNamesForIdName(attrib, true));
demoAttributesFromReq.addAll(getIdentityAttributesForIdName(attrib, true));
}
}
}
Expand Down Expand Up @@ -751,7 +751,7 @@ private List<String> getIrisSubTypes(BiometricType type){
* @param idName the id name
* @return the property names for match type
*/
public List<String> getPropertyNamesForMatchType(MatchType matchType, String idName) {
public List<String> getIdentityAttributesForMatchType(MatchType matchType, String idName) {
String propertyName = idName != null ? idName : matchType.getIdMapping().getIdname();
List<String> propertyNames;
if (!matchType.isDynamic()) {
Expand All @@ -777,26 +777,35 @@ public List<String> getPropertyNamesForMatchType(MatchType matchType, String idN
return propertyNames;
}

public List<String> getIdentityAttributesForIdName(String idName)
throws IdAuthenticationBusinessException {
boolean isDynamic = idMappingConfig.getDynamicAttributes().keySet().contains(idName);
return getIdentityAttributesForIdName(idName, isDynamic);
}

/**
* Gets the property names for id name.
* Gets the identity attributes for id name.
*
* @param idName the id name
* @param isDynamic the is dynamic
* @return the property names for id name
* @throws IdAuthenticationBusinessException the id authentication business exception
*/
public List<String> getPropertyNamesForIdName(String idName, boolean isDynamic)
public List<String> getIdentityAttributesForIdName(String idName, boolean isDynamic)
throws IdAuthenticationBusinessException {
DemoMatchType[] demoMatchTypes = DemoMatchType.values();
List<String> propNames = new ArrayList<>();
for (DemoMatchType demoMatchType : demoMatchTypes) {
if(isDynamic == demoMatchType.isDynamic()) {
List<String> propertyNamesForMatchType = this.getPropertyNamesForMatchType(demoMatchType, idName);
List<String> propertyNamesForMatchType = this.getIdentityAttributesForMatchType(demoMatchType, idName);
if(!propertyNamesForMatchType.isEmpty()) {
propNames.addAll(propertyNamesForMatchType);
}
}
}
if(propNames.isEmpty()) {
propNames.add(idName);
}
return propNames;
}

Expand All @@ -806,7 +815,11 @@ public boolean isBiometricDataNeeded(AuthRequestDTO authRequestDTO) {

public boolean containsPhotoKYCAttribute(AuthRequestDTO authRequestDTO) {
return (authRequestDTO instanceof KycAuthRequestDTO)
&& Optional.ofNullable(((KycAuthRequestDTO) authRequestDTO).getAllowedKycAttributes()).orElse(List.of())
.contains(IdAuthCommonConstants.PHOTO);
&& isKycAttributeHasPhoto((KycAuthRequestDTO) authRequestDTO);
}

public boolean isKycAttributeHasPhoto(KycAuthRequestDTO authRequestDTO) {
return Optional.ofNullable(authRequestDTO.getAllowedKycAttributes()).orElse(List.of())
.contains(IdAuthCommonConstants.PHOTO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.DIGITAL_ID;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.FAILURE;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.IDA;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.KYC_STATUS;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.QUALITY_SCORE;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.REQUEST;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.RESPONSE;
Expand Down Expand Up @@ -283,10 +284,18 @@ private Map<String, List<IdentityInfoDTO>> getMapOfIdentityInfoDTOList(Map<Strin
return Map.of();
}

@SuppressWarnings("unchecked")
private void setStatus(Map<String, Object> responseBody, AnonymousAuthenticationProfile ananymousProfile) {
String status;
if(responseBody != null && responseBody.get(RESPONSE) instanceof Map) {
status = String.valueOf(((Map<String, Object>)responseBody.get(RESPONSE)).get(AUTH_STATUS));
String statusKey;
if (responseBody.get(IdAuthCommonConstants.ID) == null || !responseBody.get(IdAuthCommonConstants.ID).equals(env.getProperty(IdAuthConfigKeyConstants.MOSIP_IDA_API_ID_KYC))) {
statusKey = AUTH_STATUS;
} else {
statusKey = KYC_STATUS;
}
Map<String, Object> responseMap = (Map<String, Object>)responseBody.get(RESPONSE);
status = String.valueOf(responseMap.get(statusKey));
} else {
status = String.valueOf(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public boolean isMultiLanguage(String propName, Map<String, List<IdentityInfoDTO
//Otherwise use the property name itself to fetch the record
infoDtos = identityEntity.get(propName);
}
if (infoDtos != null && infoDtos.stream().anyMatch(infoDto -> infoDto.getLanguage() == null)) {
if (infoDtos == null || infoDtos.stream().anyMatch(infoDto -> infoDto.getLanguage() == null)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -108,8 +109,9 @@ public boolean sendOtp(OtpRequestDTO otpRequestDTO, String idvid, String idvidTy
+ environment.getProperty(IdAuthConfigKeyConstants.KEY_SPLITTER) + otpRequestDTO.getTransactionID()
+ environment.getProperty(IdAuthConfigKeyConstants.KEY_SPLITTER) + otp).getBytes());

if (otpRepo.existsByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS)) {
OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS);
Optional<OtpTransaction> otpTxnOpt = otpRepo.findByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS);
if (otpTxnOpt.isPresent()) {
OtpTransaction otpTxn = otpTxnOpt.get();
otpTxn.setOtpHash(otpHash);
otpTxn.setUpdBy(securityManager.getUser());
otpTxn.setUpdDTimes(DateUtils.getUTCCurrentDateTime());
Expand Down Expand Up @@ -240,8 +242,10 @@ public boolean validateOtp(String pinValue, String otpKey) throws IdAuthenticati
String otpHash;
otpHash = IdAuthSecurityManager.digestAsPlainText(
(otpKey + environment.getProperty(IdAuthConfigKeyConstants.KEY_SPLITTER) + pinValue).getBytes());
if (otpRepo.existsByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS)) {
OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS);
Optional<OtpTransaction> otpTxnOpt = otpRepo.findByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS);
if (otpTxnOpt.isPresent()) {
OtpTransaction otpTxn = otpTxnOpt.get();
//OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, IdAuthCommonConstants.ACTIVE_STATUS);
otpTxn.setStatusCode(IdAuthCommonConstants.USED_STATUS);
otpRepo.save(otpTxn);
if (otpTxn.getExpiryDtimes().isAfter(DateUtils.getUTCCurrentDateTime())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package io.mosip.authentication.common.service.repository;

import java.util.Optional;

import io.mosip.authentication.common.service.entity.OtpTransaction;
import io.mosip.kernel.core.dataaccess.spi.repository.BaseRepository;

/**
* @author Manoj SP
* The Interface OtpTxnRepository.
*
* @author Manoj SP
*/
public interface OtpTxnRepository extends BaseRepository<OtpTransaction, String> {

Boolean existsByOtpHashAndStatusCode(String otpHash, String statusCode);

OtpTransaction findByOtpHashAndStatusCode(String otpHash, String statusCode);
/**
* Find by otp hash and status code.
*
* @param otpHash the otp hash
* @param statusCode the status code
* @return the optional
*/
Optional<OtpTransaction> findByOtpHashAndStatusCode(String otpHash, String statusCode);

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ private void validateSuccessiveBioSegmentTimestamp(List<BioIdentityInfoDTO> biom
this.biometricTimestampParser(bioIdentityInfoDTO.getData().getTimestamp()));
LocalDateTime previousIndexDateTime = DateUtils.parseDateToLocalDateTime(
this.biometricTimestampParser((biometrics.get(index - 1).getData().getTimestamp())));
long bioTimestampDiffInSeconds = Duration.between(currentIndexDateTime, previousIndexDateTime).toSeconds();
long bioTimestampDiffInSeconds = Duration.between(previousIndexDateTime, currentIndexDateTime).toSeconds();

Long allowedTimeDiffInSeconds = env.getProperty(IdAuthConfigKeyConstants.BIO_SEGMENT_TIME_DIFF_ALLOWED, Long.class, 120L);
if (bioTimestampDiffInSeconds > allowedTimeDiffInSeconds) {
if (bioTimestampDiffInSeconds < 0 || bioTimestampDiffInSeconds > allowedTimeDiffInSeconds) {
mosipLogger.error(SESSION_ID, this.getClass().getSimpleName(), VALIDATE,
IdAuthenticationErrorConstants.INVALID_BIO_TIMESTAMP);
errors.rejectValue(IdAuthCommonConstants.REQUEST,
Expand All @@ -219,8 +220,8 @@ protected void validateSuccessiveDigitalIdTimestamp(List<BioIdentityInfoDTO> bio
this.biometricTimestampParser(bioIdentityInfoDTO.getData().getDigitalId().getDateTime()));
LocalDateTime previousIndexDateTime = DateUtils.parseDateToLocalDateTime(
this.biometricTimestampParser(biometrics.get(index - 1).getData().getDigitalId().getDateTime()));
long digitalIdTimestampDiffInSeconds = Duration.between(currentIndexDateTime, previousIndexDateTime).toSeconds();
if (digitalIdTimestampDiffInSeconds > allowedTimeDiffInSeconds) {
long digitalIdTimestampDiffInSeconds = Duration.between(previousIndexDateTime, currentIndexDateTime).toSeconds();
if (digitalIdTimestampDiffInSeconds < 0 || digitalIdTimestampDiffInSeconds > allowedTimeDiffInSeconds) {
mosipLogger.error(SESSION_ID, this.getClass().getSimpleName(), VALIDATE,
IdAuthenticationErrorConstants.INVALID_BIO_DIGITALID_TIMESTAMP);
errors.rejectValue(IdAuthCommonConstants.REQUEST,
Expand Down
Loading

0 comments on commit 0643be6

Please sign in to comment.