Skip to content
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

Global CORS Configuration for AMRIT API Services #182

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

kevalkanp1011
Copy link
Contributor

@kevalkanp1011 kevalkanp1011 commented Apr 10, 2025

πŸ“‹ Description

JIRA ID:

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ 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

  • Bug Fixes
    • Removed CORS support from multiple endpoints, which may affect cross-origin requests.
  • New Features
    • Introduced a new configuration for managing allowed origins for cross-origin requests.
  • Chores
    • Added a new configuration property to define allowed origins for cross-origin requests.

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

The changes introduce a new global CORS configuration by adding the CorsConfig class that implements WebMvcConfigurer to set allowed origins, HTTP methods, headers, and credentials, with settings injected from the application properties. The per-method @CrossOrigin() annotations have been removed from multiple controllers to centralize CORS management. Additionally, a new cors.allowed-origins property has been added in the common_ci.properties file.

Changes

File(s) Change Summary
src/main/java/com/iemr/common/config/CorsConfig.java Added new CorsConfig class that implements WebMvcConfigurer; injects cors.allowed-origins property; configures CORS mappings for GET, POST, PUT, DELETE, and OPTIONS with credentials and max age settings.
src/main/resources/application.properties Added new property cors.allowed-origins with an empty value to support global CORS configuration.
src/main/environment/common_ci.properties Added new property cors.allowed-origins with an empty value, indicating no allowed origins for CORS requests.
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java Removed @CrossOrigin() annotations from multiple methods, centralizing CORS handling away from individual endpoint definitions.
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java Removed @CrossOrigin annotation from class, affecting CORS support for its endpoints.
src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support for these endpoints.
src/main/java/com/iemr/common/controller/brd/BRDIntegrationController.java Removed @CrossOrigin() annotation from class and method, affecting CORS support.
src/main/java/com/iemr/common/controller/callhandling/CallController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/covid/CovidVaccinationController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/cti/ComputerTelephonyIntegrationController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/customization/CustomizationController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/directory/DirectoryController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/door_to_door_app/DoorToDoorAppController.java Removed @CrossOrigin annotations from class and methods, affecting CORS support.
src/main/java/com/iemr/common/controller/eausadha/EAusadhaController.java Removed @CrossOrigin annotation from class, affecting CORS support.
src/main/java/com/iemr/common/controller/email/EmailController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/esanjeevani/ESanjeevaniController.java Removed @CrossOrigin annotations from class and method, affecting CORS support.
src/main/java/com/iemr/common/controller/everwell/callhandle/EverwellCallController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/everwellTest/EverwellController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/feedback/FeedbackController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/helpline104history/Helpline104BeneficiaryHistoryController.java Removed @CrossOrigin annotation from class, affecting CORS support.
src/main/java/com/iemr/common/controller/honeywell/HoneywellController.java Removed @CrossOrigin annotations from class and methods, affecting CORS support.
src/main/java/com/iemr/common/controller/institute/InstituteController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/kmfilemanager/KMFileManagerController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/location/LocationController.java Removed @CrossOrigin annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/lonic/LonicController.java Removed @CrossOrigin annotation from method, affecting CORS support.
src/main/java/com/iemr/common/controller/lungassessment/LungAssessmentController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/mctshistory/OutboundHistoryController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/nhmdashboard/NationalHealthMissionDashboardController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/notification/NotificationController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/otp/OTPGateway.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/questionconfig/QuestionnaireController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/report/CustomerRelationshipReports.java Removed @CrossOrigin annotation from method, affecting CORS support.
src/main/java/com/iemr/common/controller/scheme/SchemeController.java Removed @CrossOrigin annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/secondaryReport/CustomerRelationshipSecondaryReports.java Removed @CrossOrigin annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/services/CategoryController.java Removed @CrossOrigin() annotation from class, affecting CORS support.
src/main/java/com/iemr/common/controller/sms/SMSController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/snomedct/SnomedController.java Removed @CrossOrigin annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/uptsu/UPTechnicalSupportController.java Removed @CrossOrigin annotations from multiple methods, affecting CORS support.
src/main/java/com/iemr/common/controller/users/EmployeeSignatureController.java Removed @CrossOrigin() annotations from multiple methods, affecting CORS support.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant CorsConfig
    participant Controller

    Client->>Server: Sends HTTP Request (Preflight OPTIONS)
    Server->>CorsConfig: Apply CORS settings (allowed origins, headers, methods)
    CorsConfig-->>Server: CORS headers applied
    alt Non-preflight Request
        Server->>Controller: Forward request
        Controller-->>Server: Processed response
    end
    Server->>Client: Return HTTP Response with CORS headers
Loading

Possibly related issues

Possibly related PRs

  • Abdm facilityΒ #145: The changes in the main PR, which involve the introduction of a new CORS configuration class, are related to the retrieved PR, as both involve modifications to CORS handling in the application, specifically affecting the @CrossOrigin annotations in controllers.
  • adding fixes related to Grievance APIsΒ #169: The changes in the main PR, which involve the introduction of a new CORS configuration class, are related to the retrieved PR as both involve modifications to CORS handling in the GrievanceController class, specifically affecting how cross-origin requests are managed.

Suggested reviewers

  • helenKaryamsetty

Tip

βš‘πŸ’¬ Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b7c718e and 078876c.

πŸ“’ Files selected for processing (35)
  • src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/brd/BRDIntegrationController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/callhandling/CallController.java (29 hunks)
  • src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/everwell/callhandle/EverwellCallController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/everwellTest/EverwellController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/feedback/FeedbackController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/grievance/GrievanceController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/helpline104history/Helpline104BeneficiaryHistoryController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/honeywell/HoneywellController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/institute/InstituteController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/kmfilemanager/KMFileManagerController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/language/LanguageController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/location/LocationController.java (7 hunks)
  • src/main/java/com/iemr/common/controller/lonic/LonicController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/lungassessment/LungAssessmentController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/mctshistory/OutboundHistoryController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java (0 hunks)
  • src/main/java/com/iemr/common/controller/nhmdashboard/NationalHealthMissionDashboardController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/notification/NotificationController.java (11 hunks)
  • src/main/java/com/iemr/common/controller/otp/OTPGateway.java (3 hunks)
  • src/main/java/com/iemr/common/controller/questionconfig/QuestionTypeController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/questionconfig/QuestionnaireController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/report/CustomerRelationshipReports.java (1 hunks)
  • src/main/java/com/iemr/common/controller/scheme/SchemeController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/secondaryReport/CustomerRelationshipSecondaryReports.java (11 hunks)
  • src/main/java/com/iemr/common/controller/services/CategoryController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/services/CommonController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/sms/SMSController.java (7 hunks)
  • src/main/java/com/iemr/common/controller/snomedct/SnomedController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/uptsu/UPTechnicalSupportController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/users/EmployeeSignatureController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (22 hunks)
  • src/main/java/com/iemr/common/controller/version/VersionController.java (0 hunks)
πŸ’€ Files with no reviewable changes (9)
  • src/main/java/com/iemr/common/controller/version/VersionController.java
  • src/main/java/com/iemr/common/controller/questionconfig/QuestionTypeController.java
  • src/main/java/com/iemr/common/controller/nhmdashboard/NHMDetailCallReportScheduler.java
  • src/main/java/com/iemr/common/controller/services/CommonController.java
  • src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java
  • src/main/java/com/iemr/common/controller/everwellTest/EverwellController.java
  • src/main/java/com/iemr/common/controller/language/LanguageController.java
  • src/main/java/com/iemr/common/controller/brd/BRDIntegrationController.java
  • src/main/java/com/iemr/common/controller/everwell/callhandle/EverwellCallController.java
βœ… Files skipped from review due to trivial changes (1)
  • src/main/java/com/iemr/common/controller/grievance/GrievanceController.java
🚧 Files skipped from review as they are similar to previous changes (23)
  • src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java
  • src/main/java/com/iemr/common/controller/helpline104history/Helpline104BeneficiaryHistoryController.java
  • src/main/java/com/iemr/common/controller/snomedct/SnomedController.java
  • src/main/java/com/iemr/common/controller/sms/SMSController.java
  • src/main/java/com/iemr/common/controller/otp/OTPGateway.java
  • src/main/java/com/iemr/common/controller/services/CategoryController.java
  • src/main/java/com/iemr/common/controller/lonic/LonicController.java
  • src/main/java/com/iemr/common/controller/questionconfig/QuestionnaireController.java
  • src/main/java/com/iemr/common/controller/lungassessment/LungAssessmentController.java
  • src/main/java/com/iemr/common/controller/report/CustomerRelationshipReports.java
  • src/main/java/com/iemr/common/controller/users/EmployeeSignatureController.java
  • src/main/java/com/iemr/common/controller/uptsu/UPTechnicalSupportController.java
  • src/main/java/com/iemr/common/controller/scheme/SchemeController.java
  • src/main/java/com/iemr/common/controller/mctshistory/OutboundHistoryController.java
  • src/main/java/com/iemr/common/controller/kmfilemanager/KMFileManagerController.java
  • src/main/java/com/iemr/common/controller/feedback/FeedbackController.java
  • src/main/java/com/iemr/common/controller/nhmdashboard/NationalHealthMissionDashboardController.java
  • src/main/java/com/iemr/common/controller/honeywell/HoneywellController.java
  • src/main/java/com/iemr/common/controller/institute/InstituteController.java
  • src/main/java/com/iemr/common/controller/location/LocationController.java
  • src/main/java/com/iemr/common/controller/secondaryReport/CustomerRelationshipSecondaryReports.java
  • src/main/java/com/iemr/common/controller/notification/NotificationController.java
  • src/main/java/com/iemr/common/controller/callhandling/CallController.java
πŸ”‡ Additional comments (2)
src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java (1)

77-578:

βœ… Verification successful

Approve removal of @crossorigin() annotations for global CORS configuration

The removal of @crossorigin() annotations from all controller methods aligns with the PR objective of implementing a global CORS configuration. This change improves maintainability by centralizing CORS policy management rather than defining it at the individual endpoint level.

This is a good architectural improvement as it:

  1. Ensures consistent CORS policy application across all endpoints
  2. Simplifies future CORS policy changes (only one place to update)
  3. Reduces code duplication

🏁 Script executed:

#!/bin/bash
# Verify a CorsConfig class was added to implement the global CORS configuration
# This is necessary to confirm the annotations weren't simply removed without an alternative

echo "Searching for CorsConfig class..."
fd -e java --exec grep -l "CorsConfig" {} \;

echo "Checking for CORS configuration in application properties..."
fd -e properties --exec grep -l "cors.allowed-origins" {} \;

Length of output: 418


Global CORS Configuration Verified – @crossorigin() Annotations Removal Approved

The global CORS configuration is now implemented via the CorsConfig.java class (located in src/main/java/com/iemr/common/config/CorsConfig.java) and the presence of cors.allowed-origins in application properties confirms that the CORS policy is centralized. This architectural change ensures:

  • Consistent CORS policy application across all endpoints.
  • Simplified updates to CORS policies in one place.
  • Reduced code duplication by eliminating method-level annotations.

The removal of all @CrossOrigin() annotations is approved as it aligns with the PR objective.

src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)

105-105:

❓ Verification inconclusive

Approve removal of @crossorigin() annotations for centralized CORS configuration

The removal of @crossorigin() annotations from all controller methods in IEMRAdminController is consistent with the global CORS configuration approach being implemented. This change improves maintainability by centralizing CORS policy management rather than configuring it individually for each endpoint.

This architectural change:

  1. Provides a single source of truth for CORS configuration
  2. Makes security policy enforcement more consistent across the application
  3. Simplifies future modifications to CORS settings

Let's confirm that the commented-out method at lines 445-471 was already commented out and not part of this PR's changes:

Also applies to: 120-120, 445-471, 473-473, 486-486, 526-526, 565-565, 612-612, 635-635, 668-668, 710-710, 731-731, 752-752, 770-770, 818-818, 833-833, 848-848, 865-865, 910-910, 932-932, 958-958


🏁 Script executed:

#!/bin/bash
# Check if the userAuthenticateV1 method was already commented out in the previous version
# to confirm this wasn't changed as part of the current PR

git show HEAD^ -- src/main/java/com/iemr/common/controller/users/IEMRAdminController.java | grep -A 30 "userAuthenticateV1"

Length of output: 125


Removal of @crossorigin Annotations Approved – Pending Manual Verification of userAuthenticateV1 Block

The removal of theβ€―@CrossOriginβ€―annotations from all controller methods inβ€―IEMRAdminController aligns with our shift to a centralized CORS configuration, improving maintainability, consistency in security policy enforcement, and easing future updates.

Action Required:

  • Please manually verify that the block for the userAuthenticateV1 method (lines 445–471) was already commented out in the previous commit (using HEAD^) and has not been modified as part of the current PR. The initial script did not return any output, so a manual check is necessary.
✨ Finishing Touches
  • πŸ“ Generate Docstrings

πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

πŸ”­ Outside diff range comments (1)
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)

936-936: πŸ› οΈ Refactor suggestion

Remove remaining @crossorigin annotation for consistency.

All other @crossorigin annotations have been removed in favor of the global CORS configuration, but this one remains. It should be removed to maintain consistency and centralized CORS management.

-	@CrossOrigin
 	@Operation(summary = "Validating security question and answers for password change")
 	@RequestMapping(value = { "/validateSecurityQuestionAndAnswer" }, method = { RequestMethod.POST })
🧹 Nitpick comments (1)
src/main/java/com/iemr/common/config/CorsConfig.java (1)

14-22: Consider using "/" pattern instead of "/" for comprehensive path mapping.**

The current mapping uses "/" which may not cover all API paths. Using "/**" would ensure all endpoints in the application have CORS properly applied.

-    public void addCorsMappings(CorsRegistry registry) {
-        registry.addMapping("/")
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/**")
             .allowedOrigins(allowedOrigins.split(","))
             .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
             .allowedHeaders("*")
             .allowCredentials(true)
             .maxAge(3600);
     }
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 3f5a727 and 62aa438.

πŸ“’ Files selected for processing (3)
  • src/main/java/com/iemr/common/config/CorsConfig.java (1 hunks)
  • src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (21 hunks)
  • src/main/resources/application.properties (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: style-check / checkstyle
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (4)
src/main/resources/application.properties (1)

187-187: CORS configuration added correctly.

The new property cors.allowed-origins is properly configured to allow requests from frontend development servers running on standard ports (3000 for React, 4200 for Angular). This configuration will be used by the new global CORS configuration class.

src/main/java/com/iemr/common/config/CorsConfig.java (2)

1-7: LGTM! Appropriate imports for CORS configuration.

All necessary imports for implementing the CORS configuration are present.


8-13: LGTM! Configuration class properly set up with property injection.

The class is correctly annotated with @Configuration and properly injects the CORS allowed origins from application properties.

src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (1)

109-110: LGTM! Successfully centralized CORS configuration.

The removal of method-level @crossorigin annotations is appropriate now that CORS is managed globally through the CorsConfig class. This change improves maintainability by centralizing CORS configuration and ensuring consistent behavior across endpoints.

Also applies to: 124-125, 284-285, 477-478, 490-491, 530-531, 569-570, 616-617, 639-640, 672-673, 714-715, 735-736, 756-757, 774-775, 822-823, 837-838, 852-853, 869-870, 914-915, 962-963

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

πŸ”­ Outside diff range comments (2)
src/main/java/com/iemr/common/controller/mctshistory/OutboundHistoryController.java (1)

1-83: πŸ’‘ Verification agent

🧩 Analysis chain

Verify the impact of CORS changes on API consumers.

Make sure that all legitimate API consumers (frontend applications, third-party integrations) are included in the cors.allowed-origins property. This change from per-method CORS annotations to a global configuration might potentially impact existing integrations if the allowed origins aren't properly configured.


🏁 Script executed:

#!/bin/bash
# Check the configured allowed origins in the properties file

echo "Checking for cors.allowed-origins property in properties files..."
find . -name "*.properties" -exec grep -l "cors.allowed-origins" {} \;

# Display the content of any files that contain the CORS configuration
echo -e "\nContent of the CORS configuration:"
find . -name "*.properties" -exec grep -A2 -B2 "cors.allowed-origins" {} \;

Length of output: 494


Action Required: Update Global CORS Configuration

The global CORS configuration is in use, but the cors.allowed-origins property in ./src/main/environment/common_ci.properties is currently empty. Please ensure that this property is updated with a comprehensive list of all legitimate API consumer origins (frontend applications, third-party integrations) to avoid unexpected API access issues.

  • File to review: src/main/environment/common_ci.properties
  • Property: cors.allowed-origins
src/main/java/com/iemr/common/controller/honeywell/HoneywellController.java (1)

1-96: πŸ’‘ Verification agent

🧩 Analysis chain

Verify existence and configuration of the global CORS config class

This file and the other controllers have had their @crossorigin annotations removed, suggesting a move to a global CORS configuration. However, I don't see the implementation of this global configuration in the provided files.

Please ensure that the CorsConfig class mentioned in the AI summary has been created and properly configured to allow the necessary origins, HTTP methods, headers, and credentials. This is critical to maintain functionality after removing the @crossorigin annotations.


🏁 Script executed:

#!/bin/bash
# Check for the existence of the CorsConfig class
echo "Checking for CorsConfig class..."
find src/main -name "CorsConfig.java" | grep .

# If found, display its content
if [ $? -eq 0 ]; then
  echo -e "\nFound CorsConfig.java. Displaying content:"
  find src/main -name "CorsConfig.java" -exec cat {} \;
else
  echo "CorsConfig.java not found!"
fi

# Check for CORS properties in configuration files
echo -e "\nChecking for CORS configuration in properties files..."
grep -r "cors.allowed-origins" src/

Length of output: 1589


Global CORS configuration verified – ensure valid allowed origins are provided

  • Confirmed that the CorsConfig class exists at src/main/java/com/iemr/common/config/CorsConfig.java and implements a global CORS configuration.
  • The configuration properly sets the allowed HTTP methods (GET, POST, PUT, DELETE, OPTIONS), allows all headers, explicitly exposes headers (Authorization, Jwttoken), and permits credentials.
  • Action Required: The CORS allowed origins are loaded from the property cors.allowed-origins, which in src/main/environment/common_ci.properties appears empty. Please verify that this property is correctly set in all relevant environment configurations to avoid inadvertently blocking expected origins.
🧹 Nitpick comments (17)
src/main/java/com/iemr/common/controller/services/CategoryController.java (1)

57-57: @crossorigin annotation removed as part of global CORS configuration

The removal of the @CrossOrigin annotation is consistent with implementing a centralized CORS configuration. This is a good practice as it centralizes CORS policy management.

As the CrossOrigin annotation is no longer used, consider removing the unused import at line 33:

-import org.springframework.web.bind.annotation.CrossOrigin;
src/main/java/com/iemr/common/controller/eausadha/EAusadhaController.java (1)

27-27: @crossorigin annotation removed as part of global CORS configuration

The removal of the @CrossOrigin annotation is consistent with implementing a centralized CORS configuration. This is a good practice as it centralizes CORS policy management.

As the CrossOrigin annotation is no longer used, consider removing the unused import at line 6:

-import org.springframework.web.bind.annotation.CrossOrigin;
src/main/java/com/iemr/common/controller/lonic/LonicController.java (1)

56-56: @crossorigin annotation removed as part of global CORS configuration

The removal of the @CrossOrigin annotation is consistent with implementing a centralized CORS configuration. This is a good practice as it centralizes CORS policy management.

As the CrossOrigin annotation is no longer used, consider removing the unused import at line 27:

-import org.springframework.web.bind.annotation.CrossOrigin;
src/main/java/com/iemr/common/controller/kmfilemanager/KMFileManagerController.java (1)

81-81:

❓ Verification inconclusive

Removal of @crossorigin annotations - centralized CORS configuration

The @crossorigin annotations have been removed from all methods in this controller as part of implementing a global CORS configuration. This change promotes consistency in how CORS is handled across the application.

Consider removing the CrossOrigin import at line 32 if it's no longer used elsewhere in this file.

Also applies to: 104-104, 130-130


🏁 Script executed:

#!/bin/bash
# Check if CrossOrigin is still used in this file
rg -c "@CrossOrigin" "src/main/java/com/iemr/common/controller/kmfilemanager/KMFileManagerController.java"

Length of output: 104


Action Required: Verify and Remove Unused @crossorigin Import

  • The controller no longer uses any @CrossOrigin annotations, supporting our shift to a centralized CORS configuration.
  • Please manually verify that the import statement (typically at lineβ€―32:
    import org.springframework.web.bind.annotation.CrossOrigin;) is not required elsewhere in the file before removing it.
  • This check also applies to the noted method areas (lines 81, 104, and 130).
src/main/java/com/iemr/common/controller/cti/ComputerTelephonyIntegrationController.java (1)

59-59:

❓ Verification inconclusive

Removal of @crossorigin annotations - centralized CORS configuration

All @crossorigin annotations have been removed from this controller's methods (22 methods in total) as part of implementing a global CORS configuration. This is a significant improvement as it:

  1. Centralizes CORS management
  2. Ensures consistent CORS policies across endpoints
  3. Makes future CORS policy changes easier to implement

Consider removing the CrossOrigin import at line 30 if it's no longer used elsewhere in this file.

Also applies to: 81-81, 102-102, 123-123, 146-146, 168-168, 189-189, 210-210, 232-232, 257-257, 278-278, 299-299, 322-322, 345-345, 368-368, 389-389, 410-410, 431-431, 452-452, 475-475, 501-501, 527-527


🏁 Script executed:

#!/bin/bash
# Check if CrossOrigin is still used in this file
rg -c "@CrossOrigin" "src/main/java/com/iemr/common/controller/cti/ComputerTelephonyIntegrationController.java"

Length of output: 109


Action Required: Verify Removal of @crossorigin and Clean Up Imports

The @crossorigin annotations appear to be removed in line with the centralized CORS configuration, which is a solid improvement for consistent endpoint management. However, the initial verification script did not return clear results regarding any remaining @crossorigin occurrences. Please manually verify the following:

  • Ensure that no stray @crossorigin annotations remain in the file.
  • Confirm if the unused CrossOrigin import at line 30 is indeed redundant and can be safely removed.

Once these points have been manually verified, the cleanup can be finalized.

src/main/java/com/iemr/common/controller/nhmdashboard/NationalHealthMissionDashboardController.java (3)

29-29: Remove unused import.

The CrossOrigin import is no longer used since all @CrossOrigin annotations have been removed from the controller methods. This is part of the centralization of CORS configuration.

- import org.springframework.web.bind.annotation.CrossOrigin;

53-53: Clean up unnecessary whitespace.

This empty line was likely left after removing the @CrossOrigin annotation. Remove it to maintain clean code.


22-112: Verify global CORS configuration for these endpoints.

The @CrossOrigin annotations have been removed from all controller methods, which means these endpoints now rely on the global CORS configuration in the CorsConfig class. Ensure that the global configuration properly handles cross-origin requests for these specific endpoints.

This change centralizes CORS management, which is good for maintainability but could cause issues if specific endpoints need different CORS settings.

src/main/java/com/iemr/common/controller/institute/InstituteController.java (3)

30-30: Remove unused import.

The CrossOrigin import is no longer used since all @CrossOrigin annotations have been removed from the controller methods. This is part of the centralization of CORS configuration.

- import org.springframework.web.bind.annotation.CrossOrigin;

78-78: Clean up unnecessary whitespace.

These empty lines were likely left after removing the @CrossOrigin annotations. Remove them to maintain clean code.

Also applies to: 99-99, 120-120, 137-137, 153-153, 170-170


47-186: Verify global CORS configuration for institute endpoints.

The @CrossOrigin annotations have been removed from all controller methods, which means these endpoints now rely on the global CORS configuration in the CorsConfig class. Ensure that the global configuration properly handles cross-origin requests for these specific endpoints, particularly those that client applications may be directly calling.

This change centralizes CORS management, which is good for maintainability but could cause issues if specific endpoints need different CORS settings.

src/main/java/com/iemr/common/controller/notification/NotificationController.java (3)

29-29: Remove unused import.

The CrossOrigin import is no longer used since all @CrossOrigin annotations have been removed from the controller methods. This is part of the centralization of CORS configuration.

- import org.springframework.web.bind.annotation.CrossOrigin;

55-55: Clean up unnecessary whitespace.

These empty lines were likely left after removing the @CrossOrigin annotations. Remove them to maintain clean code.

Also applies to: 75-75, 95-95, 123-123, 149-149, 166-166, 185-185, 204-204, 222-222, 239-239, 261-261


42-281: Verify global CORS configuration for notification endpoints.

The @CrossOrigin annotations have been removed from all controller methods, which means these endpoints now rely on the global CORS configuration in the CorsConfig class. Ensure that the global configuration properly handles cross-origin requests for notification endpoints.

Since notification endpoints might be called from various clients, including external systems, verify that the global CORS policy adequately addresses their specific access requirements.

src/main/java/com/iemr/common/controller/customization/CustomizationController.java (3)

9-9: Remove unused import.

The CrossOrigin import is no longer used since all @CrossOrigin annotations have been removed from the controller methods. This is part of the centralization of CORS configuration.

- import org.springframework.web.bind.annotation.CrossOrigin;

33-33: Clean up unnecessary whitespace.

These empty lines were likely left after removing the @CrossOrigin annotations. Remove them to maintain clean code.

Also applies to: 50-50, 66-66, 83-83, 100-100, 117-117, 134-134, 150-150, 166-166, 182-182, 199-199, 216-216, 233-233, 250-250


23-264:

❓ Verification inconclusive

Verify global CORS configuration for customization endpoints.

The @CrossOrigin annotations have been removed from all controller methods, which means these endpoints now rely on the global CORS configuration in the CorsConfig class. Ensure that the global configuration properly handles cross-origin requests for customization endpoints.

For UI-focused endpoints like customization, it's particularly important to verify that the CORS configuration allows the appropriate origins where your web applications are hosted.


🏁 Script executed:

#!/bin/bash
# Find the CorsConfig class to understand the global configuration
fd CorsConfig.java

# Check what origins are allowed in the properties
fd -t f -e properties | xargs grep "cors.allowed-origins" || echo "No cors.allowed-origins found in properties files"

Length of output: 195


Action: Verify Global CORS Settings for Customization Endpoints

The global CORS configuration is correctly centralized in CorsConfig.java, and the controller endpoints now rely on this configuration rather than using method-level @CrossOrigin annotations. Note that in the CI properties file (src/main/environment/common_ci.properties), the cors.allowed-origins property is currently empty. Please verify that the desired origins are set in the appropriate environment properties so that UI applications can successfully access these endpoints in production.

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 62aa438 and b7c718e.

πŸ“’ Files selected for processing (40)
  • src/main/environment/common_ci.properties (1 hunks)
  • src/main/java/com/iemr/common/config/CorsConfig.java (1 hunks)
  • src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java (9 hunks)
  • src/main/java/com/iemr/common/controller/brd/BRDIntegrationController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/callhandling/CallController.java (29 hunks)
  • src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/covid/CovidVaccinationController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/cti/ComputerTelephonyIntegrationController.java (22 hunks)
  • src/main/java/com/iemr/common/controller/customization/CustomizationController.java (14 hunks)
  • src/main/java/com/iemr/common/controller/directory/DirectoryController.java (4 hunks)
  • src/main/java/com/iemr/common/controller/door_to_door_app/DoorToDoorAppController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/eausadha/EAusadhaController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/email/EmailController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/esanjeevani/ESanjeevaniController.java (0 hunks)
  • src/main/java/com/iemr/common/controller/everwell/callhandle/EverwellCallController.java (9 hunks)
  • src/main/java/com/iemr/common/controller/everwellTest/EverwellController.java (4 hunks)
  • src/main/java/com/iemr/common/controller/feedback/FeedbackController.java (24 hunks)
  • src/main/java/com/iemr/common/controller/helpline104history/Helpline104BeneficiaryHistoryController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/honeywell/HoneywellController.java (4 hunks)
  • src/main/java/com/iemr/common/controller/institute/InstituteController.java (6 hunks)
  • src/main/java/com/iemr/common/controller/kmfilemanager/KMFileManagerController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/location/LocationController.java (7 hunks)
  • src/main/java/com/iemr/common/controller/lonic/LonicController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/lungassessment/LungAssessmentController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/mctshistory/OutboundHistoryController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/nhmdashboard/NationalHealthMissionDashboardController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/notification/NotificationController.java (11 hunks)
  • src/main/java/com/iemr/common/controller/otp/OTPGateway.java (3 hunks)
  • src/main/java/com/iemr/common/controller/questionconfig/QuestionnaireController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/report/CustomerRelationshipReports.java (1 hunks)
  • src/main/java/com/iemr/common/controller/scheme/SchemeController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/secondaryReport/CustomerRelationshipSecondaryReports.java (11 hunks)
  • src/main/java/com/iemr/common/controller/services/CategoryController.java (1 hunks)
  • src/main/java/com/iemr/common/controller/sms/SMSController.java (7 hunks)
  • src/main/java/com/iemr/common/controller/snomedct/SnomedController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/uptsu/UPTechnicalSupportController.java (2 hunks)
  • src/main/java/com/iemr/common/controller/users/EmployeeSignatureController.java (3 hunks)
  • src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (22 hunks)
  • src/main/resources/application.properties (1 hunks)
πŸ’€ Files with no reviewable changes (2)
  • src/main/java/com/iemr/common/controller/brd/BRDIntegrationController.java
  • src/main/java/com/iemr/common/controller/esanjeevani/ESanjeevaniController.java
βœ… Files skipped from review due to trivial changes (9)
  • src/main/resources/application.properties
  • src/main/java/com/iemr/common/controller/helpline104history/Helpline104BeneficiaryHistoryController.java
  • src/main/java/com/iemr/common/controller/uptsu/UPTechnicalSupportController.java
  • src/main/java/com/iemr/common/controller/sms/SMSController.java
  • src/main/java/com/iemr/common/controller/carestream/CareStreamCreateOrderController.java
  • src/main/java/com/iemr/common/controller/everwell/callhandle/EverwellCallController.java
  • src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java
  • src/main/java/com/iemr/common/controller/secondaryReport/CustomerRelationshipSecondaryReports.java
  • src/main/java/com/iemr/common/controller/callhandling/CallController.java
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test
πŸ”‡ Additional comments (50)
src/main/java/com/iemr/common/controller/abdmfacility/AbdmFacilityController.java (1)

27-27: Removed @crossorigin annotation for centralized CORS management

The removal of the method-level @CrossOrigin annotation aligns with the PR objective of implementing a global CORS configuration. This change means that the endpoint will now use the centralized CORS configuration instead of having its own settings.

src/main/java/com/iemr/common/controller/otp/OTPGateway.java (3)

54-54: Removed @crossorigin annotation from sendOTP method

The removal of the method-level @CrossOrigin() annotation for the sendOTP method is part of the global CORS configuration implementation. This endpoint will now use the centralized CORS settings.


77-77: Removed @crossorigin annotation from validateOTP method

The removal of the method-level @CrossOrigin() annotation for the validateOTP method is part of the global CORS configuration implementation. This endpoint will now use the centralized CORS settings.


101-101: Removed @crossorigin annotation from resendOTP method

The removal of the method-level @CrossOrigin() annotation for the resendOTP method is part of the global CORS configuration implementation. This endpoint will now use the centralized CORS settings.

src/main/java/com/iemr/common/controller/snomedct/SnomedController.java (3)

56-56: Removed @crossorigin annotation from getSnomedCTRecord method

The removal of the method-level @CrossOrigin() annotation for the getSnomedCTRecord method is consistent with the global CORS configuration implementation. This endpoint will now use the centralized CORS settings.


82-82: Removed @crossorigin annotation from getSnomedCTRecordList method

The removal of the method-level @CrossOrigin() annotation for the getSnomedCTRecordList method is consistent with the global CORS configuration implementation. This endpoint will now use the centralized CORS settings.


1-109:

βœ… Verification successful

Verify CorsConfig implementation for global configuration

While removing the individual @crossorigin annotations is a good step toward centralized CORS configuration, it's important to verify that the new CorsConfig class is properly implemented to support all needed CORS functionality.


🏁 Script executed:

#!/bin/bash
# Check for the new CorsConfig class implementation
echo "Looking for CorsConfig implementation:"
cat src/main/java/com/iemr/common/config/CorsConfig.java

echo -e "\nChecking CORS properties configuration:"
grep -r "cors.allowed-origins" --include="*.properties" .

Length of output: 1287


Global CORS Setup Verified
The new CorsConfig class in src/main/java/com/iemr/common/config/CorsConfig.java is implemented correctlyβ€”it centralizes CORS configuration by reading the allowed origins (splitting a comma‐delimited string from the cors.allowed-origins property) and properly configuring allowed methods, headers, exposed headers, credentials, and max age. One point to note is that the cors.allowed-origins property in src/main/environment/common_ci.properties is currently empty. Please verify that this property is set appropriately for each deployment environment to ensure the expected CORS behavior.

src/main/java/com/iemr/common/config/CorsConfig.java (1)

1-25: Centralized CORS configuration looks good.

This class implements a global CORS configuration for the application, which is a more maintainable approach than having individual @CrossOrigin() annotations scattered across controller methods. The implementation correctly:

  • Uses a property injection for allowed origins
  • Configures standard HTTP methods
  • Exposes necessary headers for authentication
  • Properly sets allowCredentials and maxAge
src/main/java/com/iemr/common/controller/feedback/FeedbackController.java (1)

99-99: CORS configuration cleanup looks good.

The removal of individual @CrossOrigin() annotations from all these methods is consistent with the new approach of using a centralized CORS configuration through the CorsConfig class.

Also applies to: 116-116, 132-132, 148-148, 166-166, 181-181, 195-195, 211-211, 227-227, 243-243, 259-259, 286-286, 299-299, 312-312, 328-328, 344-344, 364-364, 381-381, 405-405, 424-424, 443-443, 460-460, 477-477, 492-492

src/main/java/com/iemr/common/controller/questionconfig/QuestionnaireController.java (1)

59-59: CORS configuration cleanup is consistent.

The removal of @CrossOrigin() annotations from these methods aligns with the global CORS configuration approach implemented in this PR.

Also applies to: 74-74

src/main/java/com/iemr/common/controller/mctshistory/OutboundHistoryController.java (1)

50-50: CORS configuration cleanup is consistent.

The removal of @CrossOrigin() annotations from these methods follows the same pattern as in other controllers, moving to the centralized CORS configuration approach.

Also applies to: 66-66

src/main/java/com/iemr/common/controller/email/EmailController.java (1)

58-58:

βœ… Verification successful

CORS annotations removed in favor of global configuration

The @crossorigin annotations have been removed from the SendEmail, getAuthorityEmailID, and sendEmailGeneral methods. This change aligns with the PR's objective to implement a global CORS configuration.

Also applies to: 77-77, 92-92


🏁 Script executed:

#!/bin/bash
# Check if a global CORS configuration exists in the codebase
echo "Searching for CorsConfig class..."
rg -p "class.*CorsConfig.*implements.*WebMvcConfigurer" --type java

Length of output: 255


Global CORS Configuration Verified and Approved

  • Confirmed that the global CORS setup is active via the presence of src/main/java/com/iemr/common/config/CorsConfig.java (e.g., line 9 verifying it implements WebMvcConfigurer).
  • Removal of @CrossOrigin annotations from the SendEmail, getAuthorityEmailID, and sendEmailGeneral methods in EmailController.java (lines 58, 77, and 92) is consistent with this centralized configuration.

No further changes are required.

src/main/java/com/iemr/common/controller/scheme/SchemeController.java (1)

59-59: CORS annotations removed in favor of global configuration

The @crossorigin annotations have been removed from the saveSchemeDetails, getSchemeList, and deleteScheme methods. This change is consistent with the overall approach of centralizing CORS configuration.

Also applies to: 86-86, 112-112

src/main/java/com/iemr/common/controller/location/LocationController.java (1)

54-54:

βœ… Verification successful

CORS annotations removed from location endpoints

The @crossorigin annotations have been removed from all methods in the LocationController: getStates, getDistricts, getStatetDistricts, getDistrictBlocks, getCity, getVillages, and getCountries. This aligns with the global CORS configuration approach.

Also applies to: 70-70, 86-86, 103-103, 119-119, 136-136, 157-157


🏁 Script executed:

#!/bin/bash
# Examine application properties to check CORS configuration
echo "Searching for CORS configuration in properties files..."
fd --type f --extension properties | xargs grep -l "cors"

Length of output: 220


Approved: Global CORS Configuration Verified

The global CORS setup was confirmed by the properties file (src/main/environment/common_ci.properties) containing relevant CORS settings. This validates the removal of the @CrossOrigin annotations from the LocationController methods (lines 54, 70, 86, 103, 119, 136, and 157), ensuring consistency across the application.

src/main/java/com/iemr/common/controller/door_to_door_app/DoorToDoorAppController.java (1)

42-42:

βœ… Verification successful

CORS annotations removed at both class and method levels

The @crossorigin annotations have been removed from the DoorToDoorAppController class as well as from the getUserDetails and getSuspectedData_HRP_TB_NCD methods. This is part of the architectural change to use global CORS configuration instead of method-level annotations.

Also applies to: 52-52, 73-73


🏁 Script executed:

#!/bin/bash
# Look for the implementation of the global CORS configuration
echo "Checking CorsConfig implementation details..."
fd "CorsConfig.java" --type f | xargs cat

Length of output: 1066


Global CORS Configuration Verified

The removal of the @CrossOrigin annotations from the DoorToDoorAppController (lines 42, 52, and 73) is confirmed by our global CORS configuration in CorsConfig.java. The implementation in CorsConfig.java correctly sets up CORS using allowed origin patterns and the necessary HTTP methods. This centralized approach aligns with the architectural shift away from method-level annotations.

src/main/java/com/iemr/common/controller/lungassessment/LungAssessmentController.java (3)

50-50: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the startAssesment method is consistent with the centralized CORS approach being implemented in this PR.


68-68: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getAssessment method is consistent with the centralized CORS approach being implemented in this PR.


86-86: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getAssessmentDetails method is consistent with the centralized CORS approach being implemented in this PR.

src/main/java/com/iemr/common/controller/directory/DirectoryController.java (4)

82-82: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getDirectory method is consistent with the centralized CORS approach being implemented in this PR.


103-103: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getDirectoryV1 method is consistent with the centralized CORS approach being implemented in this PR.


127-127: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getSubDirectory method is consistent with the centralized CORS approach being implemented in this PR.


151-151: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getInstitutesDirectories method is consistent with the centralized CORS approach being implemented in this PR.

src/main/java/com/iemr/common/controller/users/EmployeeSignatureController.java (3)

59-59: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the fetchFile method is consistent with the centralized CORS approach being implemented in this PR.


81-81: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the fetchFileFromCentral method is consistent with the centralized CORS approach being implemented in this PR.


103-103: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the existFile method is consistent with the centralized CORS approach being implemented in this PR.

src/main/java/com/iemr/common/controller/covid/CovidVaccinationController.java (4)

62-62: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getVaccinationTypeAndDoseTaken method is consistent with the centralized CORS approach being implemented in this PR.


87-87: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the getCovidVaccinationDetails method is consistent with the centralized CORS approach being implemented in this PR.


131-131: Removal of @crossorigin annotation aligns with global CORS configuration.

The removal of the @crossorigin annotation from the saveCovidVaccinationDetails method is consistent with the centralized CORS approach being implemented in this PR.


1-167:

βœ… Verification successful

Consider adding exception handling for potential CORS-related issues

With the transition to a global CORS configuration, it's important to ensure that any CORS-related exceptions are properly handled. Consider adding appropriate exception handling or logging for situations where CORS might still cause issues.


🏁 Script executed:

#!/bin/bash
# Check if there's appropriate CORS exception handling in the new CorsConfig class

fd "CorsConfig" --type f --exec cat {} \; | grep -B 5 -A 10 "implements WebMvcConfigurer"

Length of output: 728


CORS Exception Handling Verified via Global Configuration

After verifying the global configuration in the CorsConfig class (which implements WebMvcConfigurer and correctly sets up CORS mappings and allowed origins), it appears that potential CORS issues are already managed centrally. There is no need to add additional exception handling in the CovidVaccinationController.

  • Verified File: CorsConfig properly configures CORS via addCorsMappings.
  • Action: No changes required in CovidVaccinationController for CORS exception handling.
src/main/java/com/iemr/common/controller/users/IEMRAdminController.java (21)

109-109: CORS configuration now centralized

The removal of @CrossOrigin() annotation is part of the global CORS configuration implementation. This change improves security and maintainability by enforcing a consistent CORS policy across all endpoints.


124-124: Consistent CORS policy enforcement

Removing method-level @CrossOrigin() annotation aligns with the PR objective of implementing a global CORS configuration, making the security policy more consistent and maintainable.


284-284: Centralized CORS handling

The removal of @CrossOrigin() annotation from this method supports the global CORS configuration approach, reducing duplication and improving security governance.


449-475: Commented code removal

The commented-out userAuthenticateV1 method is being fully removed. This is good practice as it reduces code clutter and prevents potential confusion.


477-477: Standardized CORS management

Removing the method-level CORS annotation ensures that all authentication endpoints follow the same cross-origin policy defined in the global configuration.


490-490: Consistent security policy

Removing the @CrossOrigin() annotation from the password management endpoint ensures uniform security policy enforcement across the application.


530-530: Global CORS configuration adoption

The removal of method-specific CORS annotation aligns with the PR's goal of centralizing CORS management, which helps prevent security misconfiguration.


569-569: Centralized access control

Removing the @CrossOrigin() annotation from this sensitive endpoint (password change) improves security by ensuring it adheres to the globally defined CORS rules.


639-639: Consolidated CORS configuration

The @CrossOrigin() annotation removal from this endpoint contributes to the unified CORS policy implementation across the application.


672-672: Standardized access control

Removing the method-level CORS annotation ensures consistent handling of cross-origin requests for role-based access endpoints.


714-714: Unified CORS management

Centralizing CORS configuration by removing method-specific annotations improves maintainability and security consistency for user service point endpoints.


735-735: Standardized cross-origin policy

The removal of @CrossOrigin() annotation from this data access endpoint ensures it follows the globally defined security rules.


756-756: Centralized security control

Removing method-level CORS configuration contributes to a more maintainable and consistent security posture for location-based endpoints.


774-774: Uniform CORS handling

The removal of @CrossOrigin() annotation from the logout endpoint ensures consistent security behavior across authentication-related operations.


822-822: Consolidated access control

Removing the method-specific CORS annotation from this session management endpoint improves security governance through centralized configuration.


837-837: Standardized security policy

The @CrossOrigin() annotation removal ensures that the logout functionality adheres to the globally defined CORS policy.


852-852: Improved CORS governance

Removing the method-level CORS annotation contributes to a more consistent and maintainable cross-origin security implementation.


869-869: Centralized cross-origin control

The removal of @CrossOrigin() annotation from this authentication endpoint aligns with the global CORS configuration strategy.


936-936: Consistent security implementation

Removing method-specific CORS annotation ensures that security validation endpoints follow the centralized cross-origin policy.


962-962: Unified CORS management

Removing the @CrossOrigin() annotation from this authentication endpoint ensures consistent cross-origin request handling across the application.


75-1037:

❓ Verification inconclusive

Verify global CORS configuration compatibility with all endpoints

All method-level CORS annotations have been removed in favor of a centralized configuration. Make sure that the global CORS settings in the new CorsConfig class provide appropriate access for all these endpoints, especially considering the various authentication, user management, and administrative operations they handle.


🏁 Script executed:

#!/bin/bash
# Check for the new CorsConfig class to understand the global configuration
fd -e java "CorsConfig.java" | xargs cat

# Check application properties to see CORS-related settings
fd -e properties | xargs grep -l "cors" | xargs cat

Length of output: 7258


Global CORS Configuration Verification

The centralized CORS setup in CorsConfig now applies to all endpoints (with the pattern /**), allowing the HTTP methods GET, POST, PUT, DELETE, and OPTIONS; all headers are allowed; credentials are enabled; and specific headers like "Authorization" and "Jwttoken" are exposed. This effectively removes method-level CORS annotations.

Key points for verification:

  • The configuration derives allowed origins from the cors.allowed-origins property. However, the properties output shows this value is currently empty.
  • Ensure that in each deployment environment (or via environment variables), the cors.allowed-origins property is properly set; an empty value may lead to unintended restrictions on frontend access.
  • Double-check that this global configuration meets the security and functionality requirements for all authentication, user management, and administrative operations.

Please verify that the intended origins are correctly configured (and are not left empty) so that all endpoints are accessible as expected.

@@ -167,5 +167,7 @@ grievanceAllocationRetryConfiguration=3
start-grievancedatasync-scheduler=false
cron-scheduler-grievancedatasync=0 0/2 * * * ?

cors.allowed-origins=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Verification agent

🧩 Analysis chain

Empty value for CORS allowed origins

The cors.allowed-origins property has been added but left empty. This could lead to either all cross-origin requests being blocked or potentially allowing all origins depending on how the property is processed in the CorsConfig class.

Please specify appropriate values for this property based on your environment requirements. Typical values might include:

  • Specific domain: https://example.com
  • Multiple domains: https://example.com,https://another-example.com
  • Wildcard: * (allows all origins, but should be used cautiously in production)

🏁 Script executed:

#!/bin/bash
# Check how cors.allowed-origins is being used in the code
grep -r "cors.allowed-origins" --include="*.java" .

Length of output: 144


Action: Update CORS Allowed Origins Configuration

The cors.allowed-origins property in src/main/environment/common_ci.properties is currently empty. The property is injected in CorsConfig.java via @Value("${cors.allowed-origins}"), meaning that if this value remains unset, the application’s CORS behavior could inadvertently either block all cross-origin requests or potentially allow all origins depending on the internal processing logic.

Please specify the correct origin(s) based on your environment requirements. For example:

  • A specific domain: https://example.com
  • Multiple domains: https://example.com,https://another-example.com
  • A wildcard (*): Use cautiously in non-production setups

@@ -58,7 +58,7 @@ public void setCallReportsService(CallReportsService callReportsService) {
@Autowired
Report1097Mapper mapper;

@CrossOrigin()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Verification agent

🧩 Analysis chain

Removed @crossorigin annotation as part of global CORS configuration

The removal of the method-level @CrossOrigin() annotation is consistent with the PR objective of implementing a global CORS configuration. Note that this controller still has a class-level @CrossOrigin annotation at line 43, which might need to be addressed for complete centralization.


🏁 Script executed:

#!/bin/bash
# Check if any controllers in the codebase still have class-level @CrossOrigin annotations
# that might override the global configuration

grep -r "@CrossOrigin" --include="*.java" src/main/java/com/iemr/common/controller/

Length of output: 1171


Action Required: Evaluate Class-Level @crossorigin in CustomerRelationshipReports

The removal of the method-level @CrossOrigin() annotation aligns with moving to a global CORS configuration. However, the CustomerRelationshipReports.java controller still retains a class-level @CrossOrigin annotation (line 43). Please verify whether this annotation is necessary or if it can be removed to ensure complete centralization of CORS settings.

  • File: src/main/java/com/iemr/common/controller/report/CustomerRelationshipReports.java
  • Concern: Remnant class-level @CrossOrigin annotation at line 43

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
6.2% Duplication on New Code (required ≀ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant