Skip to content

Commit

Permalink
Revert "Allow application creation in sub organization level"
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanChathusanda93 authored Jan 7, 2025
1 parent 6def1e0 commit 4f48be1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,15 @@ public boolean doPreCreateApplication(ServiceProvider serviceProvider, String te
throws IdentityApplicationManagementException {

try {
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());
}
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());
}
return true;
} catch (OrganizationManagementClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Organization not found for the tenant: " + tenantDomain);
Expand Down Expand Up @@ -591,7 +584,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 isSharedAppFromSharingProcess(ServiceProvider serviceProvider, String tenantDomain) {
private boolean isSharedAppFromInternalProcess(ServiceProvider serviceProvider, String tenantDomain) {

return serviceProvider.getSpProperties() != null && Arrays.stream(serviceProvider.getSpProperties())
.anyMatch(property -> IS_FRAGMENT_APP.equals(property.getName()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Object[][] getSubOrganizationMetaData() {

return new Object[][]{
// Create application in sub-organization.
{"orgId2", 2, tenantDomain, false, false},
{"orgId2", 2, tenantDomain, false, true},
// 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.
Expand Down

0 comments on commit 4f48be1

Please sign in to comment.