Skip to content

Commit

Permalink
Fix oidc claim mapping in jwt access token attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
shashimalcse committed Dec 19, 2024
1 parent daa0726 commit 1db3fae
Showing 1 changed file with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ private Map<String, Object> getOIDCClaimsFromUserAttributes(Map<ClaimMapping, St
/**
* Get oidc claims mapping.
*
* @param federatedUserAttributed User attributes.
* @param federatedUserAttributes User attributes.
* @param requestMsgCtx Request Context.
* @return User attributes Map.
*/
private Map<String, Object> getOIDCClaimsFromFederatedUserAttributes(Map<ClaimMapping,
String> federatedUserAttributed, OAuthTokenReqMessageContext requestMsgCtx)
String> federatedUserAttributes, OAuthTokenReqMessageContext requestMsgCtx)
throws IdentityOAuth2Exception {

String spTenantDomain = getServiceProviderTenantDomain(requestMsgCtx);
Expand All @@ -283,24 +283,16 @@ private Map<String, Object> getOIDCClaimsFromFederatedUserAttributes(Map<ClaimMa
}
// Get user claims in OIDC dialect.
Map<String, String> userClaimsInOidcDialect = new HashMap<>();
if (MapUtils.isNotEmpty(federatedUserAttributed)) {
for (Map.Entry<ClaimMapping, String> userAttribute : federatedUserAttributed.entrySet()) {
if (MapUtils.isNotEmpty(federatedUserAttributes)) {
for (Map.Entry<ClaimMapping, String> userAttribute : federatedUserAttributes.entrySet()) {
ClaimMapping claimMapping = userAttribute.getKey();
String claimValue = userAttribute.getValue();
if (oidcToLocalClaimMappings.containsValue(claimMapping.getLocalClaim().getClaimUri())) {
String localClaimURI = claimMapping.getLocalClaim().getClaimUri();
String oidcClaimUri = oidcToLocalClaimMappings.entrySet().stream()
.filter(entry -> entry.getValue().equals(localClaimURI))
.map(Map.Entry::getKey)
.findFirst()
.orElse(null);

if (oidcClaimUri != null) {
userClaimsInOidcDialect.put(oidcClaimUri, claimValue.toString());
if (log.isDebugEnabled() &&
IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
log.debug("Mapped claim: key - " + oidcClaimUri + " value - " + claimValue);
}
String claimValue = userAttribute.getValue().toString();
String localClaimURI = claimMapping.getLocalClaim().getClaimUri();
if (oidcToLocalClaimMappings.containsKey(localClaimURI) && StringUtils.isNotBlank(claimValue)) {
userClaimsInOidcDialect.put(localClaimURI, claimValue);
if (log.isDebugEnabled() &&
IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
log.debug("Mapped claim: key - " + localClaimURI + " value - " + claimValue);
}
}
}
Expand Down Expand Up @@ -638,17 +630,12 @@ private static Map<String, Object> getUserClaimsInOIDCDialectFromFederatedUserAt
for (Map.Entry<ClaimMapping, String> userAttribute : federatedUserAttr.entrySet()) {
ClaimMapping claimMapping = userAttribute.getKey();
String claimValue = userAttribute.getValue();
if (oidcToLocalClaimMappings.containsValue(claimMapping.getLocalClaim().getClaimUri())) {
String localClaimURI = claimMapping.getLocalClaim().getClaimUri();
String oidcClaimUri = oidcToLocalClaimMappings.entrySet().stream()
.filter(entry -> entry.getValue().equals(localClaimURI))
.map(Map.Entry::getKey).findFirst().orElse(null);
if (oidcClaimUri != null && StringUtils.isNotBlank(claimValue)) {
userClaimsInOidcDialect.put(oidcClaimUri, claimValue);
if (log.isDebugEnabled() &&
IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
log.debug("Mapped claim: key - " + oidcClaimUri + " value - " + claimValue);
}
String localClaimURI = claimMapping.getLocalClaim().getClaimUri();
if (oidcToLocalClaimMappings.containsKey(localClaimURI) && StringUtils.isNotBlank(claimValue)) {
userClaimsInOidcDialect.put(localClaimURI, claimValue);
if (log.isDebugEnabled() &&
IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
log.debug("Mapped claim: key - " + localClaimURI + " value - " + claimValue);
}
}
}
Expand Down

0 comments on commit 1db3fae

Please sign in to comment.