CORS Filter

Configuration

The CORS Filter can be run with no additional configuration in most situations. By default it operates in public mode: It informs the browser that requests from any origin are accepted and that they may include optional credentials such as cookies.

The default CORS behaviour can be overridden by adding one or more explicit init-param elements to the filter declaration in the WEB-INF/web.xml descriptor file.

For example, to allow CORS requests from the http://example.com origin only:

<filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

        <init-param>
                <param-name>cors.allowOrigin</param-name>
                <param-value>http://example.com</param-value>
        </init-param>
</filter>

Have a look at the web.xml of the demo CORS application included with the download package to see a complete CORS filter declaration, configuration and mapping example.

Filter init parameters

Remember to restart your web server after making CORS configuration changes!