Skip to content

Commit

Permalink
Merge pull request #273 from sadilchamishka/Fix-associated-user-org-i…
Browse files Browse the repository at this point in the history
…ssue

Fix associated user org id resolving issue
  • Loading branch information
sadilchamishka authored Oct 26, 2023
2 parents 6933a5d + 79f66bb commit 3735c86
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package org.wso2.carbon.identity.organization.management.organization.user.sharing.listener;

import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.event.IdentityEventException;
import org.wso2.carbon.identity.event.event.Event;
import org.wso2.carbon.identity.event.handler.AbstractEventHandler;
Expand All @@ -30,17 +32,18 @@
import org.wso2.carbon.identity.organization.management.role.management.service.RoleManager;
import org.wso2.carbon.identity.organization.management.role.management.service.models.Role;
import org.wso2.carbon.identity.organization.management.role.management.service.models.User;
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.Organization;
import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.identity.organization.management.service.util.Utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

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;

/**
* The event handler for sharing the organization creator to the child organization.
Expand All @@ -67,9 +70,11 @@ public void handleEvent(Event event) throws IdentityEventException {
}

String associatedUserId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserId();
// #TODO associatedUserOrgId should be retrieved from the carbon context. As of now, set SUPER_ORG_ID.
// Feature won't work for b2b enabled tenant.
userSharingService.shareOrganizationUser(orgId, associatedUserId, SUPER_ORG_ID);
String associatedOrgId = (String) IdentityUtil.threadLocalProperties.get().get("USER_RESIDENT_ORG");
if (StringUtils.isEmpty(associatedOrgId)) {
associatedOrgId = getOrganizationManager().resolveOrganizationId(Utils.getTenantDomain());
}
userSharingService.shareOrganizationUser(orgId, associatedUserId, associatedOrgId);
String userId = userSharingService.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, orgId)
.getUserId();
Role organizationCreatorRole = buildOrgCreatorRole(userId);
Expand Down Expand Up @@ -124,4 +129,9 @@ private RoleManager getRoleManager() {

return OrganizationUserSharingDataHolder.getInstance().getRoleManager();
}

private OrganizationManager getOrganizationManager() {

return OrganizationUserSharingDataHolder.getInstance().getOrganizationManager();
}
}

0 comments on commit 3735c86

Please sign in to comment.