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..842e8bdd5 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 @@ -132,15 +132,22 @@ public boolean doPreCreateApplication(ServiceProvider serviceProvider, String te 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()); + boolean isFragmentApp = serviceProvider.getSpProperties() != null && + Arrays.stream(serviceProvider.getSpProperties()).anyMatch( + property -> IS_FRAGMENT_APP.equals(property.getName()) && + Boolean.parseBoolean(property.getValue())); + if (isFragmentApp) { + String organizationId = getOrganizationManager().resolveOrganizationId(tenantDomain); + int organizationDepthInHierarchy = + getOrganizationManager().getOrganizationDepthInHierarchy(organizationId); + if (isSubOrganization(organizationDepthInHierarchy) && + !isSharedAppFromSharingProcess(serviceProvider, tenantDomain)) { + throw new IdentityApplicationManagementClientException( + ERROR_CODE_SUB_ORG_CANNOT_CREATE_APP.getCode(), + ERROR_CODE_SUB_ORG_CANNOT_CREATE_APP.getMessage()); + } } + return true; } catch (OrganizationManagementClientException e) { if (LOG.isDebugEnabled()) { LOG.debug("Organization not found for the tenant: " + tenantDomain); @@ -584,7 +591,7 @@ private ClaimMapping[] addApplicationRolesToFilteredClaimMappings(ClaimMapping[] * @param tenantDomain The tenant domain which the service provider app is belongs to. * @return True if app is shared by an internal process of Asgardeo for sharing apps to sub organizations. */ - private boolean isSharedAppFromInternalProcess(ServiceProvider serviceProvider, String tenantDomain) { + private boolean isSharedAppFromSharingProcess(ServiceProvider serviceProvider, String tenantDomain) { return serviceProvider.getSpProperties() != null && Arrays.stream(serviceProvider.getSpProperties()) .anyMatch(property -> IS_FRAGMENT_APP.equals(property.getName()) && diff --git a/pom.xml b/pom.xml index 95995ef12..7efab9a5d 100644 --- a/pom.xml +++ b/pom.xml @@ -502,7 +502,7 @@ - 4.9.17 + 4.10.26 [4.7.0, 5.0.0) 4.6.0