Skip to content

Commit

Permalink
Fix bio auth type check issue due to case sensitive check (#600)
Browse files Browse the repository at this point in the history
* Fix bio auth type check issue due to case sensitive check

* Minor fix
  • Loading branch information
loganathan-sekaran authored Oct 26, 2021
1 parent 6163bd7 commit e85e679
Showing 1 changed file with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ public Map<String, Object> getIdentity(String id, boolean isBio, Set<String> fil
*/
@SuppressWarnings("unchecked")
public Map<String, Object> getIdentity(String id, boolean isBio, IdType idType, Set<String> filterAttributes) throws IdAuthenticationBusinessException {

String hashedId;
try {
hashedId = securityManager.hash(id);
Expand Down Expand Up @@ -232,18 +231,21 @@ public Map<String, Object> getIdentity(String id, boolean isBio, IdType idType,
Map<String, Object> responseMap = new LinkedHashMap<>();

Map<String, String> demoDataMap = mapper.readValue(entity.getDemographicData(), Map.class);
if (!filterAttributes.isEmpty()) {
Set<String> filterAttributesInLowercase = filterAttributes.isEmpty() ? Set.of()
: filterAttributes.stream().map(String::toLowerCase).collect(Collectors.toSet());

if (!filterAttributesInLowercase.isEmpty()) {
Map<String, String> demoDataMapPostFilter = demoDataMap.entrySet().stream()
.filter(demo -> filterAttributes.contains(demo.getKey()))
.filter(demo -> filterAttributesInLowercase.contains(demo.getKey().toLowerCase()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
responseMap.put(DEMOGRAPHICS, decryptConfiguredAttributes(id, demoDataMapPostFilter));
}

if (entity.getBiometricData() != null) {
Map<String, String> bioDataMap = mapper.readValue(entity.getBiometricData(), Map.class);
if (!filterAttributes.isEmpty()) {
if (!filterAttributesInLowercase.isEmpty()) {
Map<String, String> bioDataMapPostFilter = bioDataMap.entrySet().stream()
.filter(bio -> filterAttributes.contains(bio.getKey()))
.filter(bio -> filterAttributesInLowercase.contains(bio.getKey().toLowerCase()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
responseMap.put(BIOMETRICS, decryptConfiguredAttributes(id, bioDataMapPostFilter));
}
Expand Down Expand Up @@ -274,26 +276,31 @@ private Map<String, Object> decryptConfiguredAttributes(String id, Map<String, S
Collectors.toMap(Entry::getKey, Entry::getValue)));
Map<String, String> dataToDecrypt = partitionedMap.get(true);
Map<String, String> plainData = partitionedMap.get(false);
Map<String, String> decryptedData = securityManager.zkDecrypt(id, dataToDecrypt);
Map<String, String> decryptedData = dataToDecrypt.isEmpty() ? Map.of()
: securityManager.zkDecrypt(id, dataToDecrypt);
Map<String, String> finalDataStr = new LinkedHashMap<>();
finalDataStr.putAll(plainData);
finalDataStr.putAll(decryptedData);
return finalDataStr.entrySet().stream().collect(Collectors.toMap(entry -> (String) entry.getKey(),
entry -> {
String val = entry.getValue();
if(val.trim().startsWith("[") || val.trim().startsWith("{")) {
try {
return mapper.readValue(val.getBytes(), Object.class);
} catch (IOException e) {
logger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), "decryptConfiguredAttributes",
ExceptionUtils.getStackTrace(e));
return val;
}
} else {
return val;
}
}
));
entry -> {
Object valObject = entry.getValue();
if (valObject instanceof String) {
String val = (String) valObject;
if (val.trim().startsWith("[") || val.trim().startsWith("{")) {
try {
return mapper.readValue(val.getBytes(), Object.class);
} catch (IOException e) {
logger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(),
"decryptConfiguredAttributes", ExceptionUtils.getStackTrace(e));
return val;
}
} else {
return val;
}
} else {
return valObject;
}
}));
}

/**
Expand Down

0 comments on commit e85e679

Please sign in to comment.