Skip to content

Instantly share code, notes, and snippets.

@brenopolanski
Last active February 23, 2021 17:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brenopolanski/fce90f0090ce19bcaa3acef4af9c8eb3 to your computer and use it in GitHub Desktop.
Save brenopolanski/fce90f0090ce19bcaa3acef4af9c8eb3 to your computer and use it in GitHub Desktop.
Solving CORS problem on embedding Pentaho CDE dashboard in web application

Solving CORS problem on embedding Pentaho CDE dashboard in web application

Cross-Origin Resource Sharing (CORS) is a W3C spec that allows cross-domain communication from the browser. By building on top of the XMLHttpRequest object, CORS allows developers to work with the same idioms as same-domain requests.

Enable Cross Origin Resource Sharing (CORS) in the Community Dashboard Framework (CDF), Community Dashboard Editor (CDE), and Community Data Access (CDA). While you need CDE to embed the dashboard, you will access it from a different server other than the Pentaho Server, so CORS must be enabled in CDF, CDE and CDA. Open the following CDF, CDE, and CDA settings.xml files in a text editor:

  • For CDF: server/pentaho-server/pentaho-solutions/system/pentaho-cdf/settings.xml.
  • For CDE: server/pentaho-server/pentaho-solutions/system/pentaho-cdf-dd/settings.xml.
  • For CDA: server/pentaho-server/pentaho-solutions/system/cda/settings.xml.

Make the following replacements in each settings.xml file:

  1. Find the line:
<cors-request-allowed>false</cors-request-allowed>

and then change it to:

<cors-request-allowed>true</cors-request-allowed>
  1. Find the line:
<cors-requests-allowed-domains><!-- allowed domains here --></cors-requests-allowed-domains>

and then change it to:

<cors-requests-allowed-domains>http://localhost:2777</cors-requests-allowed-domains>
  1. Add cors-filter-2.4.jar to the <<pentaho-server>>/tomcat/lib directory.

Download: cors-filter-2.4.jar

  1. Add below filter-mapping into the <<pentaho-server>>/tomcat/conf/web.xml file:
<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.headers</param-name>
    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
  </init-param>
  <init-param>
    <param-name>cors.exposed.headers</param-name>
    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
  </init-param>
  <init-param>
    <param-name>cors.support.credentials</param-name>
    <param-value>true</param-value>
  </init-param>
  <init-param>
    <param-name>cors.preflight.maxage</param-name>
    <param-value>10</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Resources

@magoya1487
Copy link

hi, have link the library cors-filter-2.4.jar ?
try te configuratioon but nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment