Configuring CORS Filters

Cross-origin resource sharing (CORS) is included with FME Server and is disabled by default. You must manually enable the CORS filter for each web service or web interface applicable. To do this for a particular web application, open its deployment descriptor in a text editor and uncomment the CORS filter directives at the end of the file.

Enable CORS Filter

  1. Open the WEB-INF/web.xml file of the web application where you want to enable CORS
  2. For example, the default location of this file for the Job Submitter service is \FMEServer\Utilities\tomcat\webapps\fmejobsubmitter\WEB-INF\web.xml.

  3. Uncomment the CORS configuration directives. For example:
  4. <!-- Cross-Origin Resource Sharing - Filter Configuration

    Enabling this filter allows you to control cross-origin requests rather than coping with traditional

    browser restrictions.

    Uncomment the section below and configure the "init-param" elements that meet your CORS requirements.

    CORS Configuration - http://software.dzhuvinov.com/cors-filter-configuration.html

    See Also the FME Server Reference Manual

    -->

    <filter>

    <filter-name>CORS</filter-name>

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

    </filter>

    By default the CORS filter is configured to be enabled for every possible URI to the web application. This can be adjusted using J2EE filters. (For more information, see the J2EE v2.5 Servlet Specification.)

    <filter-mapping>

    <filter-name>CORS</filter-name>

    <url-pattern>/*</url-pattern>

    </filter-mapping>

    For a complete CORS filter declaration and mapping example, see the web.xml of the demo CORS application included with the download package.

  5. Restart the web application or server.

Note:   By default the CORS filter applies a "public access" CORS policy, allowing all cross-site requests (including credentials/cookies). Leaving the CORS Filter at this setting is appropriate for most situations, as the intent of CORS is not to add server security, but to protect the browser, including legitimate JavaScript apps running in it and the user's confidential data, such as cookies.

Restrict CORS Filter

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 behavior 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 http://example.com 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://safe.com</param-value>

</init-param>

</filter>

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

Note:  You must restart the web application or server after making CORS configuration changes.

Filter init parameters

Note:  You must restart the web application or server after making CORS configuration changes.

See Also