-
Notifications
You must be signed in to change notification settings - Fork 49
AMM-1456 fix: cookie name #204
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
Conversation
WalkthroughThe change updates the logic in the Changes
Possibly related PRs
Suggested reviewers
Poem
Note β‘οΈ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. β¨ Finishing Touches
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. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
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.
Actionable comments posted: 1
π§Ή Nitpick comments (1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)
495-505: Consider extracting duplicated cookie lookup logic.This cookie lookup logic is duplicated in the
getJwtTokenFromCookiemethod (lines 1093-1101). Consider extracting this into a helper method to follow DRY principles.+private String extractJwtTokenFromCookies(Cookie[] cookies) { + if (cookies != null) { + for (Cookie cookie : cookies) { + if ("Jwttoken".equalsIgnoreCase(cookie.getName())) { + return cookie.getValue(); + } + } + } + return null; +}Then use it in both methods:
- if (jwtToken == null) { - Cookie[] cookies = request.getCookies(); - if (cookies != null) { - for (Cookie cookie : cookies) { - if ("Jwttoken".equalsIgnoreCase(cookie.getName())) { - jwtToken = cookie.getValue(); - break; - } - } - } - } + if (jwtToken == null) { + jwtToken = extractJwtTokenFromCookies(request.getCookies()); + }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java(1 hunks)
β° Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: style-check / checkstyle
- GitHub Check: Analyze (java)
- GitHub Check: Package-test
- GitHub Check: Build
| if (cookies != null) { | ||
| for (Cookie cookie : cookies) { | ||
| if ("jwtToken".equals(cookie.getName())) { | ||
| if ("Jwttoken".equalsIgnoreCase(cookie.getName())) { |
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.
π‘ Verification agent
π§© Analysis chain
Good fix for case-sensitivity, but verify cookie name consistency.
The change to use equalsIgnoreCase() is a good practice for robust cookie handling. However, please ensure that the cookie name "Jwttoken" exactly matches how the cookie is set elsewhere in the application.
Let me verify the cookie naming consistency across the codebase:
π Script executed:
#!/bin/bash
# Description: Check for JWT cookie naming patterns to ensure consistency
# Search for cookie setting operations
echo "=== Cookie Setting Operations ==="
rg -A 3 -B 3 "addJwtTokenToCookie|setCookie|addCookie" --type java
# Search for JWT token cookie references
echo "=== JWT Token Cookie References ==="
rg -A 2 -B 2 "jwtToken|Jwttoken|JWT.*[Cc]ookie" --type java
# Search in CookieUtil to see how the cookie is actually named
echo "=== CookieUtil Implementation ==="
fd "CookieUtil" --type f --extension java --exec cat {}Length of output: 17692
Approve caseβinsensitive cookie comparison; cookie name is consistent.
All JWT cookies are consistently named "Jwttoken" when set and read. To eliminate duplicated lookup logic, please refactor the manual loops to use the existing utility method:
β’ src/main/java/com/iemr/common/controller/users/IEMRAdminController.java
β Line 499 in getLoginResponse (manual cookie loop)
β getJwtTokenFromCookie endpoint (around line 1095)
β’ src/main/java/com/iemr/common/utils/JwtUserIdValidationFilter.java
β Cookie lookup block using equalsIgnoreCase("Jwttoken")
Replace each manual loop with a call to CookieUtil.getJwtTokenFromCookie(request) for better DRY and consistency.
π€ Prompt for AI Agents
In src/main/java/com/iemr/common/controller/users/IEMRAdminController.java at
line 499, the manual loop checking for the "Jwttoken" cookie using
equalsIgnoreCase should be refactored to use the existing utility method
CookieUtil.getJwtTokenFromCookie(request). This change will remove duplicated
cookie lookup logic, improve code consistency, and adhere to DRY principles.
Locate all manual cookie loops for JWT token retrieval in this file and in
JwtUserIdValidationFilter.java and replace them with calls to
CookieUtil.getJwtTokenFromCookie(request).




π Description
JIRA ID: AMM-1456
Ensure cookie is correctly checked in login response API
β Type of Change
Summary by CodeRabbit