Skip to content

Commit

Permalink
[ES-1100] Fixed issue to return verified claims metadata as json string.
Browse files Browse the repository at this point in the history
Signed-off-by: Mahammed Taheer <[email protected]>
  • Loading branch information
mahammedtaheer committed Dec 13, 2024
1 parent c45fb8b commit 6185d50
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void matchTestWithInValidCerts_thenFail() throws IdAuthenticationBusiness
try {
keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties);
}catch (IdAuthenticationBusinessException e){
Assert.assertEquals("IDA-KBT-001",e.getErrorCode());
Assert.assertEquals("IDA-KBT-002",e.getErrorCode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public final class IdAuthCommonConstants {

public static final String VERIFIED_CLAIMS_ATTRIBS = "verifiedAttributes";

public static final String NULL_CONST = "=null";
public static final String NULL_CONST = "null";

public static final String COMMA_STRING = ",";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,14 @@ public String buildVerifiedClaimsMetadata(String verifiedClaimsData, String oidc
if (verifiedClaimsData.equals(EMPTY)) {
mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(),
"buildVerifiedClaimsMetadata", "No Verified Claims data found for the id.");
return oidcClientAllowedVerifiedClaims.stream()
.map(md -> md.concat(NULL_CONST))
.collect(Collectors.joining(COMMA_STRING));
Map<String, Object> verifiedClaimsMap = new HashMap<>();
oidcClientAllowedVerifiedClaims.stream()
.forEach(claim -> verifiedClaimsMap.put(claim, NULL_CONST));
return convertMapToJsonString(verifiedClaimsMap);
}

mosipLogger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(),
"buildVerifiedClaimsMetadata", "Verified Claims data found for the id.");
JSONObject verifiedClaimJson = new JSONObject(verifiedClaimsData);
Set<String> verifiedClaimKeys = StreamSupport.stream(Spliterators.spliteratorUnknownSize(
verifiedClaimJson.keys(), 0),
Expand All @@ -835,15 +838,21 @@ public String buildVerifiedClaimsMetadata(String verifiedClaimsData, String oidc
return Stream.empty();
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

String verifiedClaimsStr = null;

Map<String, Object> verifiedClaimsMap = idAttribsMap.entrySet().stream().filter(e -> verifiedClaimKeys.contains(e.getKey()))
.map(entry -> new Object[] {(Object)entry.getValue(),
((JSONArray)verifiedClaimJson.get(entry.getKey())).toList()})
.collect(Collectors.toMap(strArr -> strArr[0].toString(), strArr -> strArr[1]));

oidcClientAllowedVerifiedClaims.stream().filter(claim -> !verifiedClaimsMap.keySet().contains(claim))
.forEach(claim -> verifiedClaimsMap.put(claim, "null"));
.forEach(claim -> verifiedClaimsMap.put(claim, NULL_CONST));

return convertMapToJsonString(verifiedClaimsMap);

}

private String convertMapToJsonString(Map<String, Object> verifiedClaimsMap) {
String verifiedClaimsStr = null;
try {
verifiedClaimsStr = mapper.writeValueAsString(verifiedClaimsMap);
} catch (JsonProcessingException exp) {
Expand Down

0 comments on commit 6185d50

Please sign in to comment.