Skip to content

Fix Filter internal organization scopes for root organization users#2999

Open
BashithaShamila wants to merge 6 commits intowso2-extensions:masterfrom
BashithaShamila:internal_org_scopes
Open

Fix Filter internal organization scopes for root organization users#2999
BashithaShamila wants to merge 6 commits intowso2-extensions:masterfrom
BashithaShamila:internal_org_scopes

Conversation

@BashithaShamila
Copy link
Copy Markdown

This PR introduces a mechanism to filter out internal_org_ scopes when a user is accessing the root organization. Currently, these scopes, which are intended for sub-organizations, can appear in the root organization context.

Changes
Introduced a new configuration RemoveInternalOrgScopesForRootOrg in OAuthServerConfiguration.

Updated RoleBasedScopeValidationHandler to check this configuration.

If enabled, internal_org_ prefixed scopes are removed from the associated scopes list when the user is in the root organization.

Backward Compatibility
The configuration defaults to false.

Existing deployments will retain current behavior (scopes are not removed) unless explicitly enabled in identity.xml.

issue: wso2/product-is#24880

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


BashithaShamila seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment on lines +614 to +623

private void parseRemoveInternalOrgScopesForRootOrg(OMElement oauthConfigElem) {

OMElement removeInternalOrgScopesForRootOrgElem = oauthConfigElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.REMOVE_INTERNAL_ORG_SCOPES_FOR_ROOT_ORG));

if (removeInternalOrgScopesForRootOrgElem != null) {
removeInternalOrgScopesForRootOrg = Boolean.parseBoolean(
removeInternalOrgScopesForRootOrgElem.getText().trim());
}
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
private void parseRemoveInternalOrgScopesForRootOrg(OMElement oauthConfigElem) {
OMElement removeInternalOrgScopesForRootOrgElem = oauthConfigElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.REMOVE_INTERNAL_ORG_SCOPES_FOR_ROOT_ORG));
if (removeInternalOrgScopesForRootOrgElem != null) {
removeInternalOrgScopesForRootOrg = Boolean.parseBoolean(
removeInternalOrgScopesForRootOrgElem.getText().trim());
}
private void parseRemoveInternalOrgScopesForRootOrg(OMElement oauthConfigElem) {
OMElement removeInternalOrgScopesForRootOrgElem = oauthConfigElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.REMOVE_INTERNAL_ORG_SCOPES_FOR_ROOT_ORG));
if (removeInternalOrgScopesForRootOrgElem != null) {
removeInternalOrgScopesForRootOrg = Boolean.parseBoolean(
removeInternalOrgScopesForRootOrgElem.getText().trim());
log.info("Remove internal org scopes for root org enabled: " + removeInternalOrgScopesForRootOrg);
}

Comment on lines +102 to 104

if (StringUtils.isNotBlank(scopeValidationContext.getAuthenticatedUser().getAccessingOrganization())) {
List<String> internalOrgScopes = associatedScopes.stream()
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 (StringUtils.isNotBlank(scopeValidationContext.getAuthenticatedUser().getAccessingOrganization())) {
List<String> internalOrgScopes = associatedScopes.stream()
if (StringUtils.isNotBlank(scopeValidationContext.getAuthenticatedUser().getAccessingOrganization())) {
if (log.isDebugEnabled()) {
log.debug("User is accessing organization: " + scopeValidationContext.getAuthenticatedUser().getAccessingOrganization() + ". Filtering internal scopes.");
}
List<String> internalOrgScopes = associatedScopes.stream()

Comment on lines +110 to +111
if (OAuthServerConfiguration.getInstance().isRemoveInternalOrgScopesForRootOrgEnabled()) {
// Remove Organization scopes issues for the root organization
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 (OAuthServerConfiguration.getInstance().isRemoveInternalOrgScopesForRootOrgEnabled()) {
// Remove Organization scopes issues for the root organization
if (OAuthServerConfiguration.getInstance().isRemoveInternalOrgScopesForRootOrgEnabled()) {
if (log.isDebugEnabled()) {
log.debug("Removing internal organization scopes for root organization access.");
}
// Remove Organization scopes issues for the root organization

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

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.49%. Comparing base (450ce17) to head (181f434).
⚠️ Report is 468 commits behind head on master.

Files with missing lines Patch % Lines
...dentity/oauth/config/OAuthServerConfiguration.java 60.00% 3 Missing and 1 partial ⚠️
...nhandler/impl/RoleBasedScopeValidationHandler.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2999      +/-   ##
============================================
+ Coverage     56.42%   56.49%   +0.06%     
- Complexity    10142    10234      +92     
============================================
  Files           677      677              
  Lines         58487    59388     +901     
  Branches      13897    14044     +147     
============================================
+ Hits          33002    33551     +549     
- Misses        20853    21186     +333     
- Partials       4632     4651      +19     
Flag Coverage Δ
unit 41.85% <42.85%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


private final List<String> restrictedQueryParameters = new ArrayList<>();

private boolean removeInternalOrgScopesForRootOrg = false;
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.

Suggested change
private boolean removeInternalOrgScopesForRootOrg = false;
private boolean disableInternalOrgScopeIssuanceForRootOrg = false;

parseRemoveInternalPrefixFromMappedRolesAttributeInToken(oauthElem);

//Read config for removing internal_org_ scopes for root org
parseRemoveInternalOrgScopesForRootOrg(oauthElem);
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.

Suggested change
parseRemoveInternalOrgScopesForRootOrg(oauthElem);
parseDisableInternalOrgScopeIssuanceForRootOrg(oauthElem);

parseRemoveInternalOrgScopesForRootOrg(oauthElem);
}

private void parseRemoveInternalOrgScopesForRootOrg(OMElement oauthConfigElem) {
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.

Suggested change
private void parseRemoveInternalOrgScopesForRootOrg(OMElement oauthConfigElem) {
private void parseDisableInternalOrgScopeIssuanceForRootOrg(OMElement oauthConfigElem) {


private void parseRemoveInternalOrgScopesForRootOrg(OMElement oauthConfigElem) {

OMElement removeInternalOrgScopesForRootOrgElem = oauthConfigElem.getFirstChildWithName(
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.

Suggested change
OMElement removeInternalOrgScopesForRootOrgElem = oauthConfigElem.getFirstChildWithName(
OMElement disableInternalOrgScopeIssuanceForRootOrg Elem = oauthConfigElem.getFirstChildWithName(

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.

Let's update other places similarly

BashithaShamila and others added 2 commits December 18, 2025 15:13
…o2/carbon/identity/oauth2/validators/validationhandler/impl/RoleBasedScopeValidationHandler.java

Co-authored-by: Sujan Sanjula <56070320+SujanSanjula96@users.noreply.github.com>
…o2/carbon/identity/oauth/config/OAuthServerConfiguration.java

Co-authored-by: Sujan Sanjula <56070320+SujanSanjula96@users.noreply.github.com>
@jenkins-is-staging
Copy link
Copy Markdown

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/20364792534

@jenkins-is-staging
Copy link
Copy Markdown

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/20364792534
Status: success

Copy link
Copy Markdown

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

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

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/20364792534

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.

4 participants