Skip to content

Commit

Permalink
Merge pull request #279 from sadilchamishka/fix-user-creation-issue
Browse files Browse the repository at this point in the history
Fix user sharing issue
  • Loading branch information
sadilchamishka authored Oct 30, 2023
2 parents 86ca738 + 8b802f8 commit 335aa3b
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@ public void handleEvent(Event event) throws IdentityEventException {
if (StringUtils.isEmpty(associatedOrgId)) {
associatedOrgId = getOrganizationManager().resolveOrganizationId(Utils.getTenantDomain());
}
userSharingService.shareOrganizationUser(orgId, associatedUserId, associatedOrgId);
String userId = userSharingService.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, orgId)
.getUserId();
assignUserToAdminRole(userId, orgId, tenantDomain);
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
userSharingService.shareOrganizationUser(orgId, associatedUserId, associatedOrgId);
String userId = userSharingService
.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, orgId)
.getUserId();
assignUserToAdminRole(userId, orgId, tenantDomain);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
} catch (OrganizationManagementException e) {
throw new IdentityEventException("An error occurred while sharing the organization creator to the " +
"organization : " + orgId, e);
Expand All @@ -93,15 +100,9 @@ private void assignUserToAdminRole(String userId, String organizationId, String
try {
String adminRoleId = OrganizationUserSharingDataHolder.getInstance().getRoleManagementService()
.getRoleIdByName(adminRoleName, RoleConstants.ORGANIZATION, organizationId, tenantDomain);
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
OrganizationUserSharingDataHolder.getInstance().getRoleManagementService()
.updateUserListOfRole(adminRoleId,
Collections.singletonList(userId), Collections.emptyList(), tenantDomain);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
OrganizationUserSharingDataHolder.getInstance().getRoleManagementService()
.updateUserListOfRole(adminRoleId, Collections.singletonList(userId), Collections.emptyList(),
tenantDomain);
} catch (IdentityRoleManagementException e) {
throw new IdentityEventException("An error occurred while assigning the user to the administrator role", e);
}
Expand Down

0 comments on commit 335aa3b

Please sign in to comment.