Skip to content

Commit edde36f

Browse files
committed
getting remotes claim from mapped remote claim attributes instead of property
1 parent 6867a69 commit edde36f

File tree

10 files changed

+59
-70
lines changed

10 files changed

+59
-70
lines changed

components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -422,31 +422,30 @@ private void addFederatedTokensToSessionCache(OAuthMessage oAuthMessage,
422422
}
423423

424424
/**
425-
* Add unfiltered federated user claims to session cache.
425+
* Add mapped remote claims to session cache.
426426
*
427427
* @param oAuthMessage The OAuthMessage with the session data cache entry.
428428
* @param authenticationResult The authentication result of authorization call.
429429
*/
430-
private void addUnfilteredFederatedUserClaimsToSessionCache(OAuthMessage oAuthMessage,
430+
private void addMappedRemoteClaimsToSessionCache(OAuthMessage oAuthMessage,
431431
AuthenticationResult authenticationResult) {
432432

433-
if (!(authenticationResult.getProperty(FrameworkConstants.UNFILTERED_LOCAL_CLAIM_VALUES) instanceof Map)) {
433+
Optional<Map<String, String>> mappedRemoteClaims = authenticationResult.getMappedRemoteClaims();
434+
if (!mappedRemoteClaims.isPresent()) {
434435
return;
435436
}
436-
Map<String, String> unfilteredFederatedUserClaims = (Map<String, String>) authenticationResult
437-
.getProperty(FrameworkConstants.UNFILTERED_LOCAL_CLAIM_VALUES);
438437

439438
SessionDataCacheEntry sessionDataCacheEntry = oAuthMessage.getSessionDataCacheEntry();
440-
if (sessionDataCacheEntry == null || unfilteredFederatedUserClaims.isEmpty()) {
439+
if (sessionDataCacheEntry == null || mappedRemoteClaims.get().isEmpty()) {
441440
return;
442441
}
443-
Map<ClaimMapping, String> unfilteredFederatedUserAttributes = new HashMap<>();
444-
unfilteredFederatedUserClaims.forEach(
445-
(key, value) -> unfilteredFederatedUserAttributes.put(ClaimMapping.build(key, key, null,
442+
Map<ClaimMapping, String> mappedRemoteClaimsMap = new HashMap<>();
443+
mappedRemoteClaims.get().forEach(
444+
(key, value) -> mappedRemoteClaimsMap.put(ClaimMapping.build(key, key, null,
446445
false), value));
447-
sessionDataCacheEntry.setUnfilteredFederatedUserClaims(unfilteredFederatedUserAttributes);
446+
sessionDataCacheEntry.setMappedRemoteClaims(mappedRemoteClaimsMap);
448447
if (log.isDebugEnabled() && authenticationResult.getSubject() != null) {
449-
log.debug("Added the unfiltered federated user claims to the session data cache. " +
448+
log.debug("Added the mapped remote claims to the session data cache. " +
450449
"Session context identifier: " + sessionDataCacheEntry.getSessionContextIdentifier()
451450
+ " for the user: " + authenticationResult.getSubject().getLoggableMaskedUserId());
452451
}
@@ -1420,9 +1419,9 @@ private void addToAuthenticationResultDetailsToOAuthMessage(OAuthMessage oAuthMe
14201419
authnResult.getProperty(FrameworkConstants.AnalyticsAttributes.SESSION_ID));
14211420
// Adding federated tokens come with the authentication result of the authorization call.
14221421
addFederatedTokensToSessionCache(oAuthMessage, authnResult);
1423-
// Adding federated user claims come with the authentication result to resolve access token claims in
1422+
// Adding mapped remoted claims come with the authentication result to resolve access token claims in
14241423
// federated flow.
1425-
addUnfilteredFederatedUserClaimsToSessionCache(oAuthMessage, authnResult);
1424+
addMappedRemoteClaimsToSessionCache(oAuthMessage, authnResult);
14261425
}
14271426

14281427
private void updateAuthTimeInSessionDataCacheEntry(OAuthMessage oAuthMessage) {
@@ -2177,10 +2176,9 @@ private void addUserAttributesToOAuthMessage(OAuthMessage oAuthMessage, String c
21772176
authorizationGrantCacheEntry.setRequestObjectFlow(isRequestObjectFlow);
21782177
authorizationGrantCacheEntry.setFederatedTokens(sessionDataCacheEntry.getFederatedTokens());
21792178
sessionDataCacheEntry.setFederatedTokens(null);
2180-
Map<ClaimMapping, String> unfilteredFederatedUserAttributes = sessionDataCacheEntry.
2181-
getUnfilteredFederatedUserAttributes();
2182-
if (unfilteredFederatedUserAttributes != null) {
2183-
authorizationGrantCacheEntry.setUnfilteredFederatedUserAttributes(unfilteredFederatedUserAttributes);
2179+
Map<ClaimMapping, String> mappedRemoteClaims = sessionDataCacheEntry.getMappedRemoteClaims();
2180+
if (mappedRemoteClaims != null) {
2181+
authorizationGrantCacheEntry.setMappedRemoteClaims(mappedRemoteClaims);
21842182
}
21852183
oAuthMessage.setAuthorizationGrantCacheEntry(authorizationGrantCacheEntry);
21862184
}
@@ -3824,7 +3822,7 @@ private OAuth2AuthorizeReqDTO buildAuthRequest(OAuth2Parameters oauth2Params, Se
38243822
authzReqDTO.setState(oauth2Params.getState());
38253823
authzReqDTO.setHttpServletRequestWrapper(new HttpServletRequestWrapper(request));
38263824
authzReqDTO.setRequestedSubjectId(oauth2Params.getRequestedSubjectId());
3827-
authzReqDTO.setUnfilteredFederatedUserAttributes(sessionDataCacheEntry.getUnfilteredFederatedUserAttributes());
3825+
authzReqDTO.setMappedRemoteClaims(sessionDataCacheEntry.getMappedRemoteClaims());
38283826

38293827
if (sessionDataCacheEntry.getParamMap() != null && sessionDataCacheEntry.getParamMap().get(OAuthConstants
38303828
.AMR) != null) {
@@ -4560,9 +4558,9 @@ private void addUserAttributesToCache(SessionDataCacheEntry sessionDataCacheEntr
45604558
DeviceAuthorizationGrantCacheKey cacheKey = new DeviceAuthorizationGrantCacheKey(deviceCode);
45614559
DeviceAuthorizationGrantCacheEntry cacheEntry =
45624560
new DeviceAuthorizationGrantCacheEntry(sessionDataCacheEntry.getLoggedInUser().getUserAttributes());
4563-
if (sessionDataCacheEntry.getUnfilteredFederatedUserAttributes() != null) {
4564-
cacheEntry.setUnfilteredFederatedUserAttributes(sessionDataCacheEntry
4565-
.getUnfilteredFederatedUserAttributes());
4561+
if (sessionDataCacheEntry.getMappedRemoteClaims() != null) {
4562+
cacheEntry.setMappedRemoteClaims(sessionDataCacheEntry
4563+
.getMappedRemoteClaims());
45664564
}
45674565
DeviceAuthorizationGrantCache.getInstance().addToCache(cacheKey, cacheEntry);
45684566
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/cache/AuthorizationGrantCacheEntry.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class AuthorizationGrantCacheEntry extends CacheEntry {
6666

6767
private boolean hasNonOIDCClaims;
6868

69-
private Map<ClaimMapping, String> unfilteredFederatedUserAttributes;
69+
private Map<ClaimMapping, String> mappedRemoteClaims;
7070

7171
/*
7272
OIDC sub claim. This should be formatted based on the Service Provider configurations to append
@@ -393,14 +393,14 @@ public void setPreIssueAccessTokenActionsExecuted(boolean preIssueAccessTokenAct
393393
isPreIssueAccessTokenActionsExecuted = preIssueAccessTokenActionsExecuted;
394394
}
395395

396-
public Map<ClaimMapping, String> getUnfilteredFederatedUserAttributes() {
396+
public Map<ClaimMapping, String> getMappedRemoteClaims() {
397397

398-
return unfilteredFederatedUserAttributes;
398+
return mappedRemoteClaims;
399399
}
400400

401-
public void setUnfilteredFederatedUserAttributes(
402-
Map<ClaimMapping, String> unfilteredFederatedUserAttributes) {
401+
public void setMappedRemoteClaims(
402+
Map<ClaimMapping, String> mappedRemoteClaims) {
403403

404-
this.unfilteredFederatedUserAttributes = unfilteredFederatedUserAttributes;
404+
this.mappedRemoteClaims = mappedRemoteClaims;
405405
}
406406
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/cache/SessionDataCacheEntry.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class SessionDataCacheEntry extends CacheEntry {
5454

5555
private Map<String, Serializable> endpointParams = new HashMap<>();
5656
private List<FederatedTokenDO> federatedTokens;
57-
private Map<ClaimMapping, String> unfilteredFederatedUserAttributes;
57+
private Map<ClaimMapping, String> mappedRemoteClaims;
5858

5959
public OAuthAuthzReqMessageContext getAuthzReqMsgCtx() {
6060
return authzReqMsgCtx;
@@ -175,13 +175,13 @@ public void setFederatedTokens(List<FederatedTokenDO> federatedTokens) {
175175
this.federatedTokens = federatedTokens;
176176
}
177177

178-
public Map<ClaimMapping, String> getUnfilteredFederatedUserAttributes() {
178+
public Map<ClaimMapping, String> getMappedRemoteClaims() {
179179

180-
return unfilteredFederatedUserAttributes;
180+
return mappedRemoteClaims;
181181
}
182182

183-
public void setUnfilteredFederatedUserClaims(Map<ClaimMapping, String> unfilteredFederatedUserAttributes) {
183+
public void setMappedRemoteClaims(Map<ClaimMapping, String> mappedRemoteClaims) {
184184

185-
this.unfilteredFederatedUserAttributes = unfilteredFederatedUserAttributes;
185+
this.mappedRemoteClaims = mappedRemoteClaims;
186186
}
187187
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/authz/handlers/TokenResponseTypeHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ private void addUserAttributesToCache(String accessToken,
554554
authorizationGrantCacheEntry.setMaxAge(authorizeReqDTO.getMaxAge());
555555
}
556556

557-
if (authorizeReqDTO.getUnfilteredFederatedUserAttributes() != null) {
558-
authorizationGrantCacheEntry.setUnfilteredFederatedUserAttributes(
559-
authorizeReqDTO.getUnfilteredFederatedUserAttributes());
557+
if (authorizeReqDTO.getMappedRemoteClaims() != null) {
558+
authorizationGrantCacheEntry.setMappedRemoteClaims(
559+
authorizeReqDTO.getMappedRemoteClaims());
560560
}
561561

562562
ClaimMapping key = new ClaimMapping();

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/authz/handlers/util/ResponseTypeHandlerUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ private static void addUserAttributesToCache(String accessToken, OAuthAuthzReqMe
487487
userAttributes.put(key, sub);
488488
}
489489

490-
if (authorizeReqDTO.getUnfilteredFederatedUserAttributes() != null) {
491-
authorizationGrantCacheEntry.setUnfilteredFederatedUserAttributes(
492-
authorizeReqDTO.getUnfilteredFederatedUserAttributes());
490+
if (authorizeReqDTO.getMappedRemoteClaims() != null) {
491+
authorizationGrantCacheEntry.setMappedRemoteClaims(
492+
authorizeReqDTO.getMappedRemoteClaims());
493493
}
494494

495495
authorizationGrantCacheEntry

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/device/cache/DeviceAuthorizationGrantCacheEntry.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,13 @@ public class DeviceAuthorizationGrantCacheEntry extends CacheEntry {
3131
private static final long serialVersionUID = -3043225645166013281L;
3232

3333
private Map<ClaimMapping, String> userAttributes;
34-
private Map<ClaimMapping, String> unfilteredFederatedUserAttributes;
34+
private Map<ClaimMapping, String> mappedRemoteClaims;
3535

3636
public DeviceAuthorizationGrantCacheEntry(Map<ClaimMapping, String> userAttributes) {
3737

3838
this.userAttributes = userAttributes;
3939
}
4040

41-
public DeviceAuthorizationGrantCacheEntry(Map<ClaimMapping, String> userAttributes,
42-
Map<ClaimMapping, String> unfilteredFederatedUserAttributes) {
43-
44-
this.userAttributes = userAttributes;
45-
this.unfilteredFederatedUserAttributes = unfilteredFederatedUserAttributes;
46-
}
47-
4841
/**
4942
* Return user attributes of cache entry.
5043
*
@@ -65,14 +58,14 @@ public void setUserAttributes(Map<ClaimMapping, String> userAttributes) {
6558
this.userAttributes = userAttributes;
6659
}
6760

68-
public Map<ClaimMapping, String> getUnfilteredFederatedUserAttributes() {
61+
public Map<ClaimMapping, String> getMappedRemoteClaims() {
6962

70-
return unfilteredFederatedUserAttributes;
63+
return mappedRemoteClaims;
7164
}
7265

73-
public void setUnfilteredFederatedUserAttributes(
74-
Map<ClaimMapping, String> unfilteredFederatedUserAttributes) {
66+
public void setMappedRemoteClaims(
67+
Map<ClaimMapping, String> mappedRemoteClaims) {
7568

76-
this.unfilteredFederatedUserAttributes = unfilteredFederatedUserAttributes;
69+
this.mappedRemoteClaims = mappedRemoteClaims;
7770
}
7871
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/dto/OAuth2AuthorizeReqDTO.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class OAuth2AuthorizeReqDTO {
6363
private boolean isRequestObjectFlow;
6464
private String state;
6565
private String requestedSubjectId;
66-
private Map<ClaimMapping, String> unfilteredFederatedUserAttributes;
66+
private Map<ClaimMapping, String> mappedRemoteClaims;
6767

6868
public String getRequestedSubjectId() {
6969

@@ -307,14 +307,14 @@ public void setHttpServletRequestWrapper(HttpServletRequestWrapper httpServletRe
307307
this.httpServletRequestWrapper = httpServletRequestWrapper;
308308
}
309309

310-
public Map<ClaimMapping, String> getUnfilteredFederatedUserAttributes() {
310+
public Map<ClaimMapping, String> getMappedRemoteClaims() {
311311

312-
return unfilteredFederatedUserAttributes;
312+
return mappedRemoteClaims;
313313
}
314314

315-
public void setUnfilteredFederatedUserAttributes(
316-
Map<ClaimMapping, String> unfilteredFederatedUserAttributes) {
315+
public void setMappedRemoteClaims(
316+
Map<ClaimMapping, String> mappedRemoteClaims) {
317317

318-
this.unfilteredFederatedUserAttributes = unfilteredFederatedUserAttributes;
318+
this.mappedRemoteClaims = mappedRemoteClaims;
319319
}
320320
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/AccessTokenIssuer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,9 @@ private Optional<AuthorizationGrantCacheEntry> getAuthzGrantCacheEntryFromDevice
623623
Map<ClaimMapping, String> userAttributes = cacheEntry.getUserAttributes();
624624
AuthorizationGrantCacheEntry authorizationGrantCacheEntry =
625625
new AuthorizationGrantCacheEntry(userAttributes);
626-
if (cacheEntry.getUnfilteredFederatedUserAttributes() != null) {
627-
authorizationGrantCacheEntry.setUnfilteredFederatedUserAttributes(cacheEntry
628-
.getUnfilteredFederatedUserAttributes());
626+
if (cacheEntry.getMappedRemoteClaims() != null) {
627+
authorizationGrantCacheEntry.setMappedRemoteClaims(cacheEntry
628+
.getMappedRemoteClaims());
629629
}
630630
return Optional.of(authorizationGrantCacheEntry);
631631
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandler.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,16 @@ private Map<ClaimMapping, String> getUserAttributesCachedAgainstDeviceCode(Strin
479479
DeviceAuthorizationGrantCacheEntry cacheEntry =
480480
DeviceAuthorizationGrantCache.getInstance().getValueFromCache(cacheKey);
481481
if (fetchFederatedUserAttributes) {
482-
return cacheEntry == null ? Collections.emptyMap() : cacheEntry.getUnfilteredFederatedUserAttributes();
482+
return cacheEntry == null ? Collections.emptyMap() : cacheEntry.getMappedRemoteClaims();
483483
}
484484
return cacheEntry == null ? Collections.emptyMap() : cacheEntry.getUserAttributes();
485485
}
486486

487487
/**
488488
* Get user attributes cached against the authorization code.
489489
*
490-
* @param authorizationCode Authorization Code
490+
* @param authorizationCode Authorization Code
491+
* @param fetchFederatedUserAttributes Flag to indicate whether to fetch federated user attributes.
491492
* @return User attributes cached against the authorization code
492493
*/
493494
private Map<ClaimMapping, String> getUserAttributesFromCacheUsingCode(String authorizationCode,
@@ -504,7 +505,7 @@ private Map<ClaimMapping, String> getUserAttributesFromCacheUsingCode(String aut
504505
AuthorizationGrantCacheEntry cacheEntry =
505506
AuthorizationGrantCache.getInstance().getValueFromCacheByCode(cacheKey);
506507
if (fetchFederatedUserAttributes) {
507-
return cacheEntry == null ? new HashMap<>() : cacheEntry.getUnfilteredFederatedUserAttributes();
508+
return cacheEntry == null ? new HashMap<>() : cacheEntry.getMappedRemoteClaims();
508509
}
509510
return cacheEntry == null ? new HashMap<>() : cacheEntry.getUserAttributes();
510511
}
@@ -584,7 +585,7 @@ private Map<String, Object> retrieveClaimsForFederatedUser(OAuthAuthzReqMessageC
584585
Map<ClaimMapping, String> userAttributes = authenticatedUser.getUserAttributes();
585586
// Since this is a federated flow we are retrieving the federated user attributes as well.
586587
Map<ClaimMapping, String> federatedUserAttributes =
587-
oAuth2AuthorizeReqDTO.getUnfilteredFederatedUserAttributes();
588+
oAuth2AuthorizeReqDTO.getMappedRemoteClaims();
588589
userClaimsMappedToOIDCDialect = getOIDCClaimMapFromUserAttributes(userAttributes);
589590
Map<String, Object> federatedUserClaimsMappedToOIDCDialect =
590591
getUserClaimsInOIDCDialectFromFederatedUserAttributes(authzReqMessageContext.getAuthorizationReqDTO()
@@ -641,10 +642,7 @@ private static Map<String, Object> getUserClaimsInOIDCDialectFromFederatedUserAt
641642
String localClaimURI = claimMapping.getLocalClaim().getClaimUri();
642643
String oidcClaimUri = oidcToLocalClaimMappings.entrySet().stream()
643644
.filter(entry -> entry.getValue().equals(localClaimURI))
644-
.map(Map.Entry::getKey)
645-
.findFirst()
646-
.orElse(null);
647-
645+
.map(Map.Entry::getKey).findFirst().orElse(null);
648646
if (oidcClaimUri != null) {
649647
userClaimsInOidcDialect.put(oidcClaimUri, claimValue);
650648
if (log.isDebugEnabled() &&
@@ -717,7 +715,7 @@ private Map<ClaimMapping, String> getUserAttributesFromCacheUsingToken(String ac
717715
AuthorizationGrantCacheEntry cacheEntry = AuthorizationGrantCache.getInstance()
718716
.getValueFromCacheByToken(cacheKey);
719717
if (fetchFederatedUserAttributes) {
720-
return cacheEntry == null ? new HashMap<>() : cacheEntry.getUnfilteredFederatedUserAttributes();
718+
return cacheEntry == null ? new HashMap<>() : cacheEntry.getMappedRemoteClaims();
721719
}
722720
return cacheEntry == null ? new HashMap<>() : cacheEntry.getUserAttributes();
723721
}

components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/openidconnect/JWTAccessTokenOIDCClaimsHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public void testHandleClaimsForOAuthTokenReqMessageContextWithAuthorizationCode(
451451
TestConstants.CLAIM_VALUE2);
452452
AuthorizationGrantCacheEntry authorizationGrantCacheEntry = new
453453
AuthorizationGrantCacheEntry();
454-
authorizationGrantCacheEntry.setUnfilteredFederatedUserAttributes(federatedUserAttributes);
454+
authorizationGrantCacheEntry.setMappedRemoteClaims(federatedUserAttributes);
455455
mockAuthorizationGrantCache(authorizationGrantCacheEntry, authorizationGrantCache);
456456

457457
UserRealm userRealm = getUserRealmWithUserClaims(USER_CLAIMS_MAP);

0 commit comments

Comments
 (0)