From c16a54c13f25519cfba845709ae0e2999ed11c7f Mon Sep 17 00:00:00 2001 From: Shan Chathusanda Jayathilaka Date: Sun, 1 Dec 2024 03:34:35 +0530 Subject: [PATCH] Improve sub org application creation when accessing through tenant perspective --- .../FragmentApplicationMgtListener.java | 35 ++++++++++--------- pom.xml | 6 ++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListener.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListener.java index 283b1294b..f8f647a28 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListener.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListener.java @@ -131,23 +131,26 @@ public boolean isEnable() { public boolean doPreCreateApplication(ServiceProvider serviceProvider, String tenantDomain, String userName) throws IdentityApplicationManagementException { - try { - String organizationId = getOrganizationManager().resolveOrganizationId(tenantDomain); - int organizationDepthInHierarchy = - getOrganizationManager().getOrganizationDepthInHierarchy(organizationId); - if (isSubOrganization(organizationDepthInHierarchy) && - !isSharedAppFromInternalProcess(serviceProvider, tenantDomain)) { - throw new IdentityApplicationManagementClientException( - ERROR_CODE_SUB_ORG_CANNOT_CREATE_APP.getCode(), - ERROR_CODE_SUB_ORG_CANNOT_CREATE_APP.getMessage()); - } - } catch (OrganizationManagementClientException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Organization not found for the tenant: " + tenantDomain); + if (StringUtils.isEmpty(PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getApplicationResidentOrganizationId())) { + try { + String organizationId = getOrganizationManager().resolveOrganizationId(tenantDomain); + int organizationDepthInHierarchy = + getOrganizationManager().getOrganizationDepthInHierarchy(organizationId); + if (isSubOrganization(organizationDepthInHierarchy) && + !isSharedAppFromInternalProcess(serviceProvider, tenantDomain)) { + throw new IdentityApplicationManagementClientException( + ERROR_CODE_SUB_ORG_CANNOT_CREATE_APP.getCode(), + ERROR_CODE_SUB_ORG_CANNOT_CREATE_APP.getMessage()); + } + } catch (OrganizationManagementClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Organization not found for the tenant: " + tenantDomain); + } + } catch (OrganizationManagementException e) { + throw new IdentityApplicationManagementException( + "An error occurred while getting depth of the organization", e); } - } catch (OrganizationManagementException e) { - throw new IdentityApplicationManagementException( - "An error occurred while getting depth of the organization", e); } return true; } diff --git a/pom.xml b/pom.xml index 95995ef12..2a817c228 100644 --- a/pom.xml +++ b/pom.xml @@ -502,9 +502,9 @@ - 4.9.17 - [4.7.0, 5.0.0) - 4.6.0 + 4.10.25 + [4.10.0, 5.0.0) + 4.10.0 [4.7.0, 5.0.0)