Skip to content

Commit

Permalink
Add request initiating username to privileged carbon context when sta…
Browse files Browse the repository at this point in the history
…rting tenant flow
  • Loading branch information
shanggeeth committed Nov 19, 2023
1 parent 647fdaa commit 1ef5e85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ private void createSharedRolesOnNewRoleCreation(Map<String, Object> eventPropert
String sharedOrganizationId = sharedApplications.get(taskId).getOrganizationId();
String shareAppTenantDomain =
getOrganizationManager().resolveTenantDomain(sharedOrganizationId);
String associatedUserName =
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.setTenantDomain(shareAppTenantDomain, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.setUsername(associatedUserName);
RoleBasicInfo sharedRoleInfo =
getRoleManagementServiceV2().addRole(mainRoleName, Collections.emptyList(),
Collections.emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public void handleEvent(Event event) throws IdentityEventException {
return;
}
String associatedUserId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserId();
String associatedUserName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(associatedUserName);
Role organizationCreatorRole = buildOrgCreatorRole(associatedUserId);
Role administratorRole = buildAdministratorRole(associatedUserId);
getRoleManager().createRole(orgId, organizationCreatorRole);
Expand All @@ -94,6 +96,7 @@ public void handleEvent(Event event) throws IdentityEventException {
if (!OrganizationManagementUtil.isOrganization(tenantDomain)) {
return;
}
String associatedUserName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String associatedUserId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserId();
String associatedOrgId = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getUserResidentOrganizationId();
Expand All @@ -103,6 +106,7 @@ public void handleEvent(Event event) throws IdentityEventException {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(associatedUserName);
userSharingService.shareOrganizationUser(orgId, associatedUserId, associatedOrgId);
String userId = userSharingService
.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, orgId)
Expand Down

0 comments on commit 1ef5e85

Please sign in to comment.