Skip to content

Conversation

@ShanChathusanda93
Copy link
Contributor

Proposed changes in this pull request

$subject

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

+ appResidentOrgId + " by using the primary organization");
}
tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
try {
try {
log.debug("Retrieving primary organization for app resident org: " + appResidentOrgId);

String primaryOrgId = FrameworkServiceDataHolder.getInstance().getOrganizationManager()
.getPrimaryOrganizationId(appResidentOrgId);
tenantDomain = FrameworkUtils.resolveTenantDomainFromOrganizationId(primaryOrgId);
} catch (OrganizationManagementException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
} catch (OrganizationManagementException e) {
} catch (OrganizationManagementException e) {
log.error("Failed to retrieve primary organization for org: " + appResidentOrgId + ". Error: " + e.getMessage());

Comment on lines +280 to +284
if (context.getProperty("appResidentOrgId") != null) {
// starting a tenant flow to set the required tenant id, tenant domain and the application
// resident organization in carbon context.
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 3

Suggested change
if (context.getProperty("appResidentOrgId") != null) {
// starting a tenant flow to set the required tenant id, tenant domain and the application
// resident organization in carbon context.
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (context.getProperty("appResidentOrgId") != null) {
log.info("Starting tenant flow for application resident organization");
// starting a tenant flow to set the required tenant id, tenant domain and the application
// resident organization in carbon context.
PrivilegedCarbonContext.startTenantFlow();

Comment on lines +295 to +297
carbonContext.setApplicationResidentOrganizationId(
(String) context.getProperty("appResidentOrgId"));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 4

Suggested change
carbonContext.setApplicationResidentOrganizationId(
(String) context.getProperty("appResidentOrgId"));
}
carbonContext.setApplicationResidentOrganizationId(
(String) context.getProperty("appResidentOrgId"));
if (log.isDebugEnabled()) {
log.debug("Set tenant context - Domain: " + tenantDomain + ", Org ID: " +
context.getProperty("appResidentOrgId"));
}
}

Comment on lines 1607 to 1608
// We use the tenant domain set in context only in tenanted session is enabled.
if (IdentityTenantUtil.isTenantedSessionsEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 5

Suggested change
// We use the tenant domain set in context only in tenanted session is enabled.
if (IdentityTenantUtil.isTenantedSessionsEnabled()) {
// We use the tenant domain set in context only in tenanted session is enabled.
if (IdentityTenantUtil.isTenantedSessionsEnabled()) {
log.debug("Tenanted sessions enabled. Retrieving login tenant domain from context.");

Comment on lines +1611 to +1613
if (StringUtils.isNotBlank(appResidentOrganization)) {
try {
return FrameworkUtils.resolveTenantDomainFromOrganizationId(appResidentOrganization);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 6

Suggested change
if (StringUtils.isNotBlank(appResidentOrganization)) {
try {
return FrameworkUtils.resolveTenantDomainFromOrganizationId(appResidentOrganization);
if (StringUtils.isNotBlank(appResidentOrganization)) {
try {
log.debug("Resolving tenant domain from organization id: " + appResidentOrganization);
return FrameworkUtils.resolveTenantDomainFromOrganizationId(appResidentOrganization);

Comment on lines +554 to +563
String primaryTenantDomain;
try {
// Caching needed here to avoid multiple calls to organization management component.
String primaryOrgId = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
.getPrimaryOrganizationId(accessingOrganization);
primaryTenantDomain = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(primaryOrgId);
} catch (OrganizationManagementException e) {
throw new IdentityRuntimeException(e.getMessage(), e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 7

Suggested change
String primaryTenantDomain;
try {
// Caching needed here to avoid multiple calls to organization management component.
String primaryOrgId = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
.getPrimaryOrganizationId(accessingOrganization);
primaryTenantDomain = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(primaryOrgId);
} catch (OrganizationManagementException e) {
throw new IdentityRuntimeException(e.getMessage(), e);
}
try {
log.debug("Fetching primary organization details for organization: " + accessingOrganization);
// Caching needed here to avoid multiple calls to organization management component.
String primaryOrgId = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
.getPrimaryOrganizationId(accessingOrganization);
primaryTenantDomain = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
.resolveTenantDomain(primaryOrgId);
log.debug("Resolved tenant domain: " + primaryTenantDomain + " for organization: " + accessingOrganization);
} catch (OrganizationManagementException e) {
log.error("Failed to resolve tenant domain for organization: " + accessingOrganization + ". Error: " + e.getMessage());
throw new IdentityRuntimeException(e.getMessage(), e);
}

Copy link
Contributor

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5
#### Log Improvement Suggestion No: 6
#### Log Improvement Suggestion No: 7

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 7, 2026

String applicationResidentOrgId = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getApplicationResidentOrganizationId();
if (applicationResidentOrgId != null && context.getCallerPath().contains(applicationResidentOrgId)) {
context.setProperty("appResidentOrgId", applicationResidentOrgId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use a context parameter to keep the request initiation path mode so that we can handle both supported paths vice versa

String primaryTenantDomain;
try {
// Caching needed here to avoid multiple calls to organization management component.
String primaryOrgId = IdentityCoreServiceDataHolder.getInstance().getOrganizationManager()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will not need these changes if we start the tenant flows identical to how we initialize at valve level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants