Skip to content

Commit

Permalink
Handle NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Naduni Pamudika committed Jan 7, 2025
1 parent 7194e8a commit 1f3e7ba
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.wso2.carbon.identity.core.util.IdentityCoreConstants;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.oauth.OAuthAdminService;
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
import org.wso2.carbon.registry.core.ActionConstants;
Expand Down Expand Up @@ -2493,6 +2494,10 @@ public static String[] getListOfRoles(String username) throws APIManagementExcep
try {
int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager()
.getTenantId(tenantDomain);
// If tenant Id is not set in the tokenReqContext, deriving it from username.
if (tenantId == 0 || tenantId == -1) {
tenantId = IdentityTenantUtil.getTenantIdOfUser(username);
}
UserStoreManager manager = ServiceReferenceHolder.getInstance().getRealmService()
.getTenantUserRealm(tenantId).getUserStoreManager();
roles = manager.getRoleListOfUser(MultitenantUtils.getTenantAwareUsername(username));
Expand Down

0 comments on commit 1f3e7ba

Please sign in to comment.