Skip claim config initialization for organizations#8101
Conversation
| try { | ||
| /* | ||
| * Sub-organization tenants do not maintain their own claim metadata. Therefore, the per-tenant | ||
| * claim configuration initialization for the tenant must NOT run for sub-organization tenants. | ||
| */ | ||
| if (isOrganization(tenantId)) { |
There was a problem hiding this comment.
Log Improvement Suggestion No: 1
| try { | |
| /* | |
| * Sub-organization tenants do not maintain their own claim metadata. Therefore, the per-tenant | |
| * claim configuration initialization for the tenant must NOT run for sub-organization tenants. | |
| */ | |
| if (isOrganization(tenantId)) { | |
| try { | |
| log.debug("Initializing claim metadata store for tenant: " + tenantId); | |
| /* | |
| * Sub-organization tenants do not maintain their own claim metadata. Therefore, the per-tenant | |
| * claim configuration initialization for the tenant must NOT run for sub-organization tenants. | |
| */ | |
| if (isOrganization(tenantId)) { |
| if (isOrganization(tenantId)) { | ||
| this.tenantId = tenantId; | ||
| return; | ||
| } |
There was a problem hiding this comment.
Log Improvement Suggestion No: 2
| if (isOrganization(tenantId)) { | |
| this.tenantId = tenantId; | |
| return; | |
| } | |
| if (isOrganization(tenantId)) { | |
| log.info("Skipping claim metadata initialization for sub-organization tenant: " + tenantId); | |
| this.tenantId = tenantId; | |
| return; | |
| } |
There was a problem hiding this comment.
AI Agent Log Improvement Checklist
- 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 |
📝 WalkthroughWalkthroughThe PR updates ChangesSub-organization tenant detection in claim metadata initialization
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java`:
- Around line 95-97: In DefaultClaimMetadataStore (the initialization path that
checks tenant sub-organization status) change the error logging call that
currently uses log.error(..., e) to log only the error message string (remove
the exception object) so the ERROR log contains no stack trace; if you still
need the exception for diagnostics, log the exception at DEBUG/TRACE using the
same message (e.g., use log.debug(...) with the exception) and keep the ERROR
call as a plain message string without the exception parameter.
- Around line 94-99: The catch in DefaultClaimMetadataStore that currently logs
OrganizationManagementException and returns false allows code to proceed with
default claim initialization for tenants when org-check fails; change the catch
to treat failures as "sub-organization" (fail-closed) by returning true (or
rethrowing the exception) so that the default initialization path is not
executed — locate the boolean org-check method (the
isSubOrganization/organization-check call inside DefaultClaimMetadataStore that
catches OrganizationManagementException) and replace the return false in that
catch with return true (or throw a runtime/checked exception) so
sub-organization tenants are not seeded on org-check errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: ce37eca3-ef6f-4b8c-bf61-4c826b61e660
📒 Files selected for processing (1)
components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java
| } catch (OrganizationManagementException e) { | ||
| log.error("Error while checking whether tenant: " + tenantId + | ||
| " is a sub-organization during claim metadata store initialization. " + | ||
| "Proceeding with the default claim configuration initialization path.", e); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Fail-open fallback can initialize sub-organization tenants on org-check errors.
When tenant-type detection fails, returning false (Line 98) continues into the default initialization path, which can seed claim metadata for sub-organization tenants.
Suggested fix
private boolean isOrganization(int tenantId) {
try {
return OrganizationManagementUtil.isOrganization(tenantId);
} catch (OrganizationManagementException e) {
- log.error("Error while checking whether tenant: " + tenantId +
- " is a sub-organization during claim metadata store initialization. " +
- "Proceeding with the default claim configuration initialization path.", e);
- return false;
+ log.error("Error while checking whether tenant: " + tenantId +
+ " is a sub-organization during claim metadata store initialization. " +
+ "Skipping claim configuration initialization for safety.");
+ return true;
}
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java`
around lines 94 - 99, The catch in DefaultClaimMetadataStore that currently logs
OrganizationManagementException and returns false allows code to proceed with
default claim initialization for tenants when org-check fails; change the catch
to treat failures as "sub-organization" (fail-closed) by returning true (or
rethrowing the exception) so that the default initialization path is not
executed — locate the boolean org-check method (the
isSubOrganization/organization-check call inside DefaultClaimMetadataStore that
catches OrganizationManagementException) and replace the return false in that
catch with return true (or throw a runtime/checked exception) so
sub-organization tenants are not seeded on org-check errors.
| log.error("Error while checking whether tenant: " + tenantId + | ||
| " is a sub-organization during claim metadata store initialization. " + | ||
| "Proceeding with the default claim configuration initialization path.", e); |
There was a problem hiding this comment.
ERROR log should not include the exception object.
This log.error(..., e) pattern violates the repository logging rule for ERROR level in this PR context.
As per coding guidelines, “for ERROR logs, log only the error message (no stack traces/exception objects).”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/DefaultClaimMetadataStore.java`
around lines 95 - 97, In DefaultClaimMetadataStore (the initialization path that
checks tenant sub-organization status) change the error logging call that
currently uses log.error(..., e) to log only the error message string (remove
the exception object) so the ERROR log contains no stack trace; if you still
need the exception for diagnostics, log the exception at DEBUG/TRACE using the
same message (e.g., use log.debug(...) with the exception) and keep the ERROR
call as a plain message string without the exception parameter.
|
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #8101 +/- ##
============================================
- Coverage 53.28% 53.28% -0.01%
Complexity 20627 20627
============================================
Files 2147 2147
Lines 126484 126491 +7
Branches 18132 18133 +1
============================================
- Hits 67403 67395 -8
- Misses 50866 50881 +15
Partials 8215 8215
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



Proposed changes in this pull request
$subject
Child organization tenants do not maintain their own claim metadata. Their claim dialects, local claims, and external claim mappings are resolved hierarchically from the parent (root) organization via UnifiedClaimMetadataManager and OrgResourceResolverService [1]. Therefore, the per-tenant claim configuration initialization (which seeds rows into IDN_CLAIM_DIALECT / IDN_CLAIM / IDN_CLAIM_MAPPED_ATTRIBUTE for the tenant) must NOT run for child organization tenants.
[1] https://github.com/wso2/carbon-identity-framework/blob/master/components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/UnifiedClaimMetadataManager.java#L93