Skip to content

Commit

Permalink
Merge pull request #907 from LoganathanSekar7627/MOSIP-23889-fix-issu…
Browse files Browse the repository at this point in the history
…e-with-minutiae

MOSIP-23889, PSA-146  fix issue in bio auth with minutiae in gallery
  • Loading branch information
nayakrounak authored Sep 16, 2022
2 parents bddea59 + dfeccfe commit 3a0681a
Show file tree
Hide file tree
Showing 19 changed files with 2,227 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ private List<MatchInput> buildMatchInput(AuthRequestDTO authRequestDTO, MatchTyp
.collect(Collectors.toList());
} else {
if(idInfoFetcher.getIdentityRequestInfo(matchType, identity, language).size() > 0) {
return List.of(contstructMatchInput(authRequestDTO, matchType.getIdMapping().getIdname(), matchType, authType, language));
MatchInput matchInput = contstructMatchInput(authRequestDTO, matchType.getIdMapping().getIdname(), matchType, authType, language);
return matchInput == null ? List.of() : List.of(matchInput);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.mosip.authentication.common.service.impl;

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -10,6 +9,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -27,6 +27,7 @@
import io.mosip.authentication.core.constant.IdAuthCommonConstants;
import io.mosip.authentication.core.constant.IdAuthConfigKeyConstants;
import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants;
import io.mosip.authentication.core.exception.IdAuthUncheckedException;
import io.mosip.authentication.core.exception.IdAuthenticationBusinessException;
import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO;
import io.mosip.authentication.core.indauth.dto.LanguageType;
Expand All @@ -43,6 +44,10 @@
import io.mosip.authentication.core.spi.indauth.match.TriFunctionWithBusinessException;
import io.mosip.authentication.core.spi.indauth.match.ValidateOtpFunction;
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.core.cbeffutil.entity.BDBInfo;
import io.mosip.kernel.core.cbeffutil.entity.BIR;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.BDBInfoType;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.BIRType;
import io.mosip.kernel.core.cbeffutil.spi.CbeffUtil;
import io.mosip.kernel.core.logger.spi.Logger;

Expand Down Expand Up @@ -269,8 +274,8 @@ public Map<String, Entry<String, List<IdentityInfoDTO>>> getCbeffValues(Map<Stri
for (String bioAttribute : identityBioAttributes) {
Optional<String> identityValue = getIdentityValue(bioAttribute, null, idEntity).findAny();
if (!identityValue.isEmpty()) {
logger.info(String.format("getCbeffValues: %s value is \n%s", bioAttribute, identityValue.get()));
cbeffValuesForTypes.putAll(getCbeffValuesForCbeffDocType(type, matchType, identityValue));
logger.debug(String.format("getCbeffValues: %s value is \n%s", bioAttribute, identityValue.get()));
cbeffValuesForTypes.putAll(getCbeffValuesForCbeffDocType(type, matchType, identityValue.get()));
} else {
throw new IdAuthenticationBusinessException(
IdAuthenticationErrorConstants.BIOMETRIC_MISSING.getErrorCode(), String.format(
Expand All @@ -286,27 +291,49 @@ public Map<String, Entry<String, List<IdentityInfoDTO>>> getCbeffValues(Map<Stri
*
* @param type the type
* @param matchType the match type
* @param identityValue the identity value
* @param biometricCbeff the identity value
* @return the cbeff values for cbeff doc type
* @throws IdAuthenticationBusinessException the id authentication business exception
*/
private Map<String, Entry<String, List<IdentityInfoDTO>>> getCbeffValuesForCbeffDocType(CbeffDocType type,
MatchType matchType, Optional<String> identityValue) throws IdAuthenticationBusinessException {
Map<String, String> bdbBasedOnType;
MatchType matchType, String biometricCbeff) throws IdAuthenticationBusinessException {
Map<String, String> birBasedOnType;
try {
bdbBasedOnType = cbeffUtil.getBDBBasedOnType(identityValue.get().getBytes(), type.getName(),
null);
List<BIRType> birDataFromXMLType = cbeffUtil.getBIRDataFromXMLType(biometricCbeff.getBytes(), type.getName());
Function<? super BIRType, ? extends String> keyFunction = bir -> {
BDBInfoType bdbInfo = bir.getBDBInfo();
return bdbInfo.getType().get(0).toString() + "_"
+ (bdbInfo.getSubtype() == null || bdbInfo.getSubtype().isEmpty()? "" : bdbInfo.getSubtype().get(0))
+ (bdbInfo.getSubtype().size() > 1 ? " " + bdbInfo.getSubtype().get(1) : "") + "_"
+ bdbInfo.getFormat().getType();
};
if(birDataFromXMLType.size() == 1) {
//This is the segmented cbeff
//This is the most possible case
birBasedOnType = birDataFromXMLType.stream().collect(Collectors.toMap(keyFunction, bir -> biometricCbeff));
} else if(birDataFromXMLType.isEmpty()) {
//This is unlikely
birBasedOnType = Collections.emptyMap();
} else {
//If size is more than one, which is unlikely
birBasedOnType = birDataFromXMLType.stream().collect(Collectors.toMap(keyFunction, bir -> {
try {
return new String(cbeffUtil.createXML(cbeffUtil.convertBIRTypeToBIR(List.of(bir))));
} catch (Exception e) {
//Mostly this is unlikely
throw new IdAuthUncheckedException(IdAuthenticationErrorConstants.UNABLE_TO_PROCESS, e);
}
}));
}
} catch (Exception e) {
throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.BIOMETRIC_MISSING.getErrorCode(),
String.format(IdAuthenticationErrorConstants.BIOMETRIC_MISSING.getErrorMessage(), type.getName()), e);
}
return bdbBasedOnType.entrySet().stream()
return birBasedOnType.entrySet().stream()
.collect(Collectors.toMap(Entry<String, String>::getKey, (Entry<String, String> entry) -> {
IdentityInfoDTO identityInfoDTO = new IdentityInfoDTO();
identityInfoDTO.setValue(entry.getValue());
List<IdentityInfoDTO> idenityList = new ArrayList<>(1);
idenityList.add(identityInfoDTO);
return new SimpleEntry<>(getNameForCbeffName(entry.getKey(), matchType), idenityList);
return new SimpleEntry<>(getNameForCbeffName(entry.getKey(), matchType), List.of(identityInfoDTO));
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ public enum BioMatchType implements MatchType {
setOf(MultiFingerprintMatchingStrategy.PARTIAL)),

// Left Finger Image FGRIMG
FGRIMG_LEFT_THUMB(IdaIdMapping.LEFTTHUMB, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_LEFT_THUMB(IdaIdMapping.LEFTTHUMB, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.LEFT, SingleAnySubtypeType.THUMB),
FGRIMG_LEFT_INDEX(IdaIdMapping.LEFTINDEX, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_LEFT_INDEX(IdaIdMapping.LEFTINDEX, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.LEFT, SingleAnySubtypeType.INDEX_FINGER),
FGRIMG_LEFT_MIDDLE(IdaIdMapping.LEFTMIDDLE, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_LEFT_MIDDLE(IdaIdMapping.LEFTMIDDLE, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.LEFT, SingleAnySubtypeType.MIDDLE_FINGER),
FGRIMG_LEFT_RING(IdaIdMapping.LEFTRING, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_LEFT_RING(IdaIdMapping.LEFTRING, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.LEFT, SingleAnySubtypeType.RING_FINGER),
FGRIMG_LEFT_LITTLE(IdaIdMapping.LEFTLITTLE, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_LEFT_LITTLE(IdaIdMapping.LEFTLITTLE, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.LEFT, SingleAnySubtypeType.LITTLE_FINGER),

// Right Finger Image
FGRIMG_RIGHT_THUMB(IdaIdMapping.RIGHTTHUMB, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_RIGHT_THUMB(IdaIdMapping.RIGHTTHUMB, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.RIGHT, SingleAnySubtypeType.THUMB),
FGRIMG_RIGHT_INDEX(IdaIdMapping.RIGHTINDEX, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_RIGHT_INDEX(IdaIdMapping.RIGHTINDEX, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.RIGHT, SingleAnySubtypeType.INDEX_FINGER),
FGRIMG_RIGHT_MIDDLE(IdaIdMapping.RIGHTMIDDLE, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_RIGHT_MIDDLE(IdaIdMapping.RIGHTMIDDLE, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.RIGHT, SingleAnySubtypeType.MIDDLE_FINGER),
FGRIMG_RIGHT_RING(IdaIdMapping.RIGHTRING, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_RIGHT_RING(IdaIdMapping.RIGHTRING, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.RIGHT, SingleAnySubtypeType.RING_FINGER),
FGRIMG_RIGHT_LITTLE(IdaIdMapping.RIGHTLITTLE, setOf(FingerPrintMatchingStrategy.PARTIAL), CbeffDocType.FINGER,
FGRIMG_RIGHT_LITTLE(IdaIdMapping.RIGHTLITTLE, setOf(FingerPrintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR),
SingleAnySubtypeType.RIGHT, SingleAnySubtypeType.LITTLE_FINGER),

FGRIMG_UNKNOWN(IdaIdMapping.UNKNOWN_FINGER, CbeffDocType.FINGER, null, null,
FGRIMG_UNKNOWN(IdaIdMapping.UNKNOWN_FINGER, setOf(CbeffDocType.FINGER, CbeffDocType.FMR), null, null,
setOf(MultiFingerprintMatchingStrategy.PARTIAL)),

// Multi-fingerPrint
Expand All @@ -101,7 +101,7 @@ public enum BioMatchType implements MatchType {
FGRMIN_MULTI(IdaIdMapping.FINGERPRINT, setOf(MultiFingerprintMatchingStrategy.PARTIAL), CbeffDocType.FMR, null,
null),

FGRIMG_COMPOSITE(IdaIdMapping.FINGERPRINT, setOf(MultiFingerprintMatchingStrategy.PARTIAL), CbeffDocType.FINGER, null,
FGRIMG_COMPOSITE(IdaIdMapping.FINGERPRINT, setOf(MultiFingerprintMatchingStrategy.PARTIAL), setOf(CbeffDocType.FINGER, CbeffDocType.FMR), null,
null),

FGRIMG_MULTI(IdaIdMapping.FINGERPRINT, setOf(MultiFingerprintMatchingStrategy.PARTIAL), CbeffDocType.FINGER, null,
Expand Down Expand Up @@ -141,6 +141,12 @@ public enum BioMatchType implements MatchType {

/** The single any subtype. */
private SingleAnySubtypeType singleAnySubtype;


private BioMatchType(IdMapping idMapping, Set<MatchingStrategy> allowedMatchingStrategy, Set<CbeffDocType> cbeffDocTypes,
SingleAnySubtypeType subType, SingleAnySubtypeType singleAnySubtype) {
this(idMapping,cbeffDocTypes.toArray(s -> new CbeffDocType[s]), subType, singleAnySubtype,allowedMatchingStrategy);
}

/**
* Instantiates a new bio match type.
Expand Down Expand Up @@ -170,6 +176,11 @@ private BioMatchType(IdMapping idMapping, CbeffDocType[] cbeffDocType, SingleAny
}
}

private BioMatchType(IdMapping idMapping, CbeffDocType cbeffDocType, SingleAnySubtypeType subType,
SingleAnySubtypeType singleAnySubtype, Set<MatchingStrategy> allowedMatchingStrategy) {
this(idMapping, setOf(cbeffDocType), subType, singleAnySubtype, allowedMatchingStrategy);
}

/**
* Instantiates a new bio match type for UNKNOWN scenarios
*
Expand All @@ -180,11 +191,11 @@ private BioMatchType(IdMapping idMapping, CbeffDocType[] cbeffDocType, SingleAny
* @param allowedMatchingStrategy the allowed matching strategy
*/

private BioMatchType(IdMapping idMapping, CbeffDocType cbeffDocType, SingleAnySubtypeType subType,
private BioMatchType(IdMapping idMapping, Set<CbeffDocType> cbeffDocTypes, SingleAnySubtypeType subType,
SingleAnySubtypeType singleAnySubtype, Set<MatchingStrategy> allowedMatchingStrategy) {
// This constructor is called for UNKNOWN match types only. Make sure its id
// info function only calls by self instead of its sub-idmappings
this(idMapping, allowedMatchingStrategy, new CbeffDocType[] { cbeffDocType }, subType, singleAnySubtype, null);
this(idMapping, allowedMatchingStrategy, cbeffDocTypes.toArray(s -> new CbeffDocType[s]), subType, singleAnySubtype, null);
this.identityInfoFunction = requestDto -> getIdInfoFromBioIdInfo(requestDto.getBiometrics());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand All @@ -26,6 +27,7 @@
import io.mosip.authentication.core.logger.IdaLogger;
import io.mosip.authentication.core.spi.indauth.match.IdInfoFetcher;
import io.mosip.authentication.core.spi.indauth.match.IdMapping;
import io.mosip.authentication.core.util.CryptoUtil;
import io.mosip.kernel.biometrics.constant.BiometricFunction;
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.biosdk.provider.factory.BioAPIFactory;
Expand All @@ -35,12 +37,14 @@
import io.mosip.kernel.core.cbeffutil.entity.BDBInfo;
import io.mosip.kernel.core.cbeffutil.entity.BIR;
import io.mosip.kernel.core.cbeffutil.entity.BIR.BIRBuilder;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.BIRType;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.ProcessedLevelType;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.PurposeType;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.RegistryIDType;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.SingleType;
import io.mosip.kernel.core.cbeffutil.spi.CbeffUtil;
import io.mosip.kernel.core.cbeffutil.spi.CbeffUtil;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.authentication.core.util.CryptoUtil;
import io.mosip.kernel.core.util.DateUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -66,6 +70,9 @@ public class BioMatcherUtil {

@Value("${" + IDA_BDB_PROCESSED_LEVEL + ":" + BDB_DEAULT_PROCESSED_LEVEL + "}")
private String bdbProcessedLevel;

@Autowired
private CbeffUtil cbeffUtil;

/**
* Match function.
Expand Down Expand Up @@ -176,18 +183,18 @@ private BIR[][] getBirValues(Map<String, String> reqInfo, Map<String, String> en
int index = 0;
if (reqInfo.keySet().stream().noneMatch(key -> key.startsWith(IdAuthCommonConstants.UNKNOWN_BIO))) {
reqInfoObj = new BIR[reqInfo.size()];
entityInfoObj = new BIR[reqInfo.size()];
entityInfoObj = new BIR[entityInfo.size()];

for (Map.Entry<String, String> e : reqInfo.entrySet()) {
String key = e.getKey();

reqInfoObj[index] = getBir(e.getValue(), getType(key, idMappings));
entityInfoObj[index] = getBir(entityInfo.get(key), getType(key, idMappings));
entityInfoObj[index] = getBirFromCbeff(entityInfo.get(key));
index++;
}
} else {
List<IdAuthenticationBusinessException> reqMapexceptions = new ArrayList<>();
Function<? super Entry<String, String>, ? extends BIR> birMapper = e -> {
Function<? super Entry<String, String>, ? extends BIR> probeBirMapper = e -> {
try {
return getBir(e.getValue(), getType(e.getKey(), idMappings));
} catch (IdAuthenticationBusinessException e1) {
Expand All @@ -196,17 +203,26 @@ private BIR[][] getBirValues(Map<String, String> reqInfo, Map<String, String> en
}
};
reqInfoObj = reqInfo.entrySet().stream()
.map(birMapper)
.map(probeBirMapper)
.toArray(s -> new BIR[s]);
if(!reqMapexceptions.isEmpty()) {
throw reqMapexceptions.get(0);
}

List<IdAuthenticationBusinessException> entityMapexceptions = new ArrayList<>();

Function<? super Entry<String, String>, ? extends BIR> galleryBirMapper = e -> {
try {
return getBirFromCbeff(e.getValue());
} catch (IdAuthenticationBusinessException e1) {
entityMapexceptions.add(e1);
return null;
}
};

entityInfoObj = entityInfo.entrySet()
.stream()
.map(birMapper)
.map(galleryBirMapper)
.toArray(s -> new BIR[s]);

if(!entityMapexceptions.isEmpty()) {
Expand All @@ -217,6 +233,17 @@ private BIR[][] getBirValues(Map<String, String> reqInfo, Map<String, String> en
return new BIR[][] { reqInfoObj, entityInfoObj };
}

private BIR getBirFromCbeff(String cbeff) throws IdAuthenticationBusinessException {
try {
List<BIRType> birDataFromXMLType = cbeffUtil.getBIRDataFromXML(cbeff.getBytes());
List<BIR> birList = cbeffUtil.convertBIRTypeToBIR(birDataFromXMLType);
return birList.get(0);
} catch (Exception e) {
logger.error(IdAuthCommonConstants.SESSION_ID, "IDA", "getBirFromCbeff", "Cabit convert cbeff to BIR, " + ExceptionUtils.getStackTrace(e));
throw new IdAuthenticationBusinessException(IdAuthenticationErrorConstants.UNABLE_TO_PROCESS, e);
}
}

/**
* Gets the type.
*
Expand Down
Loading

0 comments on commit 3a0681a

Please sign in to comment.