Skip to content
Open
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 @@ -28,6 +28,8 @@
import org.wso2.carbon.identity.claim.metadata.mgt.util.ClaimConstants;
import org.wso2.carbon.identity.claim.metadata.mgt.util.ClaimMetadataUtils;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.user.api.Claim;
import org.wso2.carbon.user.api.ClaimMapping;
import org.wso2.carbon.user.api.UserRealm;
Expand Down Expand Up @@ -60,6 +62,14 @@ public static DefaultClaimMetadataStore getInstance(int tenantId) {
public DefaultClaimMetadataStore(ClaimConfig claimConfig, int tenantId) {

try {
/*
* Child organization tenants do not maintain their own claim metadata. Therefore, the per-tenant
* claim configuration initialization for the tenant must NOT run for child organization tenants.
*/
if (isOrganization(tenantId)) {
Comment on lines 64 to +69

Copy link
Copy Markdown
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 {
/*
* 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)) {

this.tenantId = tenantId;
return;
}
Comment on lines +69 to +72

Copy link
Copy Markdown
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
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;
}

ReadWriteClaimMetadataManager dbBasedClaimMetadataManager = new DBBasedClaimMetadataManager();
if (!skipClaimMetadataPersistence() && dbBasedClaimMetadataManager.getClaimDialects(tenantId).isEmpty()) {
IdentityClaimManagementServiceDataHolder.getInstance().getClaimConfigInitDAO()
Expand All @@ -68,10 +78,27 @@ public DefaultClaimMetadataStore(ClaimConfig claimConfig, int tenantId) {
} catch (ClaimMetadataException e) {
log.error("Error while retrieving claim dialects", e);
}

this.tenantId = tenantId;
}

/**
* Checks whether the given tenant corresponds to a child organization under a root organization.
*
* @param tenantId Tenant id to check.
* @return {@code true} if the tenant is a child organization, {@code false} otherwise.
*/
private boolean isOrganization(int tenantId) {

try {
return OrganizationManagementUtil.isOrganization(tenantId);
} catch (OrganizationManagementException e) {
log.error("Error while checking whether tenant: " + tenantId +
" is a child organization during claim metadata store initialization. " +
"Proceeding with the default claim configuration initialization path.", e);
Comment on lines +95 to +97

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

return false;
}
Comment on lines +94 to +99

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

}

@Override
public String[] getAllClaimUris() throws UserStoreException {

Expand Down
Loading