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/components/org.wso2.carbon.identity.organization.management.application/src/test/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListenerTest.java b/components/org.wso2.carbon.identity.organization.management.application/src/test/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListenerTest.java index 596fb0f90..2c61136b2 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/test/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListenerTest.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/test/java/org/wso2/carbon/identity/organization/management/application/listener/FragmentApplicationMgtListenerTest.java @@ -101,7 +101,7 @@ public Object[][] getSubOrganizationMetaData() { return new Object[][]{ // Create application in sub-organization. - {"orgId2", 2, tenantDomain, false, true}, + {"orgId2", 2, tenantDomain, false, false}, // Create an application in a sub-organization, and it's marked as a fragment app. {"orgId3", 2, tenantDomain, true, true}, // Create an application marked as a fragmented app by an internal process of primaryTenantDomain.