Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES-1100] Fixed issue to return verified claims metadata as json string. #1392

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading