I need help with CORS

cancel
Showing results for 
Search instead for 
Did you mean: 
viperboys
Active Member II

I need help with CORS

Hi

I am new to Alfresco. About 3 years ago I did a development where through APIS I sent a Wordpress file to Alfresco. This was super good. Now I want to implement it again and it doesn't work for me. I get this error

Política de referentes: Ignorando la política de referencias menos restringida “origin-when-cross-origin” para la solicitud de sitios cruzados: http://127.0.0.1:8080/alfresco/service/api/login.json?u=admin&pw=admin jquery.min.js:2:82713
Solicitud desde otro origen bloqueada: la política de mismo origen impide leer el recurso remoto en http://127.0.0.1:8080/alfresco/service/api/login.json?u=admin&pw=admin (razón: falta la cabecera CORS 'Access-Control-Allow-Origin'). Código de estado: 200.
 
Solicitud de origen cruzado bloqueada: La misma política de origen no permite la lectura de recursos remotos en http://127.0.0.1:8080/alfresco/service/api/login.json?u=admin&pw=admin. (Razón: Solicitud CORS sin éxito). Código de estado: (null).
 
I have Alfresco installed locally on my computer and my wordpress site is in the cloud. When it worked for me that time I did a lot of configuration in Alfresco but I don't remember.
 
If I remember correctly it was to enable CORS. This is my CORS now
<!-- CORS Filter Begin -->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>http://localhost:8081</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, PUT, DELETE, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>origin, authorization, x-file-size, x-file-name, content-type, accept, x-file-type</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
</filter>-->
<!-- CORS Filter End -->
 
What can be happening?
 
Thank you
3 Replies
abhinavmishra14
Advanced
ash_saxena10
Active Member II

Re: I need help with CORS

@abhinavmishra14 My observation for cors settings above Alfresco 6.0 version is once we place three jars enablecors-1.0.jar , cors-filter-2.5.jar and java-property-utils-1.9.1.jar at path $TOMCAT_DIR/webapps/alfresco/WEB-INF/lib/ ,

no need of configuring cors settings in  $TOMCAT_DIR/webapps/alfresco/WEB-INF/web.xml file as was specified in your above post . Just placing above three jar files should work . 

And better option would be to place it in $Alfresco_Dir/modules/platform/ as tomcat alfresco directory will re-explode in case of any changes to alfresco.war file and changes will be lost in that case .

abhinavmishra14
Advanced

Re: I need help with CORS

thanks @ash_saxena10 i am not sure about your observation. The example was tested with 7.x and you have to add the allowOrigin option in the web.xml.

Thanks for additonal details on the jar location. Yes it is useful when you setup manually using distribution or have a non-containerized deployment. The example is based on containerized deployment. Images are pre-built with exploded wars already and hence DockerFile will copy the jars to appropriate locations. 

Check here: https://github.com/abhinavmishra14/enable-cors-acs-demo/blob/master/build-config/alfresco/Dockerfile...

~Abhinav
(ACSCE, AWS SAA, Azure Admin)