Our Work

How to enable CORS in Liferay 7

Updated 26 days ago

In this Article we will learn how to enable Liferay Cross Domain Access. Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. To allow CORS in liferay we need to do few configuration changes and also we need to import few libraries.

  • Step 1: First download the below jars and keep in the tomcat lib

    • Cors-filter-2.6.jar

    • Java-property-utils-1.13.jar

  • Step 2: Then we need to add xml configuration to Liferay/tomcat/webapps/ROOT/WEB-INF/web.xml file

	<!-- Cors Filter  -->
    	<filter>
        	<filter-name>CORS</filter-name>
        	<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    	<init-param>
    	<param-name>cors.allowOrigin</param-name>
       <!-- Update specific domains instead of giving to all -->
    	<param-value>*</param-value>
    	</init-param>
    	<init-param>
    	<param-name>cors.supportsCredentials</param-name>
    	<param-value>false</param-value>
    	</init-param>
    	<init-param>
    	<param-name>cors.supportedHeaders</param-name>
    	<param-value>accept, authorization, origin</param-value>
        	</init-param>
     <init-param>
    	<param-name>cors.supportedMethods</param-name>
            	<param-value>GET, POST, HEAD, OPTIONS</param-value>
     </init-param>
    	</filter>
    	<filter-mapping>
        	<filter-name>CORS</filter-name>
        	<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	<!-- Cors Filter End -->
  • Step 3: After completion of above configuration, we need to restart liferay server.

KTree is the best offshore Liferay development company with extensive experience in Liferay Portal Development services alongwith Upgrade & Migration. Hire Liferay developers or Liferay development services from LiferayDeveloper.
KTree is one of top most Web Application Development company from India which specializes in Web Application development and Mobile Apps Development