From 5a692daf00d789de691fd339efa3c6f61793ca1c Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Tue, 24 Oct 2023 23:21:40 +0530 Subject: [PATCH] Address review comments --- .../user/sharing/OrganizationUserSharingService.java | 2 +- .../organization/user/sharing/constant/SQLConstants.java | 3 +-- .../internal/OrganizationUserSharingServiceComponent.java | 3 +-- .../SharingOrganizationCreatorUserEventHandler.java | 8 ++++---- .../management/service/dao/RoleManagementDAOImpl.java | 4 +--- .../listeners/TenantAssociationManagementListener.java | 5 +---- .../management/constant/UserInvitationMgtConstants.java | 6 +++--- .../internal/UserInvitationMgtServiceComponent.java | 1 - 8 files changed, 12 insertions(+), 20 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/OrganizationUserSharingService.java b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/OrganizationUserSharingService.java index 3da005c45..1dc2b6154 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/OrganizationUserSharingService.java +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/OrganizationUserSharingService.java @@ -38,7 +38,7 @@ void shareOrganizationUser(String orgId, String associatedUserId, String associa throws OrganizationManagementException; /** - * UnShare all the shared users for the given user. + * Unshare all the shared users for the given user. * * @param associatedUserId The ID of the associated user. * @param associatedOrgId The ID of the organization where the user is managed. diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/constant/SQLConstants.java b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/constant/SQLConstants.java index 539bd15f1..c745c0485 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/constant/SQLConstants.java +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/constant/SQLConstants.java @@ -35,9 +35,8 @@ public class SQLConstants { public static final String GET_ORGANIZATION_USER_ASSOCIATION_FOR_ROOT_USER_IN_ORG = "SELECT UM_USER_ID, " + "UM_ORG_ID, UM_ASSOCIATED_USER_ID, UM_ASSOCIATED_ORG_ID FROM UM_ORG_USER_ASSOCIATION " + "WHERE UM_ASSOCIATED_USER_ID = ? AND UM_ORG_ID = ?"; - public static final String GET_ORGANIZATION_USER_ASSOCIATIONS_FOR_SHARED_USER = "SELECT UM_USER_ID, UM_ORG_ID, " + - "UM_ASSOCIATED_USER_ID, UM_ASSOCIATED_ORG_ID FROM UM_ORG_USER_ASSOCIATION " + + "UM_ASSOCIATED_USER_ID, UM_ASSOCIATED_ORG_ID FROM UM_ORG_USER_ASSOCIATION " + "WHERE UM_USER_ID = ? AND UM_ORG_ID = ?"; /** * SQL placeholders related to organization user sharing SQL operations. diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingServiceComponent.java b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingServiceComponent.java index 68faba500..ca001bc3e 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingServiceComponent.java +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingServiceComponent.java @@ -58,7 +58,7 @@ protected void activate(ComponentContext componentContext) { new SharedUserOperationEventListener(), null); bundleContext.registerService(AbstractEventHandler.class.getName(), new SharingOrganizationCreatorUserEventHandler(), null); - LOG.info("Shared Organization User Listener activated successfully."); + LOG.info("OrganizationUserSharingServiceComponent activated successfully."); } @Reference( @@ -89,7 +89,6 @@ protected void setOrganizationManagementService(OrganizationManager organization OrganizationUserSharingDataHolder.getInstance().setOrganizationManager(organizationManager); LOG.debug("Set Organization Management Service"); - } protected void unsetOrganizationManagementService(OrganizationManager organizationManager) { diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharingOrganizationCreatorUserEventHandler.java b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharingOrganizationCreatorUserEventHandler.java index c17630518..ee898b862 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharingOrganizationCreatorUserEventHandler.java +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharingOrganizationCreatorUserEventHandler.java @@ -32,6 +32,7 @@ import org.wso2.carbon.identity.organization.management.role.management.service.models.User; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; import org.wso2.carbon.identity.organization.management.service.model.Organization; +import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; import java.util.ArrayList; import java.util.Collections; @@ -40,7 +41,6 @@ import static org.wso2.carbon.identity.organization.management.role.management.service.constant.RoleManagementConstants.ORG_ADMINISTRATOR_ROLE; import static org.wso2.carbon.identity.organization.management.role.management.service.constant.RoleManagementConstants.ORG_CREATOR_ROLE; 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.isSubOrganization; /** * The event handler for sharing the organization creator to the child organization. @@ -60,9 +60,9 @@ public void handleEvent(Event event) throws IdentityEventException { String orgId = organization.getId(); try { - int organizationDepth = OrganizationUserSharingDataHolder.getInstance().getOrganizationManager() - .getOrganizationDepthInHierarchy(orgId); - if (!isSubOrganization(organizationDepth)) { + String tenantDomain = OrganizationUserSharingDataHolder.getInstance().getOrganizationManager() + .resolveTenantDomain(orgId); + if (!OrganizationManagementUtil.isOrganization(tenantDomain)) { return; } diff --git a/components/org.wso2.carbon.identity.organization.management.role.management.service/src/main/java/org/wso2/carbon/identity/organization/management/role/management/service/dao/RoleManagementDAOImpl.java b/components/org.wso2.carbon.identity.organization.management.role.management.service/src/main/java/org/wso2/carbon/identity/organization/management/role/management/service/dao/RoleManagementDAOImpl.java index 0ea053f74..b20bc2ec2 100644 --- a/components/org.wso2.carbon.identity.organization.management.role.management.service/src/main/java/org/wso2/carbon/identity/organization/management/role/management/service/dao/RoleManagementDAOImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.role.management.service/src/main/java/org/wso2/carbon/identity/organization/management/role/management/service/dao/RoleManagementDAOImpl.java @@ -454,11 +454,9 @@ public List getUserOrganizationPermissions(String userId, String organiz permissions.addAll(groupAssignedRoles); } - } catch (UserStoreException | DataAccessException e) { + } catch (UserStoreException | DataAccessException | OrganizationManagementException e) { throw handleServerException(ERROR_CODE_ERROR_RETRIEVING_ORGANIZATION_PERMISSIONS, e, organizationId, userId); - } catch (OrganizationManagementException e) { - throw new RuntimeException(e); } return permissions; diff --git a/components/org.wso2.carbon.identity.organization.management.tenant.association/src/main/java/org/wso2/carbon/identity/organization/management/tenant/association/listeners/TenantAssociationManagementListener.java b/components/org.wso2.carbon.identity.organization.management.tenant.association/src/main/java/org/wso2/carbon/identity/organization/management/tenant/association/listeners/TenantAssociationManagementListener.java index f6c4ea211..fcb42d9d3 100644 --- a/components/org.wso2.carbon.identity.organization.management.tenant.association/src/main/java/org/wso2/carbon/identity/organization/management/tenant/association/listeners/TenantAssociationManagementListener.java +++ b/components/org.wso2.carbon.identity.organization.management.tenant.association/src/main/java/org/wso2/carbon/identity/organization/management/tenant/association/listeners/TenantAssociationManagementListener.java @@ -25,7 +25,6 @@ import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants; 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.tenant.association.internal.TenantAssociationDataHolder; import org.wso2.carbon.stratos.common.beans.TenantInfoBean; @@ -75,11 +74,9 @@ public void onTenantCreate(TenantInfoBean tenantInfo) { organization.setType(OrganizationManagementConstants.OrganizationTypes.TENANT.name()); getOrganizationManager().addRootOrganization(tenant.getId(), organization); } - } catch (UserStoreException | OrganizationManagementServerException e) { + } catch (UserStoreException | OrganizationManagementException e) { String error = "Error occurred while adding user-tenant association for the tenant id: " + tenantId; LOG.error(error, e); - } catch (OrganizationManagementException e) { - throw new RuntimeException(e); } } diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java index ce01e64f2..64910ab52 100644 --- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java +++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/constant/UserInvitationMgtConstants.java @@ -108,13 +108,13 @@ public enum ErrorMessage { ERROR_CODE_ACCEPT_INVITATION("10024", "Unable to accept the invitation.", "Could not accept the invitation for the user %s."), - ERROR_CODE_CONSTRUCT_REDIRECT_URL("10029", + ERROR_CODE_CONSTRUCT_REDIRECT_URL("10025", "Unable to construct the redirect URL.", "Unable to construct the redirect URL for invitation acceptance."), - ERROR_CODE_GET_USER_STORE_MANAGER("10031", + ERROR_CODE_GET_USER_STORE_MANAGER("10026", "Unable to get the user store manager.", "Unable to get the user store manager for the tenant."), - ERROR_CODE_GET_TENANT_FROM_ORG("10032", + ERROR_CODE_GET_TENANT_FROM_ORG("10027", "Unable to get the tenant domain.", "Unable to get the tenant domain for the organization %s."), diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java index 938b4f02d..bd05edbce 100644 --- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java +++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/main/java/org/wso2/carbon/identity/organization/user/invitation/management/internal/UserInvitationMgtServiceComponent.java @@ -129,7 +129,6 @@ protected void setOrganizationUserSharingService(OrganizationUserSharingService UserInvitationMgtDataHolder.getInstance().setOrganizationUserSharingService(organizationUserSharingService); LOG.debug("Set organization user association service."); - } protected void unsetOrganizationUserAssociationService(