Skip to content

Commit

Permalink
Set authenticated user resident organization ID in the carbon context
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Nov 1, 2023
1 parent 9881415 commit 6e13004
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ protected void postAuthenticate(MessageContext messageContext, AuthenticationRes
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(IdentityUtil.addDomainToName
(user.getUserName(), user.getUserStoreDomain()));
// Set the user's resident organization if user is accessing an organization
IdentityUtil.threadLocalProperties.get().put("USER_RESIDENT_ORG", userResidentOrganization);
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.setUserResidentOrganizationId(userResidentOrganization);
}
// Set the user id to the Carbon context if the user authentication is succeeded.
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ public void invoke(Request request, Response response) throws IOException, Servl
unsetMDCThreadLocals();
// Clear thread local authenticated with basic auth flag.
unsetAuthenticatedWithBasicAuth();

// Clear user resident organization thread local.
IdentityUtil.threadLocalProperties.get().remove("USER_RESIDENT_ORG");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,18 @@ private void startOrganizationBoundTenantFlow(String authorizedOrganization) {

String userId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserId();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String userResidentOrganizationId = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getUserResidentOrganizationId();
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUserId(userId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.setUserResidentOrganizationId(userResidentOrganizationId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setOrganizationId(authorizedOrganization);
try {
String authorizedTenantDomain = AuthorizationValveServiceHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(authorizedOrganization);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(authorizedTenantDomain, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUserId(userId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
} catch (OrganizationManagementException e) {
throw new AuthRuntimeException("Error while resolving tenant domain by organization.", e);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
<osgi.util.tracker.imp.pkg.version.range>[1.5.1, 2.0.0)</osgi.util.tracker.imp.pkg.version.range>

<!-- Carbon Kernel version -->
<carbon.kernel.version>4.9.15</carbon.kernel.version>
<carbon.kernel.version>4.9.17-SNAPSHOT</carbon.kernel.version>
<carbon.kernel.feature.version>4.9.0</carbon.kernel.feature.version>
<carbon.kernel.imp.pkg.version.range>[4.5.0, 5.0.0)</carbon.kernel.imp.pkg.version.range>

Expand Down

0 comments on commit 6e13004

Please sign in to comment.