-
Notifications
You must be signed in to change notification settings - Fork 21
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
401 unauthorized issue resolved #68
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe modifications focus on enhancing the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant V as VisitServiceImpl
participant R as RequestContextHolder
participant CU as CookieUtil
participant API as External API
C->>V: Call service method (e.g., getBeneficiaryListByIDs)
V->>R: Retrieve current HTTP request
R-->>V: Return HTTP request
V->>CU: Extract JWT token from cookie
CU-->>V: Return JWT token
V->>API: Call API with header "Cookie: Jwttoken={token}"
API-->>V: API response
V-->>C: Return response
Poem
β¨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
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: 0
π§Ή Nitpick comments (2)
src/main/java/com/iemr/inventory/service/visit/VisitServiceImpl.java (2)
32-35
: Unused imports detected.The imported classes
LinkedMultiValueMap
andMultiValueMap
(lines 32-33) aren't used in the code. Consider removing these unused imports to improve code cleanliness.-import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap;
107-111
: Consider adding null check for RequestContextHolder.The current implementation assumes that
RequestContextHolder.getRequestAttributes()
will never return null, which could potentially lead to a NullPointerException if called outside of a request context.-HttpServletRequest requestHeader = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) - .getRequest(); -String jwtTokenFromCookie = cookieUtil.getJwtTokenFromCookie(requestHeader); -header.put("Cookie", "Jwttoken=" + jwtTokenFromCookie); +if (RequestContextHolder.getRequestAttributes() != null) { + HttpServletRequest requestHeader = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) + .getRequest(); + String jwtTokenFromCookie = cookieUtil.getJwtTokenFromCookie(requestHeader); + if (jwtTokenFromCookie != null) { + header.put("Cookie", "Jwttoken=" + jwtTokenFromCookie); + } +}Also applies to: 143-147
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
src/main/java/com/iemr/inventory/service/visit/VisitServiceImpl.java
(4 hunks)
π Additional comments (4)
src/main/java/com/iemr/inventory/service/visit/VisitServiceImpl.java (4)
62-63
: Good addition of CookieUtil dependency.The CookieUtil autowiring adds the necessary functionality to retrieve JWT tokens from cookies, which is essential for resolving the 401 unauthorized issue.
107-111
: JWT token handling added correctly.The implementation correctly retrieves the JWT token from cookies and adds it to the request headers, which should resolve the 401 unauthorized issue. This approach ensures that authenticated requests are properly forwarded to downstream services.
143-147
: Consistent implementation of JWT token handling.The same JWT token retrieval logic is correctly applied here as in the
getBeneficiaryListByIDs
method, ensuring consistent authentication behavior across all beneficiary-related API calls.
62-63
: Consider adding unit tests for the JWT authentication flow.The newly added authentication flow should be properly tested to ensure it handles various scenarios correctly, including:
- When a valid JWT token is present in cookies
- When no JWT token is present
- When RequestContextHolder returns null
This will help ensure the robustness of the authentication mechanism.
Also applies to: 107-111, 143-147
π Description
JIRA ID:
Please provide a summary of the change and the motivation behind it. Include relevant context and details.
β Type of Change
βΉοΈ Additional Information
Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.
Summary by CodeRabbit