Skip to content

Commit

Permalink
Set user resident organization thread local
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Oct 26, 2023
1 parent b389b2a commit b241005
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 @@ -103,14 +103,19 @@ protected void postAuthenticate(MessageContext messageContext, AuthenticationRes
// organization is authorized to access. Skip this for cross tenant scenarios.

String authorizedOrganization = null;
String userResidentOrganization = null;
if (user instanceof AuthenticatedUser) {
authorizedOrganization = ((AuthenticatedUser) user).getAccessingOrganization();
userResidentOrganization = ((AuthenticatedUser) user).getUserResidentOrganization();
}

if (user.getTenantDomain() != null && (user.getTenantDomain()
.equalsIgnoreCase(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()) ||
StringUtils.isNotEmpty(authorizedOrganization))) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(IdentityUtil.addDomainToName
(user.getUserName(), user.getUserStoreDomain()));
// Set the user's resident organization if user not belongs to the accessing organization
IdentityUtil.threadLocalProperties.get().put("USER_RESIDENT_ORG", 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,6 +193,9 @@ 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

0 comments on commit b241005

Please sign in to comment.