Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear org app link #396

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,16 @@ default int getCountOfDiscoverableSharedApplications(String filter, String tenan

return 0;
}

/**
* Check whether the main application has fragment applications.
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved
*
* @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 {
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = :" +
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved
SQLPlaceholders.DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID + ";";

private SQLConstants() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,4 +172,9 @@ List<ApplicationBasicInfo> getDiscoverableSharedApplicationBasicInfo(int limit,
*/
int getCountOfDiscoverableSharedApplications(String filter, String tenantDomain, String rootOrgId)
throws OrganizationManagementException;

default void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException {
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved

return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -380,6 +382,19 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant
return count;
}

@Override
public void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException {
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved

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_DELETING_SHARED_APPLICATION_LINK, e, organizationId);
}
}

private int getCountOfDiscoverableSharedApplications(String tenantDomain, String rootOrgId)
throws OrganizationManagementException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -85,6 +87,7 @@ public void handleEvent(Event event) throws IdentityEventException {
Map<String, Object> eventProperties = event.getEventProperties();
String organizationId = (String) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION_ID);
try {
handleSharedAppDeletionForPostDeleteOrganization(event);
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved
handleMainApplicationUpdateForPreDeleteOrganization(organizationId);
} catch (IdentityApplicationManagementException | OrganizationManagementException e) {
throw new IdentityEventException("An error occurred while retrieving main applications of " +
Expand Down Expand Up @@ -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);
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved
}


private void handleMainApplicationUpdateForPreDeleteOrganization(String organizationId)
throws IdentityApplicationManagementException, OrganizationManagementException {

Expand Down Expand Up @@ -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<BasicOrganization> 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);
Expand Down
Loading