Skip to content

Commit 3dc9c22

Browse files
Introduce app resident tenant domain extraction and get app resident tenant from pre process username
1 parent 1b0a58e commit 3dc9c22

File tree

1 file changed

+35
-0
lines changed
  • components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util

1 file changed

+35
-0
lines changed

components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java

+35
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
import org.wso2.carbon.identity.event.event.Event;
140140
import org.wso2.carbon.identity.event.services.IdentityEventService;
141141
import org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult;
142+
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
142143
import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException;
143144
import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager;
144145
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
@@ -3897,6 +3898,16 @@ public static String preprocessUsername(String username, ServiceProvider service
38973898
boolean isSaaSApp = serviceProvider.isSaasApp();
38983899
String appTenantDomain = serviceProvider.getOwner().getTenantDomain();
38993900

3901+
// Get the application tenant domain when the request comes from tenant perspective.
3902+
try {
3903+
String appResidentTenantDomain = getAppResidentTenantDomain();
3904+
if (StringUtils.isNotEmpty(appResidentTenantDomain)) {
3905+
appTenantDomain = appResidentTenantDomain;
3906+
}
3907+
} catch (FrameworkException e) {
3908+
log.error("Error while getting the tenant domain of the application owner.", e);
3909+
}
3910+
39003911
if (isLegacySaaSAuthenticationEnabled() && isSaaSApp) {
39013912
return username;
39023913
}
@@ -4553,4 +4564,28 @@ private static String resolveTenantDomain(HttpServletRequest request) {
45534564
}
45544565
return tenantDomain;
45554566
}
4567+
4568+
/**
4569+
* Resolve the tenant domain from the application resident organization id which will be set when the resource
4570+
* is accessing from the tenanted endpoint.
4571+
*
4572+
* @return Application resident tenant domain.
4573+
* @throws FrameworkException When an error occurred while resolving the tenant domain.
4574+
*/
4575+
public static String getAppResidentTenantDomain() throws FrameworkException {
4576+
4577+
String appResidentTenantDomain = null;
4578+
String appResidentOrgId = PrivilegedCarbonContext.getThreadLocalCarbonContext().
4579+
getApplicationResidentOrganizationId();
4580+
if (StringUtils.isNotEmpty(appResidentOrgId)) {
4581+
try {
4582+
appResidentTenantDomain = FrameworkServiceDataHolder.getInstance().getOrganizationManager().
4583+
resolveTenantDomain(appResidentOrgId);
4584+
} catch (OrganizationManagementException e) {
4585+
throw new FrameworkException("Error occurred while resolving the tenant domain for the " +
4586+
"organization id.", e);
4587+
}
4588+
}
4589+
return appResidentTenantDomain;
4590+
}
45564591
}

0 commit comments

Comments
 (0)