Skip to content

Commit

Permalink
Merge pull request #12005 from lakshithagunasekara/enduser-claim-master
Browse files Browse the repository at this point in the history
Fix the enduser claim of backend jwt to adher with enable.tenant.aware.subclaim property
  • Loading branch information
npamudika authored Jan 17, 2024
2 parents 75d2276 + 8721a6f commit 0ff726f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.wso2.carbon.registry.core.session.UserRegistry;
import org.wso2.carbon.user.core.UserCoreConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -1025,6 +1026,12 @@ private static void constructJWTContent(JSONObject subscribedAPI,
Map<String, Object> claims = jwtInfoDto.getJwtValidationInfo().getClaims();
if (claims.get(JWTConstants.SUB) != null) {
String sub = (String) jwtInfoDto.getJwtValidationInfo().getClaims().get(JWTConstants.SUB);

// A system property is used to enable/disable getting the tenant aware username as sub claim.
String tenantAwareSubClaim = System.getProperty(APIConstants.ENABLE_TENANT_AWARE_SUB_CLAIM);
if (StringUtils.isNotEmpty(tenantAwareSubClaim) && Boolean.parseBoolean(tenantAwareSubClaim)) {
sub = MultitenantUtils.getTenantAwareUsername(sub);
}
jwtInfoDto.setSub(sub);
}
if (claims.get(JWTConstants.ORGANIZATIONS) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3030,4 +3030,7 @@ public static class APILogHandler {

public static final String MIGRATE = "migrate";
public static final String SWAGGER_RELAXED_VALIDATION = "swaggerRelaxedValidation";

//Property for enabling tenant aware sub claims when invoking APIs with API key
public static final String ENABLE_TENANT_AWARE_SUB_CLAIM= "enable.tenant.aware.subclaim";
}

0 comments on commit 0ff726f

Please sign in to comment.