From 9a2bd9d27e30d6fccc561ea846b01e74b5464fe7 Mon Sep 17 00:00:00 2001 From: Kayathiri Mahendrakumaran Date: Fri, 4 Oct 2024 15:06:24 +0530 Subject: [PATCH 1/6] Remove application shared link during org deletion --- .../application/OrgApplicationManager.java | 12 +++++++++ .../OrgApplicationManagerImpl.java | 6 +++++ .../application/constant/SQLConstants.java | 3 +++ .../application/dao/OrgApplicationMgtDAO.java | 6 +++++ .../dao/impl/OrgApplicationMgtDAOImpl.java | 17 +++++++++++- .../listener/OrganizationCreationHandler.java | 27 +++++++++++++++---- 6 files changed, 65 insertions(+), 6 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java index 80dadcdd7..d57269e89 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java @@ -212,4 +212,16 @@ default int getCountOfDiscoverableSharedApplications(String filter, String tenan return 0; } + + /** + * Check whether the main application has fragment applications. + * + * @param mainApplicationId Main application ID. + * @return True if the main application has fragment applications. + * @throws OrganizationManagementException If an error occurred when checking fragment applications. + */ + default boolean hasFragmentApps(String mainApplicationId) throws OrganizationManagementException { + + return false; + } } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java index d6c325a56..cb9febd77 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java @@ -729,6 +729,12 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant return getOrgApplicationMgtDAO().getCountOfDiscoverableSharedApplications(filter, tenantDomain, rootOrgId); } + @Override + public boolean hasFragmentApps(String mainApplicationId) throws OrganizationManagementException { + + return getOrgApplicationMgtDAO().hasFragments(mainApplicationId); + } + /** * Returns whether the given application is a main application. * diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java index 3d8f8cf46..3a559bd06 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java @@ -176,6 +176,9 @@ public class SQLConstants { "sa_shared.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? AND (sa_main.IS_DISCOVERABLE = '1' OR " + "sa_shared.IS_DISCOVERABLE = '1')"; + public static final String DELETE_SHARED_APP_LINK = "DELETE FROM SP_SHARED_APP WHERE SHARED_ORG_ID = :" + + SQLPlaceholders.DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID + ";"; + private SQLConstants() { } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java index 0ddd90815..c334394d1 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java @@ -23,6 +23,7 @@ import org.wso2.carbon.identity.organization.management.application.model.SharedApplicationDO; import org.wso2.carbon.identity.organization.management.service.exception.NotImplementedException; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException; import java.util.List; import java.util.Optional; @@ -171,4 +172,9 @@ List getDiscoverableSharedApplicationBasicInfo(int limit, */ int getCountOfDiscoverableSharedApplications(String filter, String tenantDomain, String rootOrgId) throws OrganizationManagementException; + + default void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException { + + return; + } } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java index 9bfd73f2a..39d97b0ef 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java @@ -57,6 +57,7 @@ import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getConsoleAccessUrlFromServerConfig; import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getMyAccountAccessUrlFromServerConfig; import static org.wso2.carbon.identity.organization.management.application.constant.OrgApplicationMgtConstants.IS_FRAGMENT_APP; +import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.DELETE_SHARED_APP_LINK; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_FILTERED_SHARED_APPLICATIONS; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_MAIN_APPLICATION; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_SHARED_APPLICATION; @@ -93,6 +94,7 @@ import static org.wso2.carbon.identity.organization.management.application.util.OrgApplicationManagerUtil.getNewTemplate; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_CHECKING_APPLICATION_HAS_FRAGMENTS; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_CHECKING_APPLICATION_IS_A_FRAGMENT; +import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_DELETING_SHARED_APPLICATION_LINK; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_LINK_APPLICATIONS; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_RESOLVING_MAIN_APPLICATION; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_RESOLVING_SHARED_APPLICATION; @@ -210,7 +212,7 @@ public Optional getSharedApplicationResourceId(String mainAppId, String }); return Optional.ofNullable(sharedAppId); } catch (DataAccessException e) { - throw handleServerException(ERROR_CODE_ERROR_RESOLVING_SHARED_APPLICATION, e, mainAppId, ownerOrgId); + throw handleServerException(ERROR_CODE_ERROR_DELETING_SHARED_APPLICATION_LINK, e, mainAppId, ownerOrgId); } } @@ -380,6 +382,19 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant return count; } + @Override + public void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException { + + NamedJdbcTemplate namedJdbcTemplate = getNewTemplate(); + try { + namedJdbcTemplate.executeUpdate(DELETE_SHARED_APP_LINK, preparedStatement -> { + preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID, organizationId); + }); + } catch (DataAccessException e) { + throw handleServerException(ERROR_CODE_ERROR_UPDATING_APPLICATION_ATTRIBUTE, e, organizationId); + } + } + private int getCountOfDiscoverableSharedApplications(String tenantDomain, String rootOrgId) throws OrganizationManagementException { diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java index 4c76c4745..4c326b192 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.organization.management.application.listener; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -41,7 +42,7 @@ import org.wso2.carbon.identity.organization.management.ext.Constants; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; -import org.wso2.carbon.identity.organization.management.service.model.BasicOrganization; +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException; import org.wso2.carbon.identity.organization.management.service.model.Organization; import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; @@ -54,6 +55,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.ORGANIZATION_ID_PROPERTY; 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; @@ -85,6 +87,7 @@ public void handleEvent(Event event) throws IdentityEventException { Map eventProperties = event.getEventProperties(); String organizationId = (String) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION_ID); try { + handleSharedAppDeletionForPostDeleteOrganization(event); handleMainApplicationUpdateForPreDeleteOrganization(organizationId); } catch (IdentityApplicationManagementException | OrganizationManagementException e) { throw new IdentityEventException("An error occurred while retrieving main applications of " + @@ -158,6 +161,22 @@ private void addSharedApplicationsToOrganization(Organization organization) } } + /** + * Handle shared application deletion for post delete organization. + * + * @param event Event. + */ + private void handleSharedAppDeletionForPostDeleteOrganization(Event event) + throws OrganizationManagementServerException { + + String organizationId = (String) event.getEventProperties().get(ORGANIZATION_ID_PROPERTY); + if (StringUtils.isBlank(organizationId)) { + return; + } + getOrgApplicationMgtDAO().deleteSharedAppLink(organizationId); + } + + private void handleMainApplicationUpdateForPreDeleteOrganization(String organizationId) throws IdentityApplicationManagementException, OrganizationManagementException { @@ -199,17 +218,15 @@ private void handleMainApplicationUpdateForPostDeleteOrganization() throws Ident // All the applications have the same tenant ID. Therefore, tenant ID of the first application is used. int rootTenantId = getApplicationManagementService().getTenantIdByApp(mainAppIds.get(0)); String rootTenantDomain = IdentityTenantUtil.getTenantDomain(rootTenantId); - String rootOrganizationId = getOrganizationManager().resolveOrganizationId(rootTenantDomain); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(rootTenantDomain, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); for (String mainAppId : mainAppIds) { - List applicationSharedOrganizations = getOrgApplicationManager() - .getApplicationSharedOrganizations(rootOrganizationId, mainAppId); + boolean hasFragmentsApps = getOrgApplicationManager().hasFragmentApps(mainAppId); // Since the application doesn't have any shared organizations, isAppShared service provider property // should be set to false. - if (CollectionUtils.isEmpty(applicationSharedOrganizations)) { + if (!hasFragmentsApps) { ServiceProvider mainApplication = getApplicationManagementService() .getApplicationByResourceId(mainAppId, rootTenantDomain); updateApplicationWithIsAppSharedProperty(false, mainApplication); From 2256244294cdabcc7d535b73e14c3b5c8979c21d Mon Sep 17 00:00:00 2001 From: Kayathiri Mahendrakumaran Date: Fri, 4 Oct 2024 15:11:05 +0530 Subject: [PATCH 2/6] Refactor code --- .../application/dao/impl/OrgApplicationMgtDAOImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java index 39d97b0ef..b5744af35 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java @@ -212,7 +212,7 @@ public Optional getSharedApplicationResourceId(String mainAppId, String }); return Optional.ofNullable(sharedAppId); } catch (DataAccessException e) { - throw handleServerException(ERROR_CODE_ERROR_DELETING_SHARED_APPLICATION_LINK, e, mainAppId, ownerOrgId); + throw handleServerException(ERROR_CODE_ERROR_RESOLVING_SHARED_APPLICATION, e, mainAppId, ownerOrgId); } } @@ -391,7 +391,7 @@ public void deleteSharedAppLink(String organizationId) throws OrganizationManage preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID, organizationId); }); } catch (DataAccessException e) { - throw handleServerException(ERROR_CODE_ERROR_UPDATING_APPLICATION_ATTRIBUTE, e, organizationId); + throw handleServerException(ERROR_CODE_ERROR_DELETING_SHARED_APPLICATION_LINK, e, organizationId); } } From 42419c0fd5eb153bbcb421c059ab9cd6c9faab4e Mon Sep 17 00:00:00 2001 From: Kayathiri Mahendrakumaran Date: Fri, 4 Oct 2024 16:51:02 +0530 Subject: [PATCH 3/6] Fix comments --- .../application/OrgApplicationManager.java | 8 ++++---- .../OrgApplicationManagerImpl.java | 2 +- .../application/constant/SQLConstants.java | 2 +- .../application/dao/OrgApplicationMgtDAO.java | 2 +- .../dao/impl/OrgApplicationMgtDAOImpl.java | 6 +++--- .../listener/OrganizationCreationHandler.java | 19 ++++++++----------- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java index d57269e89..cb5c06d40 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java @@ -214,13 +214,13 @@ default int getCountOfDiscoverableSharedApplications(String filter, String tenan } /** - * Check whether the main application has fragment applications. + * Check whether the main application has shared applications. * * @param mainApplicationId Main application ID. - * @return True if the main application has fragment applications. - * @throws OrganizationManagementException If an error occurred when checking fragment applications. + * @return True if the main application has shared applications. + * @throws OrganizationManagementException If an error occurred when checking shared applications. */ - default boolean hasFragmentApps(String mainApplicationId) throws OrganizationManagementException { + default boolean hasSharedApps(String mainApplicationId) throws OrganizationManagementException { return false; } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java index cb9febd77..f65434de2 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java @@ -730,7 +730,7 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant } @Override - public boolean hasFragmentApps(String mainApplicationId) throws OrganizationManagementException { + public boolean hasSharedApps(String mainApplicationId) throws OrganizationManagementException { return getOrgApplicationMgtDAO().hasFragments(mainApplicationId); } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java index 3a559bd06..008a739e5 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java @@ -176,7 +176,7 @@ public class SQLConstants { "sa_shared.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? AND (sa_main.IS_DISCOVERABLE = '1' OR " + "sa_shared.IS_DISCOVERABLE = '1')"; - public static final String DELETE_SHARED_APP_LINK = "DELETE FROM SP_SHARED_APP WHERE SHARED_ORG_ID = :" + + public static final String DELETE_SHARED_APP_LINKS_OF_ORG = "DELETE FROM SP_SHARED_APP WHERE SHARED_ORG_ID = :" + SQLPlaceholders.DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID + ";"; private SQLConstants() { diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java index c334394d1..ca243cf37 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java @@ -173,7 +173,7 @@ List getDiscoverableSharedApplicationBasicInfo(int limit, int getCountOfDiscoverableSharedApplications(String filter, String tenantDomain, String rootOrgId) throws OrganizationManagementException; - default void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException { + default void deleteSharedAppLinks(String organizationId) throws OrganizationManagementServerException { return; } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java index b5744af35..3717d1eff 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java @@ -57,7 +57,7 @@ import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getConsoleAccessUrlFromServerConfig; import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getMyAccountAccessUrlFromServerConfig; import static org.wso2.carbon.identity.organization.management.application.constant.OrgApplicationMgtConstants.IS_FRAGMENT_APP; -import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.DELETE_SHARED_APP_LINK; +import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.DELETE_SHARED_APP_LINKS_OF_ORG; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_FILTERED_SHARED_APPLICATIONS; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_MAIN_APPLICATION; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_SHARED_APPLICATION; @@ -383,11 +383,11 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant } @Override - public void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException { + public void deleteSharedAppLinks(String organizationId) throws OrganizationManagementServerException { NamedJdbcTemplate namedJdbcTemplate = getNewTemplate(); try { - namedJdbcTemplate.executeUpdate(DELETE_SHARED_APP_LINK, preparedStatement -> { + namedJdbcTemplate.executeUpdate(DELETE_SHARED_APP_LINKS_OF_ORG, preparedStatement -> { preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID, organizationId); }); } catch (DataAccessException e) { diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java index 4c326b192..dd4dc6eac 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java @@ -55,7 +55,6 @@ 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.ORGANIZATION_ID_PROPERTY; 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; @@ -71,9 +70,10 @@ public class OrganizationCreationHandler extends AbstractEventHandler { public void handleEvent(Event event) throws IdentityEventException { String eventName = event.getEventName(); + Map eventProperties = event.getEventProperties(); + String organizationId = (String) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION_ID); if (Constants.EVENT_POST_ADD_ORGANIZATION.equals(eventName)) { - Map eventProperties = event.getEventProperties(); Organization organization = (Organization) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION); try { addSharedApplicationsToOrganization(organization); @@ -84,10 +84,7 @@ public void handleEvent(Event event) throws IdentityEventException { } if (Constants.EVENT_PRE_DELETE_ORGANIZATION.equals(eventName)) { - Map eventProperties = event.getEventProperties(); - String organizationId = (String) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION_ID); try { - handleSharedAppDeletionForPostDeleteOrganization(event); handleMainApplicationUpdateForPreDeleteOrganization(organizationId); } catch (IdentityApplicationManagementException | OrganizationManagementException e) { throw new IdentityEventException("An error occurred while retrieving main applications of " + @@ -97,6 +94,7 @@ public void handleEvent(Event event) throws IdentityEventException { if (Constants.EVENT_POST_DELETE_ORGANIZATION.equals(eventName)) { try { + handleSharedAppDeletionForPostDeleteOrganization(organizationId); handleMainApplicationUpdateForPostDeleteOrganization(); } catch (OrganizationManagementException | IdentityApplicationManagementException e) { throw new IdentityEventException("An error occurred while updating main application based " + @@ -164,16 +162,15 @@ private void addSharedApplicationsToOrganization(Organization organization) /** * Handle shared application deletion for post delete organization. * - * @param event Event. + * @param organizationId ID of the organization. */ - private void handleSharedAppDeletionForPostDeleteOrganization(Event event) + private void handleSharedAppDeletionForPostDeleteOrganization(String organizationId) throws OrganizationManagementServerException { - String organizationId = (String) event.getEventProperties().get(ORGANIZATION_ID_PROPERTY); if (StringUtils.isBlank(organizationId)) { return; } - getOrgApplicationMgtDAO().deleteSharedAppLink(organizationId); + getOrgApplicationMgtDAO().deleteSharedAppLinks(organizationId); } @@ -223,10 +220,10 @@ private void handleMainApplicationUpdateForPostDeleteOrganization() throws Ident PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(rootTenantDomain, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); for (String mainAppId : mainAppIds) { - boolean hasFragmentsApps = getOrgApplicationManager().hasFragmentApps(mainAppId); + boolean hasSharedApps = getOrgApplicationManager().hasSharedApps(mainAppId); // Since the application doesn't have any shared organizations, isAppShared service provider property // should be set to false. - if (!hasFragmentsApps) { + if (!hasSharedApps) { ServiceProvider mainApplication = getApplicationManagementService() .getApplicationByResourceId(mainAppId, rootTenantDomain); updateApplicationWithIsAppSharedProperty(false, mainApplication); From e06fc197fcd2c0bb801d73e38c09d137ba24a205 Mon Sep 17 00:00:00 2001 From: Kayathiri Mahendrakumaran Date: Fri, 4 Oct 2024 17:11:29 +0530 Subject: [PATCH 4/6] Add constants --- .../management/application/dao/OrgApplicationMgtDAO.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java index ca243cf37..e0bf303c2 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java @@ -23,7 +23,6 @@ import org.wso2.carbon.identity.organization.management.application.model.SharedApplicationDO; import org.wso2.carbon.identity.organization.management.service.exception.NotImplementedException; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; -import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException; import java.util.List; import java.util.Optional; @@ -173,7 +172,7 @@ List getDiscoverableSharedApplicationBasicInfo(int limit, int getCountOfDiscoverableSharedApplications(String filter, String tenantDomain, String rootOrgId) throws OrganizationManagementException; - default void deleteSharedAppLinks(String organizationId) throws OrganizationManagementServerException { + default void deleteSharedAppLinks(String organizationId) throws OrganizationManagementException { return; } From ace58e53d581967671bd87cbd44f2c58aed89c9b Mon Sep 17 00:00:00 2001 From: Kayathiri Mahendrakumaran Date: Fri, 4 Oct 2024 18:31:09 +0530 Subject: [PATCH 5/6] Bump organization management core --- .../management/application/dao/OrgApplicationMgtDAO.java | 7 +++++++ .../application/listener/OrganizationCreationHandler.java | 5 ++--- pom.xml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java index e0bf303c2..7267f9669 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java @@ -172,6 +172,13 @@ List getDiscoverableSharedApplicationBasicInfo(int limit, int getCountOfDiscoverableSharedApplications(String filter, String tenantDomain, String rootOrgId) throws OrganizationManagementException; + /** + * Delete shared application links of an organization. + * + * @param organizationId The unique ID of the organization. + * @throws OrganizationManagementException the server exception is thrown in a failure when deleting the shared + * applications. + */ default void deleteSharedAppLinks(String organizationId) throws OrganizationManagementException { return; diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java index dd4dc6eac..ae502233d 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java @@ -42,7 +42,6 @@ import org.wso2.carbon.identity.organization.management.ext.Constants; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; -import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException; import org.wso2.carbon.identity.organization.management.service.model.Organization; import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; @@ -165,7 +164,7 @@ private void addSharedApplicationsToOrganization(Organization organization) * @param organizationId ID of the organization. */ private void handleSharedAppDeletionForPostDeleteOrganization(String organizationId) - throws OrganizationManagementServerException { + throws OrganizationManagementException { if (StringUtils.isBlank(organizationId)) { return; @@ -221,7 +220,7 @@ private void handleMainApplicationUpdateForPostDeleteOrganization() throws Ident PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); for (String mainAppId : mainAppIds) { boolean hasSharedApps = getOrgApplicationManager().hasSharedApps(mainAppId); - // Since the application doesn't have any shared organizations, isAppShared service provider property + // Since the application doesn't have any shared applications, isAppShared service provider property // should be set to false. if (!hasSharedApps) { ServiceProvider mainApplication = getApplicationManagementService() diff --git a/pom.xml b/pom.xml index f2f1f6a76..3a8daca28 100644 --- a/pom.xml +++ b/pom.xml @@ -517,7 +517,7 @@ [1.0.0,2.0.0) - 1.1.9 + 1.1.16 [1.0.0,2.0.0) From 876ae747740dbd1dbd531353c5bc2c0869199f26 Mon Sep 17 00:00:00 2001 From: Kayathiri Mahendrakumaran Date: Sun, 6 Oct 2024 15:06:37 +0530 Subject: [PATCH 6/6] Refactor code --- .../application/listener/OrganizationCreationHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java index ae502233d..c47add0e6 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java @@ -172,7 +172,6 @@ private void handleSharedAppDeletionForPostDeleteOrganization(String organizatio getOrgApplicationMgtDAO().deleteSharedAppLinks(organizationId); } - private void handleMainApplicationUpdateForPreDeleteOrganization(String organizationId) throws IdentityApplicationManagementException, OrganizationManagementException {