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

Fix user sharing issue #279

Merged
Merged
Changes from all 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 @@ -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
Loading