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

Remove Internal domain in application roles when creating JWT access token #2654

Merged
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 @@ -581,6 +581,7 @@ public static class OIDCClaims {
public static final String EMAIL_VERIFIED = "email_verified";
public static final String ADDRESS = "address";
public static final String ROLES = "roles";
public static final String APP_ROLES = "application_roles";
public static final String CUSTOM = "custom";
public static final String AZP = "azp";
public static final String AUTH_TIME = "auth_time";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ private static Map<String, Object> getUserClaimsInOIDCDialectFromFederatedUserAt
String oidcClaimUri = oidcToLocalClaimMappings.entrySet().stream()
.filter(entry -> entry.getValue().equals(localClaimURI))
.map(Map.Entry::getKey).findFirst().orElse(null);
if (oidcClaimUri != null) {
if (oidcClaimUri != null && StringUtils.isNotBlank(claimValue)) {
userClaimsInOidcDialect.put(oidcClaimUri, claimValue);
if (log.isDebugEnabled() &&
IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.LogConstants.ActionIDs.ISSUE_ACCESS_TOKEN;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCClaims.ADDRESS;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCClaims.APP_ROLES;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCClaims.EMAIL_VERIFIED;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCClaims.PHONE_NUMBER_VERIFIED;
import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OIDCClaims.ROLES;
Expand Down Expand Up @@ -137,6 +138,7 @@ public Map<String, Object> getClaimsFilteredByOIDCScopes(Map<String, Object> use
handleAddressClaim(claimsToBeReturned, addressScopeClaims);
}
handleRolesClaim(claimsToBeReturned);
handleApplicationRolesClaim(claimsToBeReturned);
handleUpdateAtClaim(claimsToBeReturned);
handlePhoneNumberVerifiedClaim(claimsToBeReturned);
handleEmailVerifiedClaim(claimsToBeReturned);
Expand Down Expand Up @@ -501,6 +503,23 @@ private void handleRolesClaim(Map<String, Object> returnClaims) {
}
}

private void handleApplicationRolesClaim(Map<String, Object> returnClaims) {

if (returnClaims.containsKey(APP_ROLES) && IdentityUtil.isGroupsVsRolesSeparationImprovementsEnabled()
&& returnClaims.get(APP_ROLES) instanceof String) {
String multiAttributeSeparator = FrameworkUtils.getMultiAttributeSeparator();
List<String> roles = Arrays.asList(returnClaims.get(APP_ROLES).toString().split(multiAttributeSeparator));

for (String role : roles) {
if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(IdentityUtil.extractDomainFromName(role))) {
String domainRemovedRole = UserCoreUtil.removeDomainFromName(role);
roles.set(roles.indexOf(role), domainRemovedRole);
}
}
returnClaims.put(APP_ROLES, StringUtils.join(roles, multiAttributeSeparator));
}
}

private void startTenantFlow(String tenantDomain, int tenantId) {

PrivilegedCarbonContext.startTenantFlow();
Expand Down
Loading