Improve username claim validation to handle domain-prefixed usernames during JIT provisioning#4578
Improve username claim validation to handle domain-prefixed usernames during JIT provisioning#4578Zeta201 wants to merge 2 commits intowso2:4.12.xfrom
Conversation
…ing JIT provisioning
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughUsername-claim validation in user creation was changed to normalize both the stored username and the claim value by removing userstore domain prefixes (with a null-check on the claim) before comparison; a related comment was adjusted. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.42.1)core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.javaThanks 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 |
...arbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java
Outdated
Show resolved
Hide resolved
...arbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java
Outdated
Show resolved
Hide resolved
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java`:
- Around line 5096-5097: The null value for the username claim can cause a
NullPointerException when calling
UserCoreUtil.removeDomainFromName(claims.get(USERNAME_CLAIM_URI))); update the
conditional in AbstractUserStoreManager to first retrieve the claim value into a
local (e.g., String usernameClaim = claims.get(USERNAME_CLAIM_URI)), check for
null, and if null throw a UserStoreException (or handle per existing error flow)
instead of invoking removeDomainFromName; apply the identical null-guard and
exception handling to the duplicated occurrence referenced at the second
location so both spots use the safe local variable + null check before calling
UserCoreUtil.removeDomainFromName.
🪄 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: 7d74f544-6dde-4776-8657-169980454745
📒 Files selected for processing (1)
core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java
...arbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java
Outdated
Show resolved
Hide resolved
|
PR builder started |
|
PR builder completed |
jenkins-is-staging
left a comment
There was a problem hiding this comment.
Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/24228862055
Problem
Related to wso2/product-is#27494
Self registration of a user to a secondary userstore fails with:
This issue is caused by a flaw in the existing username claim validation logic in
AbstractUserStoreManager:Root Cause
The current logic removes the domain prefix from
userName(e.g.,PRIMARY/user1 → user1) before comparison, but does not normalize theUSERNAME_CLAIM_URIclaim value.This leads to incorrect mismatches in scenarios such as:
If the claim value has no domain (e.g.,
user1) and the username includes a domain (e.g.,PRIMARY/user1), the comparison may incorrectly fail.If both the username and claim value include a secondary user store domain (e.g.,
SECONDARY/John), removing the domain only from the username results in:causing a false mismatch.
Fix
Normalize both values by applying
UserCoreUtil.removeDomainFromName()to the claim value as well:This ensures the comparison is always performed between domain-free usernames.
Behavior Comparison
Scope of Fix
The fix is applied to both:
addUseraddUserWithIDmethods in
AbstractUserStoreManager.