From 50f576fd598d1e490841fb9ff25665041eeb26fa Mon Sep 17 00:00:00 2001 From: Mahammed Taheer Date: Thu, 27 Jul 2023 17:06:21 +0530 Subject: [PATCH] [MOSIP-28622] fixed firstname, lastname not populating in e-signet issue. --- .../service/kyc/impl/KycServiceImpl.java | 76 ++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java index ac4d4896704..57dd5b97712 100644 --- a/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java +++ b/authentication/authentication-service/src/main/java/io/mosip/authentication/service/kyc/impl/KycServiceImpl.java @@ -77,6 +77,9 @@ public class KycServiceImpl implements KycService { @Value("${ida.idp.consented.address.attribute.name:address}") private String consentedAddressAttributeName; + @Value("${ida.idp.consented.name.attribute.name:name}") + private String consentedNameAttributeName; + @Value("${ida.idp.consented.individual_id.attribute.name:individual_id}") private String consentedIndividualAttributeName; @@ -534,6 +537,9 @@ private void addEntityForLangCodes(Map mappedConsentedLocales, M } } } else { + if (consentedAttribute.equals(consentedNameAttributeName)) { + addNameClaim(mappedConsentedLocales, idInfo, respMap, consentedAttribute, idSchemaAttributes); + } if (consentedAttribute.equals(consentedAddressAttributeName)) { if (mappedConsentedLocales.size() > 1) { for (String consentedLocale: mappedConsentedLocales.keySet()) { @@ -589,12 +595,14 @@ private void addFormattedAddress(List idSchemaAttributes, Map 0) addressMap.put(addressAttribute + localeAppendValue, identityInfoValue.toString()); } + if (addressMap.size() == 0) + return; + if (langCodeFound && addLocale) respMap.put(consentedAddressAttributeName + localeAppendValue, addressMap); else respMap.put(consentedAddressAttributeName, addressMap); } + private void addNameClaim(Map mappedConsentedLocales, Map> idInfo, + Map respMap, String consentedAttribute, List idSchemaAttributes) throws IdAuthenticationBusinessException{ + if(mappedConsentedLocales.size() > 1) { + for (String consentedLocale: mappedConsentedLocales.keySet()) { + String consentedLocaleValue = mappedConsentedLocales.get(consentedLocale); + StringBuilder nameBuffer = new StringBuilder(); + for (String idSchemaAttribute : idSchemaAttributes) { + List idInfoList = idInfo.get(idSchemaAttribute); + + if (Objects.isNull(idInfoList)) { + mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "addEntityForLangCodes", + "Data not available in Identity Info for the claim. So not adding to response claims. Claim Name: " + idSchemaAttribute); + continue; + } + if (nameBuffer.length() > 0) { + nameBuffer.append(" "); + } + Map mappedLangCodes = langCodeMapping(idInfoList); + if (!mappedLangCodes.keySet().contains(consentedLocaleValue)) { + break; + } + for (IdentityInfoDTO identityInfo : idInfoList) { + String langCode = mappedLangCodes.get(consentedLocaleValue); + if (identityInfo.getLanguage().equalsIgnoreCase(langCode)) { + nameBuffer.append(identityInfo.getValue()); + } + } + } + if (nameBuffer.toString().trim().length() > 0) + respMap.put(consentedAttribute + IdAuthCommonConstants.CLAIMS_LANG_SEPERATOR + consentedLocaleValue, nameBuffer.toString()); + } + } else { + StringBuilder nameBuffer = new StringBuilder(); + for (String idSchemaAttribute : idSchemaAttributes) { + List idInfoList = idInfo.get(idSchemaAttribute); + + if (Objects.isNull(idInfoList)) { + mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "addEntityForLangCodes", + "Data not available in Identity Info for the claim. So not adding to response claims. Claim Name: " + idSchemaAttribute); + continue; + } + if (nameBuffer.length() > 0) { + nameBuffer.append(" "); + } + Map mappedLangCodes = langCodeMapping(idInfoList); + List availableLangCodes = getAvailableLangCodes(mappedConsentedLocales, mappedLangCodes); + if (availableLangCodes.size() == 0) { + continue; + } + for (IdentityInfoDTO identityInfo : idInfoList) { + String langCode = mappedLangCodes.get(availableLangCodes.get(0)); + if (identityInfo.getLanguage().equalsIgnoreCase(langCode)) { + nameBuffer.append(identityInfo.getValue()); + } + } + } + if (nameBuffer.toString().trim().length() > 0) + respMap.put(consentedAttribute, nameBuffer.toString()); + } + } + private String convertJP2ToJpeg(String jp2Image) { try { ConvertRequestDto convertRequestDto = new ConvertRequestDto();