Skip to content

Introduce app resident tenant domain extraction and get app resident tenant from pre process username #6586

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -139,6 +139,7 @@
import org.wso2.carbon.identity.event.event.Event;
import org.wso2.carbon.identity.event.services.IdentityEventService;
import org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException;
import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
Expand Down Expand Up @@ -3897,6 +3898,16 @@ public static String preprocessUsername(String username, ServiceProvider service
boolean isSaaSApp = serviceProvider.isSaasApp();
String appTenantDomain = serviceProvider.getOwner().getTenantDomain();

// Get the application tenant domain when the request comes from tenant perspective.
try {
String appResidentTenantDomain = getAppResidentTenantDomain();
if (StringUtils.isNotEmpty(appResidentTenantDomain)) {
appTenantDomain = appResidentTenantDomain;
}
} catch (FrameworkException e) {
log.error("Error while getting the tenant domain of the application owner.", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected behavior when this exception is thrown

}

if (isLegacySaaSAuthenticationEnabled() && isSaaSApp) {
return username;
}
Expand Down Expand Up @@ -4553,4 +4564,28 @@ private static String resolveTenantDomain(HttpServletRequest request) {
}
return tenantDomain;
}

/**
* Resolve the tenant domain from the application resident organization id which will be set when the resource
* is accessing from the tenanted endpoint.
*
* @return Application resident tenant domain.
* @throws FrameworkException When an error occurred while resolving the tenant domain.
*/
private static String getAppResidentTenantDomain() throws FrameworkException {

String appResidentTenantDomain = null;
String appResidentOrgId = PrivilegedCarbonContext.getThreadLocalCarbonContext().
getApplicationResidentOrganizationId();
if (StringUtils.isNotEmpty(appResidentOrgId)) {
try {
appResidentTenantDomain = FrameworkServiceDataHolder.getInstance().getOrganizationManager().
resolveTenantDomain(appResidentOrgId);
} catch (OrganizationManagementException e) {
throw new FrameworkException("Error occurred while resolving the tenant domain for the " +
"organization id.", e);
}
}
return appResidentTenantDomain;
}
}