Skip to content

[Sync][master -> next][#3153]: Improve token validation for sub organization applications#3182

Open
github-actions[bot] wants to merge 2 commits intonextfrom
sync-pr-3153-to-next
Open

[Sync][master -> next][#3153]: Improve token validation for sub organization applications#3182
github-actions[bot] wants to merge 2 commits intonextfrom
sync-pr-3153-to-next

Conversation

@github-actions
Copy link
Copy Markdown

@github-actions github-actions bot commented Apr 8, 2026

🤖 Auto-sync from master

This PR automatically syncs the changes from #3153 to the next branch.

Original PR: #3153
Author: @ShanChathusanda93
Total commits: 2
Workflow run: https://github.com/wso2-extensions/identity-inbound-auth-oauth/actions/runs/24118391220

Commits:

38792dbc92 Improve sub organization token validation
d1cd794474 Improve token validation for sub organization applications

Comment on lines 123 to +124
introspectionRequest.setRequiredClaimURIs(claimsUris);
introspectionRequest.setIntrospectionRequest(true);
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
introspectionRequest.setRequiredClaimURIs(claimsUris);
introspectionRequest.setIntrospectionRequest(true);
introspectionRequest.setRequiredClaimURIs(claimsUris);
introspectionRequest.setIntrospectionRequest(true);
log.info("Processing token introspection request");

Comment on lines +1051 to +1058
private void validateIntrospectionForSubOrgTokens(String tenantDomain, AccessTokenDO accessTokenDO,
boolean isIntrospectionRequest)
throws OrganizationManagementException, IdentityOAuth2Exception, InvalidOAuthClientException {

String accessingOrgID = accessTokenDO.getAuthzUser().getAccessingOrganization();
String orgIdOfIntrospectingTenant = OAuthComponentServiceHolder.getInstance().getOrganizationManager()
String introspectingTenantOrgId = OAuthComponentServiceHolder.getInstance().getOrganizationManager()
.resolveOrganizationId(tenantDomain);
boolean isValidToken = true;
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
private void validateIntrospectionForSubOrgTokens(String tenantDomain, AccessTokenDO accessTokenDO,
boolean isIntrospectionRequest)
throws OrganizationManagementException, IdentityOAuth2Exception, InvalidOAuthClientException {
String accessingOrgID = accessTokenDO.getAuthzUser().getAccessingOrganization();
String orgIdOfIntrospectingTenant = OAuthComponentServiceHolder.getInstance().getOrganizationManager()
String introspectingTenantOrgId = OAuthComponentServiceHolder.getInstance().getOrganizationManager()
.resolveOrganizationId(tenantDomain);
boolean isValidToken = true;
private void validateIntrospectionForSubOrgTokens(String tenantDomain, AccessTokenDO accessTokenDO,
boolean isIntrospectionRequest)
throws OrganizationManagementException, IdentityOAuth2Exception, InvalidOAuthClientException {
String accessingOrgID = accessTokenDO.getAuthzUser().getAccessingOrganization();
String introspectingTenantOrgId = OAuthComponentServiceHolder.getInstance().getOrganizationManager()
.resolveOrganizationId(tenantDomain);
log.debug("Validating introspection for sub-org tokens. Accessing Org: " + accessingOrgID +
", Introspecting Tenant Org: " + introspectingTenantOrgId);
boolean isValidToken = true;

Comment on lines +1116 to +1119
}

if (!isValidToken) {
throw new IllegalArgumentException("Invalid Access Token. ACTIVE access token is not found.");
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: 3

Suggested change
}
if (!isValidToken) {
throw new IllegalArgumentException("Invalid Access Token. ACTIVE access token is not found.");
if (!isValidToken) {
log.error("Token validation failed for accessing org: " + accessingOrgID +
" and introspecting tenant org: " + introspectingTenantOrgId);
throw new IllegalArgumentException("Invalid Access Token. ACTIVE access token is not found.");
}

Comment on lines +602 to +605
@Test(dataProvider = "dataProviderForValidateIntrospectionForSubOrgTokens")
public void testValidateIntrospectionForSubOrgTokens(String accessingOrgID, String introspectingTenantOrgId,
String primaryOrgOfAccessingOrg, boolean isAppInSubOrg, boolean isFragmentApp, IssuerDetails issuerDetails,
boolean issuerIsOrg, String accessingOrgIdFromPath, boolean isIntrospectionRequest, boolean expectedValid)
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: 4

Suggested change
@Test(dataProvider = "dataProviderForValidateIntrospectionForSubOrgTokens")
public void testValidateIntrospectionForSubOrgTokens(String accessingOrgID, String introspectingTenantOrgId,
String primaryOrgOfAccessingOrg, boolean isAppInSubOrg, boolean isFragmentApp, IssuerDetails issuerDetails,
boolean issuerIsOrg, String accessingOrgIdFromPath, boolean isIntrospectionRequest, boolean expectedValid)
public void testValidateIntrospectionForSubOrgTokens(String accessingOrgID, String introspectingTenantOrgId,
String primaryOrgOfAccessingOrg, boolean isAppInSubOrg, boolean isFragmentApp, IssuerDetails issuerDetails,
boolean issuerIsOrg, String accessingOrgIdFromPath, boolean isIntrospectionRequest, boolean expectedValid)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Testing introspection validation for sub-org tokens with accessingOrgID: " + accessingOrgID +
", introspectingTenantOrgId: " + introspectingTenantOrgId +
", isAppInSubOrg: " + isAppInSubOrg);
}

Comment on lines +706 to +707
validationRequest.setAccessToken(accessToken);
validationRequest.setIntrospectionRequest(isIntrospectionRequest);
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: 5

Suggested change
validationRequest.setAccessToken(accessToken);
validationRequest.setIntrospectionRequest(isIntrospectionRequest);
OAuth2IntrospectionResponseDTO response = tokenValidationHandler
.buildIntrospectionResponse(validationRequest);
if (log.isDebugEnabled()) {
log.debug("Introspection response received. Expected valid: " + expectedValid +
", Actual error: " + (response.getError() != null ? response.getError() : "none"));
}

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

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.

1 participant