Skip to content

Commit

Permalink
Merge pull request #302 from shanggeeth/fix-username-null-tenant-flow
Browse files Browse the repository at this point in the history
Fix username being null in carbon context for event handlers hit on org creation flow
  • Loading branch information
shanggeeth authored Nov 19, 2023
2 parents 647fdaa + 1ef5e85 commit 93a2906
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 93a2906

Please sign in to comment.