diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandler.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandler.java index 4824d4adc2..dd2ecabfa4 100644 --- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandler.java +++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandler.java @@ -264,12 +264,12 @@ private Map getOIDCClaimsFromUserAttributes(Map getOIDCClaimsFromFederatedUserAttributes(Map federatedUserAttributed, OAuthTokenReqMessageContext requestMsgCtx) + String> federatedUserAttributes, OAuthTokenReqMessageContext requestMsgCtx) throws IdentityOAuth2Exception { String spTenantDomain = getServiceProviderTenantDomain(requestMsgCtx); @@ -283,24 +283,16 @@ private Map getOIDCClaimsFromFederatedUserAttributes(Map userClaimsInOidcDialect = new HashMap<>(); - if (MapUtils.isNotEmpty(federatedUserAttributed)) { - for (Map.Entry userAttribute : federatedUserAttributed.entrySet()) { + if (MapUtils.isNotEmpty(federatedUserAttributes)) { + for (Map.Entry 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); } } } @@ -638,17 +630,12 @@ private static Map getUserClaimsInOIDCDialectFromFederatedUserAt for (Map.Entry 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); } } } diff --git a/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandlerTest.java b/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandlerTest.java index f6ad220a88..e69e945828 100644 --- a/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandlerTest.java +++ b/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandlerTest.java @@ -445,9 +445,9 @@ public void testHandleClaimsForOAuthTokenReqMessageContextWithAuthorizationCode( OAuthTokenReqMessageContext requestMsgCtx = getTokenReqMessageContextForFederatedUser(userAttributes); requestMsgCtx.addProperty("AuthorizationCode", "dummyAuthorizationCode"); Map federatedUserAttributes = new HashMap<>(); - federatedUserAttributes.put(SAML2BearerGrantHandlerTest.buildClaimMapping(LOCAL_COUNTRY_CLAIM_URI), + federatedUserAttributes.put(SAML2BearerGrantHandlerTest.buildClaimMapping("country"), TestConstants.CLAIM_VALUE1); - federatedUserAttributes.put(SAML2BearerGrantHandlerTest.buildClaimMapping(LOCAL_EMAIL_CLAIM_URI), + federatedUserAttributes.put(SAML2BearerGrantHandlerTest.buildClaimMapping("email"), TestConstants.CLAIM_VALUE2); AuthorizationGrantCacheEntry authorizationGrantCacheEntry = new AuthorizationGrantCacheEntry();