Skip to content

Commit

Permalink
Improve app sharing logic during organization creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SujanSanjula96 committed Sep 30, 2024
1 parent 63bf95e commit b2f73d4
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

import static org.wso2.carbon.identity.organization.management.application.constant.OrgApplicationMgtConstants.SHARE_WITH_ALL_CHILDREN;
import static org.wso2.carbon.identity.organization.management.application.util.OrgApplicationManagerUtil.setIsAppSharedProperty;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.IS_APP_SHARED;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SUPER_ORG_ID;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.getAuthenticatedUsername;

Expand Down Expand Up @@ -143,17 +144,10 @@ private void addSharedApplicationsToOrganization(Organization organization)
if (mainApplication != null && Arrays.stream(mainApplication.getSpProperties())
.anyMatch(p -> SHARE_WITH_ALL_CHILDREN.equalsIgnoreCase(
p.getName()) && Boolean.parseBoolean(p.getValue()))) {
String mainAppOrgId = getOrganizationManager().resolveOrganizationId(mainApplication
.getTenantDomain());
List<BasicOrganization> applicationSharedOrganizations = getOrgApplicationManager()
.getApplicationSharedOrganizations(mainAppOrgId,
mainApplication.getApplicationResourceId());
// Having an empty list implies that this is the first organization to which the application is
// shared with.
boolean updateIsAppSharedProperty = CollectionUtils.isEmpty(applicationSharedOrganizations);
getOrgApplicationManager().shareApplication(parentOrgId, organization.getId(),
mainApplication, true);
if (updateIsAppSharedProperty) {
boolean isAppShared = isAppShared(mainApplication);
if (!isAppShared) {
updateApplicationWithIsAppSharedProperty(true, mainApplication);
}
}
Expand Down Expand Up @@ -238,6 +232,12 @@ private void updateApplicationWithIsAppSharedProperty(boolean isAppShared, Servi
}
}

private boolean isAppShared(ServiceProvider mainApplication) {

return Arrays.stream(mainApplication.getSpProperties())
.anyMatch(p -> IS_APP_SHARED.equalsIgnoreCase(p.getName()) && Boolean.parseBoolean(p.getValue()));
}

private ApplicationManagementService getApplicationManagementService() {

return OrgApplicationMgtDataHolder.getInstance().getApplicationManagementService();
Expand Down

0 comments on commit b2f73d4

Please sign in to comment.