Skip to content

Conversation

@AshokThangavel
Copy link
Contributor

@AshokThangavel AshokThangavel commented Dec 1, 2025

PR: Feature - Default CORS and JWT Configuration for Web Applications

This Pull Request enables default configuration settings for Cross-Origin Resource Sharing (CORS) and JSON Web Token (JWT) Authentication directly into the IPM module.xml <WebApplication> resource definition. This enhancement enables the use of existing features through the package manager.
Fixes #814

Summary of Feature Enhancements

This feature request introduces the following capabilities:

  1. Support for loading CORS and JWT properties defined in the <WebApplication> configuration section

  2. Support for loading CORS and JWT properties generated through the IPM CLI (Generate/gen) command

    • During generation, replaces the deprecated <CSPApplication> element with the correct <WebApplication> element.

Key Features & Rationale

Feature IRIS Version IPM Attributes Added
Default CORS Settings 2025+ CorsAllowlist, CorsCredentialsAllowed, CorsHeadersList
Default JWT Authentication 2024+ JWTAuthEnabled, JWTAccessTokenTimeout, JWTRefreshTokenTimeout

Combined Configuration Example

The following attributes are now included in the <WebApplication> tag by default, ensuring immediate security compliance for the created web application (/testcors):

<WebApplication
    ...
    CorsAllowlist="https://www.example.com,https://pm.intersystems.com" 
    CorsCredentialsAllowed="1" 
    JWTAccessTokenTimeout="60" 
    JWTAuthEnabled="1" 
    JWTRefreshTokenTimeout="900" 
    CorsHeadersList="Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Access-Control-Max-Age, Access-Control-Expose-Headers, Access-Control-Request-Method, Access-Control-Request-Headers" 
    ...
/>

Detailed Test Results

Extensive unit and integration testing was performed to validate the correct application of these settings. All tests passed successfully, confirming the configuration integrity and non-interference between the two security features.

1. Unit Test Results (CORS Configuration Verification)

Class: Test.PM.Unit.WebAppCorsTest

TestMethod Status ErrorDescription Duration
TestCORSEnabledViaWebAppTag passed 0.980177
Action Status Description Location
LogMessage passed loading via "WebApplcation" tag TestCORSEnabledViaWebAppTag+1^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed Removed the 'module.xml' file from /home/irisowner/zpm/tests/unit_tests/Test/PM/Unit/_data/cors-rest-apps/webapp/ TestCORSEnabledViaWebAppTag+10^Test.PM.Unit.WebAppCorsTest.cls
LogMessage passed Creating module.xml with "WebApplcation" tag TestCORSEnabledViaWebAppTag+12^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed Created module.xml manually on /home/irisowner/zpm/tests/unit_tests/Test/PM/Unit/_data/cors-rest-apps/webapp/ successfully. TestCORSEnabledViaWebAppTag+17^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed Loaded cors-rest-apps module successfully. /home/irisowner/zpm/tests/unit_tests/Test/PM/Unit/_data/cors-rest-apps/webapp/ TestCORSEnabledViaWebAppTag+20^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed Web application /testcors created successfully VerifyCORSSettings+4^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed CorsAllowlist values are defined VerifyCORSSettings+6^Test.PM.Unit.WebAppCorsTest.cls
LogMessage passed https://pm.intersystems.com VerifyCORSSettings+7^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed CorsCredentialsAllowed values are defined VerifyCORSSettings+10^Test.PM.Unit.WebAppCorsTest.cls
LogMessage passed 1 VerifyCORSSettings+11^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed CorsHeadersList values are defined VerifyCORSSettings+14^Test.PM.Unit.WebAppCorsTest.cls
LogMessage passed Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Access-Control-Max-Age, Access-Control-Expose-Headers, Origin, Access-Control-Request-Method, Access-Control-Request-Headers VerifyCORSSettings+15^Test.PM.Unit.WebAppCorsTest.cls
AssertStatusOK passed uninstalled cors-rest-apps module successfully. TestCORSEnabledViaWebAppTag+24^Test.PM.Unit.WebAppCorsTest.cls
LogMessage passed Duration of execution: .980177 sec.

2. Unit Test Results (JWT Configuration Verification)

Class: Test.PM.Unit.WebAppJWTConfigTest

TestMethod Status ErrorDescription Duration
TestJWTEnabledViaWebAppTag passed 1.133911
Action Status Description Location
LogMessage passed loading via "WebApplcation" tag TestJWTEnabledViaWebAppTag+1^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed Removed the 'module.xml' file from /home/irisowner/zpm/tests/unit_tests/Test/PM/Unit/_data/cors-rest-apps/webapp/ TestJWTEnabledViaWebAppTag+10^Test.PM.Unit.WebAppJWTConfigTest.cls
LogMessage passed Creating module.xml with "WebApplcation" tag TestJWTEnabledViaWebAppTag+12^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed Created module.xml manually on /home/irisowner/zpm/tests/unit_tests/Test/PM/Unit/_data/cors-rest-apps/webapp/ successfully. TestJWTEnabledViaWebAppTag+17^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed Loaded cors-rest-apps module successfully. /home/irisowner/zpm/tests/unit_tests/Test/PM/Unit/_data/cors-rest-apps/webapp/ TestJWTEnabledViaWebAppTag+20^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed Web application /testcors created successfully VerifyJWTConfiguration+4^Test.PM.Unit.WebAppJWTConfigTest.cls
LogMessage passed Validating JWT configuration VerifyJWTConfiguration+5^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed JWTAccessTokenTimeout value is defined VerifyJWTConfiguration+7^Test.PM.Unit.WebAppJWTConfigTest.cls
LogMessage passed 60 VerifyJWTConfiguration+8^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed JWTAuthEnabled value is defined VerifyJWTConfiguration+11^Test.PM.Unit.WebAppJWTConfigTest.cls
LogMessage passed 1 VerifyJWTConfiguration+12^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed JWTRefreshTokenTimeout value is defined VerifyJWTConfiguration+15^Test.PM.Unit.WebAppJWTConfigTest.cls
LogMessage passed 900 VerifyJWTConfiguration+16^Test.PM.Unit.WebAppJWTConfigTest.cls
AssertStatusOK passed uninstalled cors-rest-apps module successfully. TestJWTEnabledViaWebAppTag+24^Test.PM.Unit.WebAppJWTConfigTest.cls
LogMessage passed Duration of execution: 1.133911 sec.

3. Integration Test Results (Combined Validation)

Class: Test.PM.Integration.ConfigCorsAndJWTInWebAppTest

This test confirms the successful and simultaneous application of all CORS and JWT settings during a single module load, demonstrating complete feature integration.

Action Status Description Location
AssertStatusOK passed Loaded cors-rest-apps module successfully. N/A
AssertStatusOK passed Web applciation /testcors created scuccessfully N/A
AssertStatusOK passed CorsAllowlist values are defined N/A
LogMessage passed https://www.example.com,https://pm.intersystems.com N/A
AssertStatusOK passed CorsCredentialsAllowed values are defined N/A
LogMessage passed 1 N/A
AssertStatusOK passed CorsHeadersList values are defined N/A
LogMessage passed Access-Control-Allow-Origin, ... (Confirmed comprehensive list) N/A
AssertStatusOK passed Web applciation /testcors created scuccessfully N/A
LogMessage passed Validating JWT configuration N/A
AssertStatusOK passed JWTAccessTokenTimeout value is defined (60) N/A
AssertStatusOK passed JWTAuthEnabled value is defined (1) N/A
AssertStatusOK passed JWTRefreshTokenTimeout value is defined (900) N/A
AssertStatusOK passed uninstalled cors-rest-apps module successfully. N/A
LogMessage passed Duration of execution: .947516 sec. N/A
Overall Passed Test.PM.Integration.CorsAndJWTTest passed N/A

@isc-dchui
Copy link
Collaborator

(Unfortunately) CSPApplication has been deprecated in favor of WebApplication and CPFMerge, so we're really not looking to make any improvements to it. I'll let @isc-tleavitt and @isc-kiyer weigh in if they believe differently though.

@AshokThangavel
Copy link
Contributor Author

Hi @isc-dchui
Thank you for the feedback. However, This feature request provides support for both WebApplication and the deprecated, backward-compatible CSPApplication.
Thank you!

@isc-kiyer
Copy link
Collaborator

Hi @isc-dchui Thank you for the feedback. However, This feature request provides support for both WebApplication and the deprecated, backward-compatible CSPApplication. Thank you!

@AshokThangavel Thanks for the PR! Please remove any changes to CSPApplication. Since it is deprecated, we want to encourage moving to WebApplication. For tests added, please add them to WebApplication instead of CSPApplication.

@AshokThangavel
Copy link
Contributor Author

Hi @isc-kiyer
Thank you! I’ve removed all changes related to <CSPApplication> and committed the updates. All code and test cases are now under <WebApplication>.

Copy link
Collaborator

@isc-kiyer isc-kiyer left a comment

Choose a reason for hiding this comment

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

@AshokThangavel a few more comments (mostly regarding naming and removing redundancies)!

JWTAuthEnabled="1"
JWTRefreshTokenTimeout="900"
CorsHeadersList="Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Access-Control-Max-Age, Access-Control-Expose-Headers, Access-Control-Request-Method, Access-Control-Request-Headers"
PasswordAuthEnabled="1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

For WebApplication, these properties for auth are all encapsulated as part of AutheEnabled and not separate properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@isc-kiyer
Could you please provide an example of how the authentication settings are represented when they are encapsulated under the AuthEnabled attribute in the element?
A sample XML snippet would be very helpful.
Thank you!

CorsAllowlist="https://pm.intersystems.com"
CorsCredentialsAllowed="1"
CorsHeadersList="Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Access-Control-Max-Age, Access-Control-Expose-Headers, Origin, Access-Control-Request-Method, Access-Control-Request-Headers"
PasswordAuthEnabled="1" Recurse="1" UnauthenticatedEnabled="0" UseCookies="2"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

For WebApplication, these properties for auth are all encapsulated as part of AutheEnabled and not separate properties.

JWTAccessTokenTimeout="60"
JWTAuthEnabled="1"
JWTRefreshTokenTimeout="900"
PasswordAuthEnabled="1" Recurse="1" UnauthenticatedEnabled="0" UseCookies="2"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

For WebApplication, these properties for auth are all encapsulated as part of AutheEnabled and not separate properties.

@@ -0,0 +1,72 @@
/// This class validates that CORS headers and allowed origins are configured correctly,
/// and that JWT authentication is properly set up in the <b>&lt;WebApplication&gt;</b> configuration section.
Class Test.PM.Integration.ConfigCorsAndJWTInWebAppTest Extends Test.PM.Integration.Base
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test class captures the behavior so I don't think the unit tests are needed. Furthermore, in general, if unit testing a single feature, we prefer to keep tests in a single class and have multiple methods rather than splitting it across classes..
Lastly, I would name this Test.PM.Integration.ResourceProcessor.WebApplication so any other WebApplication related tests can be added here in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback.
I’ve made the changes based on your suggestions:

  • Renamed the integration test class to Test.PM.Integration.ResourceProcessor.WebApplication
  • Removed separate unit test classes since the existing test class already captures the required behavior.
    Thank you!

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.

Add support 2025.1 web app CORS settings to generate command

3 participants