Bug 59716 - Allow JNDI configuration of CorsFilter
Summary: Allow JNDI configuration of CorsFilter
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.69
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2016-06-17 14:43 UTC by Lucas Theisen
Modified: 2019-08-12 16:24 UTC (History)
0 users

Source code for the delegating filter and integration test. (5.76 KB, application/x-zip-compressed)
2016-06-17 14:43 UTC, Lucas Theisen

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Theisen 2016-06-17 14:43:16 UTC
Created attachment 33957 [details]
Source code for the delegating filter and integration test.

Currently the CorsFilter is configured by init-param's.  This makes configuration compile time (as it would be stored in the deployment artifact).  In my experience, CORS configuration is environmental (I have a different set of allowed origins based on where I deploy my app: dev/qa/production), and as such should be runtime.  Pushing config to JNDI (or at least allowing override in JNDI) allows you to configure the same artifact differently depending on environment.  I have written a filter that delegates to the CorsFilter to allow for JNDI config (which i will attach), but it would be quite simple and useful to move this functionality into the core filter.  I would be willing to patch the filter as well if you are interested in this approach...
Comment 1 Mark Thomas 2016-06-20 18:55:26 UTC
Moving to an enhancement request.

Tomcat typically handles this via property replacement [1].

[1] http://tomcat.apache.org/tomcat-9.0-doc/config/index.html
Comment 2 Lucas Theisen 2016-06-20 19:04:04 UTC
Fair enough...  I just find it easier to have all my application config in one place (GlobalNamingResources), rather than multiple (setenv.sh and GlobalNamingResources).  In any case, your suggestion would satisfy my requirement to have a single build be configurable differently per environment, so feel free to close this ticket.
Comment 3 Mark Thomas 2019-08-12 16:24:10 UTC
Closing this ticket as per the OP's comment. It is also worth noting that Java EE allows the injection of values from JNDI into Servlets, Filters etc. See section 5 of the Java EE 8 spec.