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

Set user resident organization thread local #248

Merged
Merged
Show file tree
Hide file tree
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 @@ -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 is accessing an 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
Loading