|
139 | 139 | import org.wso2.carbon.identity.event.event.Event;
|
140 | 140 | import org.wso2.carbon.identity.event.services.IdentityEventService;
|
141 | 141 | import org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult;
|
| 142 | +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; |
142 | 143 | import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException;
|
143 | 144 | import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager;
|
144 | 145 | import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
|
@@ -3897,6 +3898,16 @@ public static String preprocessUsername(String username, ServiceProvider service
|
3897 | 3898 | boolean isSaaSApp = serviceProvider.isSaasApp();
|
3898 | 3899 | String appTenantDomain = serviceProvider.getOwner().getTenantDomain();
|
3899 | 3900 |
|
| 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 | + |
3900 | 3911 | if (isLegacySaaSAuthenticationEnabled() && isSaaSApp) {
|
3901 | 3912 | return username;
|
3902 | 3913 | }
|
@@ -4553,4 +4564,28 @@ private static String resolveTenantDomain(HttpServletRequest request) {
|
4553 | 4564 | }
|
4554 | 4565 | return tenantDomain;
|
4555 | 4566 | }
|
| 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 | + } |
4556 | 4591 | }
|
0 commit comments