Skip to content

Commit

Permalink
Merge pull request #114 from sadilchamishka/remove-obsolete-code
Browse files Browse the repository at this point in the history
Remove the obsolete logic of resolving the authenticated username of organization SSO users
  • Loading branch information
sadilchamishka authored Nov 15, 2023
2 parents 4e07122 + d3d83d2 commit ec208d2
Showing 1 changed file with 0 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.Permission;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
import org.wso2.carbon.user.core.common.User;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.util.UserCoreUtil;
import org.wso2.carbon.user.mgt.UserMgtConstants;
Expand Down Expand Up @@ -224,20 +223,6 @@ public static String getOrganizationId() {
*/
public static String getAuthenticatedUsername() {

String userResidentOrganizationId = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getUserResidentOrganizationId();
/* When user accessing a different organization, the user resident organization is populated in the carbon
context. That value can be used to find the username from the user ID. */
if (StringUtils.isNotEmpty(userResidentOrganizationId)) {
try {
User user = getUserStoreManager(userResidentOrganizationId).getUser(getUserId(), null);
if (user != null) {
return user.getUsername();
}
} catch (OrganizationManagementException | UserStoreException e) {
LOG.debug("Authenticated user's username could not be resolved.", e);
}
}
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
}

Expand Down Expand Up @@ -609,18 +594,6 @@ private static String generatePassword() {
return uuid.toString().substring(0, 12);
}

private static AbstractUserStoreManager getUserStoreManager(String organizationId)
throws UserStoreException, OrganizationManagementException {

String tenantDomain = OrganizationManagementDataHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(organizationId);
int tenantId = OrganizationManagementDataHolder.getInstance().getRealmService().getTenantManager()
.getTenantId(tenantDomain);
RealmService realmService = OrganizationManagementDataHolder.getInstance().getRealmService();
UserRealm tenantUserRealm = realmService.getTenantUserRealm(tenantId);
return (AbstractUserStoreManager) tenantUserRealm.getUserStoreManager();
}

/**
* Check whether the legacy authorization runtime is enabled or not.
*
Expand Down

0 comments on commit ec208d2

Please sign in to comment.