diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml
index d65b2ecdd18..b2d1820bc2c 100644
--- a/.github/workflows/pr-builder.yml
+++ b/.github/workflows/pr-builder.yml
@@ -34,7 +34,7 @@ jobs:
distribution: "adopt"
- name: Cache local Maven repository
id: cache-maven-m2
- uses: actions/cache@v2
+ uses: actions/cache@v3
env:
cache-name: cache-m2
with:
diff --git a/components/org.wso2.carbon.identity.api.server.dcr/pom.xml b/components/org.wso2.carbon.identity.api.server.dcr/pom.xml
index 9acdae41cb0..555a114eda6 100644
--- a/components/org.wso2.carbon.identity.api.server.dcr/pom.xml
+++ b/components/org.wso2.carbon.identity.api.server.dcr/pom.xml
@@ -23,12 +23,12 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
../../pom.xml
org.wso2.carbon.identity.api.server.dcr
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
WSO2 Carbon - User DCR Rest API
WSO2 Carbon - User DCR Rest API
diff --git a/components/org.wso2.carbon.identity.api.server.oauth.scope/pom.xml b/components/org.wso2.carbon.identity.api.server.oauth.scope/pom.xml
index 652b447a9b7..bd09fcdf0d8 100644
--- a/components/org.wso2.carbon.identity.api.server.oauth.scope/pom.xml
+++ b/components/org.wso2.carbon.identity.api.server.oauth.scope/pom.xml
@@ -23,12 +23,12 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
../..
org.wso2.carbon.identity.api.server.oauth.scope
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
WSO2 Carbon - Identity OAuth 2.0 Scope Rest APIs
Rest APIs for OAuth 2.0 Scope Handling
diff --git a/components/org.wso2.carbon.identity.client.attestation.filter/pom.xml b/components/org.wso2.carbon.identity.client.attestation.filter/pom.xml
index cabf5a5f17c..3eec0fcac7c 100644
--- a/components/org.wso2.carbon.identity.client.attestation.filter/pom.xml
+++ b/components/org.wso2.carbon.identity.client.attestation.filter/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
../../pom.xml
diff --git a/components/org.wso2.carbon.identity.discovery/pom.xml b/components/org.wso2.carbon.identity.discovery/pom.xml
index 3945add1c8a..35df9eaeffe 100644
--- a/components/org.wso2.carbon.identity.discovery/pom.xml
+++ b/components/org.wso2.carbon.identity.discovery/pom.xml
@@ -21,7 +21,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
../../pom.xml
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
4.0.0
diff --git a/components/org.wso2.carbon.identity.oauth.ciba/pom.xml b/components/org.wso2.carbon.identity.oauth.ciba/pom.xml
index 779c2b42474..338e03742f8 100644
--- a/components/org.wso2.carbon.identity.oauth.ciba/pom.xml
+++ b/components/org.wso2.carbon.identity.oauth.ciba/pom.xml
@@ -20,7 +20,7 @@
identity-inbound-auth-oauth
org.wso2.carbon.identity.inbound.auth.oauth2
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
../../pom.xml
diff --git a/components/org.wso2.carbon.identity.oauth.client.authn.filter/pom.xml b/components/org.wso2.carbon.identity.oauth.client.authn.filter/pom.xml
index 22f237106b7..52e3ab365d5 100644
--- a/components/org.wso2.carbon.identity.oauth.client.authn.filter/pom.xml
+++ b/components/org.wso2.carbon.identity.oauth.client.authn.filter/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
../../pom.xml
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
4.0.0
diff --git a/components/org.wso2.carbon.identity.oauth.common/pom.xml b/components/org.wso2.carbon.identity.oauth.common/pom.xml
index 49389493611..76d94a7b060 100644
--- a/components/org.wso2.carbon.identity.oauth.common/pom.xml
+++ b/components/org.wso2.carbon.identity.oauth.common/pom.xml
@@ -23,7 +23,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
../../pom.xml
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
4.0.0
diff --git a/components/org.wso2.carbon.identity.oauth.dcr.endpoint/pom.xml b/components/org.wso2.carbon.identity.oauth.dcr.endpoint/pom.xml
index d130e616b86..f819caf1f67 100644
--- a/components/org.wso2.carbon.identity.oauth.dcr.endpoint/pom.xml
+++ b/components/org.wso2.carbon.identity.oauth.dcr.endpoint/pom.xml
@@ -6,7 +6,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
../../pom.xml
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
4.0.0
diff --git a/components/org.wso2.carbon.identity.oauth.dcr/pom.xml b/components/org.wso2.carbon.identity.oauth.dcr/pom.xml
index d1ba71ddb3b..9a6697c8c34 100644
--- a/components/org.wso2.carbon.identity.oauth.dcr/pom.xml
+++ b/components/org.wso2.carbon.identity.oauth.dcr/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
../../pom.xml
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
4.0.0
diff --git a/components/org.wso2.carbon.identity.oauth.endpoint/pom.xml b/components/org.wso2.carbon.identity.oauth.endpoint/pom.xml
index ee7db096253..6ebd3f670a7 100644
--- a/components/org.wso2.carbon.identity.oauth.endpoint/pom.xml
+++ b/components/org.wso2.carbon.identity.oauth.endpoint/pom.xml
@@ -22,7 +22,7 @@
org.wso2.carbon.identity.inbound.auth.oauth2
identity-inbound-auth-oauth
../../pom.xml
- 7.0.245-SNAPSHOT
+ 7.0.255-SNAPSHOT
4.0.0
diff --git a/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java b/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java
index 87582e9a246..c64baee318a 100644
--- a/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java
+++ b/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/authz/OAuth2AuthzEndpoint.java
@@ -4206,6 +4206,21 @@ private void associateAuthenticationHistory(SessionDataCacheEntry resultFromLogi
*/
private List getAMRValues(List authMethods, Map authenticatedIdPs) {
+ boolean authenticatorAMREnabled = true;
+ if (authenticatorAMREnabled) {
+ List resultantAuthMethods = new ArrayList<>();
+ for (Map.Entry entry : authenticatedIdPs.entrySet()) {
+ if (entry.getValue() != null && entry.getValue().getAuthenticators() != null) {
+ for (AuthenticatorConfig authenticatorConfig : entry.getValue().getAuthenticators()) {
+ if (authenticatorConfig != null && authenticatorConfig.getAmrValue() != null) {
+ resultantAuthMethods.addAll(Arrays.asList(authenticatorConfig.getAmrValue()));
+ }
+ }
+ }
+ }
+ return resultantAuthMethods;
+ }
+
boolean readAMRValueFromIdp = Boolean.parseBoolean(IdentityUtil.getProperty(
OAuthConstants.READ_AMR_VALUE_FROM_IDP));
if (readAMRValueFromIdp) {
diff --git a/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtil.java b/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtil.java
index fbb1759a450..71b2d2c1950 100644
--- a/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtil.java
+++ b/components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtil.java
@@ -18,13 +18,16 @@
package org.wso2.carbon.identity.oauth.endpoint.util;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.oltu.oauth2.common.error.OAuthError;
import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException;
+import org.wso2.carbon.identity.application.authentication.framework.handler.approles.exception.ApplicationRolesException;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
+import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
import org.wso2.carbon.identity.application.common.model.ClaimMapping;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
@@ -50,6 +53,8 @@
import org.wso2.carbon.identity.oauth2.util.AuthzUtil;
import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
import org.wso2.carbon.identity.openidconnect.OIDCClaimUtil;
+import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
+import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.user.api.RealmConfiguration;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.UserRealm;
@@ -190,13 +195,15 @@ public static Map getClaimsFromUserStore(OAuth2TokenValidationRe
realm = getUserRealm(null, userAccessingTenantDomain);
try {
FrameworkUtils.startTenantFlow(userAccessingTenantDomain);
- userClaims = getUserClaimsFromUserStore(sharedUserId, realm, claimURIList);
+ userClaims = getUserClaimsFromUserStoreWithResolvedRoles(authenticatedUser, serviceProvider,
+ sharedUserId, realm, claimURIList);
} finally {
FrameworkUtils.endTenantFlow();
}
} else {
realm = getUserRealm(null, userTenantDomain);
- userClaims = getUserClaimsFromUserStore(userId, realm, claimURIList);
+ userClaims = getUserClaimsFromUserStoreWithResolvedRoles(authenticatedUser, serviceProvider,
+ userId, realm, claimURIList);
}
if (isNotEmpty(userClaims)) {
@@ -335,6 +342,42 @@ private static Map getUserClaimsFromUserStore(String userId,
return userClaims;
}
+ private static Map getUserClaimsFromUserStoreWithResolvedRoles(AuthenticatedUser authenticatedUser,
+ ServiceProvider serviceProvider,
+ String resolvedUserId,
+ UserRealm realm,
+ List claimURIList)
+ throws UserStoreException {
+
+ Map userClaims = getUserClaimsFromUserStore(resolvedUserId, realm, claimURIList);
+ try {
+ // Check whether the roles claim is requested.
+ boolean isRoleClaimRequested = CollectionUtils.isNotEmpty(claimURIList) &&
+ claimURIList.contains(FrameworkConstants.ROLES_CLAIM);
+ String appTenantDomain = serviceProvider.getTenantDomain();
+ // Check whether the application is a shared app or an application created in sub org.
+ boolean isSubOrgApp = OrganizationManagementUtil.isOrganization(appTenantDomain);
+ // Resolving roles claim for sub org apps and shared apps since backward compatibility is not needed.
+ if (isRoleClaimRequested && isSubOrgApp) {
+ String[] appAssociatedRoles = OIDCClaimUtil.getAppAssociatedRolesOfUser(authenticatedUser,
+ serviceProvider.getApplicationResourceId());
+ if (appAssociatedRoles != null && appAssociatedRoles.length > 0) {
+ // If application associated roles are returned, set the roles claim using resolved roles.
+ userClaims.put(FrameworkConstants.ROLES_CLAIM,
+ String.join(FrameworkUtils.getMultiAttributeSeparator(), appAssociatedRoles));
+ } else {
+ // If no roles are returned, remove the roles claim from user claims.
+ userClaims.remove(FrameworkConstants.ROLES_CLAIM);
+ }
+ }
+ } catch (ApplicationRolesException e) {
+ throw new UserStoreException("Error while retrieving application associated roles for user.", e);
+ } catch (OrganizationManagementException e) {
+ throw new UserStoreException("Error while checking whether application tenant domain is an organization.");
+ }
+ return userClaims;
+ }
+
private static UserRealm getUserRealm(String username,
String userTenantDomain) throws IdentityException, UserInfoEndpointException {
diff --git a/components/org.wso2.carbon.identity.oauth.endpoint/src/test/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtilTest.java b/components/org.wso2.carbon.identity.oauth.endpoint/src/test/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtilTest.java
index 653b754b76f..bc973c12142 100644
--- a/components/org.wso2.carbon.identity.oauth.endpoint/src/test/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtilTest.java
+++ b/components/org.wso2.carbon.identity.oauth.endpoint/src/test/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtilTest.java
@@ -18,6 +18,7 @@
package org.wso2.carbon.identity.oauth.endpoint.util;
import org.apache.commons.collections.map.HashedMap;
+import org.apache.commons.lang.StringUtils;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.testng.MockitoTestNGListener;
@@ -51,6 +52,8 @@
import org.wso2.carbon.identity.oauth2.internal.OAuth2ServiceComponentHolder;
import org.wso2.carbon.identity.oauth2.model.AccessTokenDO;
import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
+import org.wso2.carbon.identity.openidconnect.OIDCClaimUtil;
+import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.user.api.RealmConfiguration;
import org.wso2.carbon.user.core.UserRealm;
import org.wso2.carbon.user.core.UserStoreException;
@@ -119,8 +122,10 @@ public class ClaimUtilTest {
private RoleMapping[] roleMappings;
private ClaimMapping[] requestedClaimMappings;
+ private ClaimMapping[] requestedClaimMappingsWithRoles;
private Map userClaimsMap;
+ private Map userClaimsMapWithRoles;
private Map