Fix Bug in Agent Token obtain when email as username feature enabled#8118
Fix Bug in Agent Token obtain when email as username feature enabled#8118ranuka-laksika wants to merge 1 commit into
Conversation
| if (IdentityUtil.isEmailUsernameEnabled()) { | ||
| if (context != null && context.getProperties() != null | ||
| && context.getProperties().containsKey(AUTH_ENTITY) | ||
| && AUTH_ENTITY_AGENT.equals(context.getProperty(AUTH_ENTITY))) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Log Improvement Suggestion No: 1
| if (IdentityUtil.isEmailUsernameEnabled()) { | |
| if (context != null && context.getProperties() != null | |
| && context.getProperties().containsKey(AUTH_ENTITY) | |
| && AUTH_ENTITY_AGENT.equals(context.getProperty(AUTH_ENTITY))) { | |
| return; | |
| } | |
| if (IdentityUtil.isEmailUsernameEnabled()) { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Email username validation enabled. Checking username format."); | |
| } | |
| if (context != null && context.getProperties() != null | |
| && context.getProperties().containsKey(AUTH_ENTITY) | |
| && AUTH_ENTITY_AGENT.equals(context.getProperty(AUTH_ENTITY))) { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Skipping email username validation for agent authentication entity."); | |
| } | |
| return; | |
| } |
| if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) { | ||
| context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true); |
There was a problem hiding this comment.
Log Improvement Suggestion No: 2
| if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) { | |
| context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true); | |
| if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) { | |
| log.warn("Invalid email username format detected. Username does not contain '@' symbol."); | |
| context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true); |
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 |
|
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)
📝 WalkthroughWalkthroughThis PR adds a conditional bypass to username validation in FrameworkUtils. When authentication context properties indicate the request originates from an agent entity ( ChangesAgent-initiated authentication bypass
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
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 #8118 +/- ##
============================================
+ Coverage 53.02% 53.10% +0.07%
+ Complexity 21214 20728 -486
============================================
Files 2151 2151
Lines 130121 127313 -2808
Branches 18991 18753 -238
============================================
- Hits 69003 67604 -1399
+ Misses 52711 51442 -1269
+ Partials 8407 8267 -140
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:
|



When email as username feature enabled then when try to get agent token it get failed in authn endpoint because it failed at the validateUsername section. The reason is that Agent username is not a email but a randomly generated UUID hence it throws an error saying username is not a valid email.
As a fix for that inside the validateUsername function check where this context has the aget_identity param with the agent as the value if yes that means this is an agent. For agents we don't validate the username instead return from that function.
Related Issue:- wso2/product-is#27856