-
Notifications
You must be signed in to change notification settings - Fork 43
[OB4] Fixes username resolving issue for secondary user store #912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -145,35 +145,54 @@ public static String reduceStringLength(String input, int maxLength) { | |||||||||||||||||||||||||||||||||||
| @Generated(message = "Ignoring because OAuth2Util cannot be mocked with no constructors") | ||||||||||||||||||||||||||||||||||||
| public static String resolveUsernameFromUserId(String userID) { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!startsWithUUID(userID)) { | ||||||||||||||||||||||||||||||||||||
| // If the user ID is not starting with a UUID that means request has sent the username, | ||||||||||||||||||||||||||||||||||||
| if (!containsUUID(userID)) { | ||||||||||||||||||||||||||||||||||||
| // If the user ID doesn't have a UUID that means request has sent the username, | ||||||||||||||||||||||||||||||||||||
| // return the same user ID as the username. | ||||||||||||||||||||||||||||||||||||
| return userID; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| String username = null; | ||||||||||||||||||||||||||||||||||||
| String extractedUUID = extractUUID(userID); | ||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+154
to
155
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 2
Suggested change
|
||||||||||||||||||||||||||||||||||||
| if (userID.contains(FinancialServicesConstants.TENANT_DOMAIN)) { | ||||||||||||||||||||||||||||||||||||
| username = OAuth2Util.resolveUsernameFromUserId(FinancialServicesConstants.TENANT_DOMAIN, | ||||||||||||||||||||||||||||||||||||
| userID.split("@" + FinancialServicesConstants.TENANT_DOMAIN)[0]); | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| username = OAuth2Util.resolveUsernameFromUserId(FinancialServicesConstants.TENANT_DOMAIN, userID); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| return OAuth2Util.resolveUsernameFromUserId(FinancialServicesConstants.TENANT_DOMAIN, extractedUUID); | ||||||||||||||||||||||||||||||||||||
| } catch (UserStoreException e) { | ||||||||||||||||||||||||||||||||||||
| log.debug("Returning null since user ID is not found in the database", e); | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
155
to
159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't turn lookup failures into
Possible fix try {
return OAuth2Util.resolveUsernameFromUserId(FinancialServicesConstants.TENANT_DOMAIN, extractedUUID);
} catch (UserStoreException e) {
- log.debug("Returning null since user ID is not found in the database", e);
- return null;
+ log.debug("Unable to resolve username from user ID. Falling back to original identifier.", e);
+ return userID;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| return username; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||
| * Method to check whether the input string starts with a UUID. | ||||||||||||||||||||||||||||||||||||
| * Method to extract the UUID from the input string. | ||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||
| * @param input Input string | ||||||||||||||||||||||||||||||||||||
| * @return Extracted UUID if found, else null | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| public static String extractUUID(String input) { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (input == null) { | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Use your existing constant or regex string | ||||||||||||||||||||||||||||||||||||
| Pattern uuidPattern = Pattern.compile(FinancialServicesConstants.UUID_REGEX); | ||||||||||||||||||||||||||||||||||||
| Matcher matcher = uuidPattern.matcher(input); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // 1. Search for the pattern | ||||||||||||||||||||||||||||||||||||
| if (matcher.find()) { | ||||||||||||||||||||||||||||||||||||
| // 2. Return the specific substring that matched | ||||||||||||||||||||||||||||||||||||
| return matcher.group(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||
| * Method to check whether the input string has a UUID. | ||||||||||||||||||||||||||||||||||||
| * @param input Input string | ||||||||||||||||||||||||||||||||||||
| * @return true if the input string starts with a UUID | ||||||||||||||||||||||||||||||||||||
| * @return true if the input string has a UUID | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| public static boolean startsWithUUID(String input) { | ||||||||||||||||||||||||||||||||||||
| Pattern uuidPattern = Pattern.compile("^" + FinancialServicesConstants.UUID_REGEX + ".*$"); | ||||||||||||||||||||||||||||||||||||
| return uuidPattern.matcher(input).matches(); | ||||||||||||||||||||||||||||||||||||
| public static boolean containsUUID(String input) { | ||||||||||||||||||||||||||||||||||||
| Pattern uuidPattern = Pattern.compile(FinancialServicesConstants.UUID_REGEX); | ||||||||||||||||||||||||||||||||||||
| return uuidPattern.matcher(input).find(); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+193
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle
Possible fix public static boolean containsUUID(String input) {
+ if (input == null) {
+ return false;
+ }
Pattern uuidPattern = Pattern.compile(FinancialServicesConstants.UUID_REGEX);
return uuidPattern.matcher(input).find();
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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