cancel
Showing results for 
Search instead for 
Did you mean: 

I need help with CORS

viperboys
Star Contributor
Star Contributor

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
5 REPLIES 5

@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 .

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)

I'm using alfresco and when i make a requisition on my front (localhost:4200) to the alfresco's backend api (localhost:8080), i got a cors issue and tried a lot to fix that problem, but with no sucess.

I use windows and used that instalation mode:

https://github.com/Alfresco/alfresco-sdk/blob/master/docs/getting-started.md

I cant find some files to help that kind of issue because of the instalation method i think. That files simply doesnt exist.

Files like cors that u open with notepad and edit as you want, putting filters or adding some properties.

Also, i tried to find the alfresco-global-config.property, i found it, but when i put properties that works with that authorizations, like that: 

cors.enabled=true

cors.allowed.origins=http://localhost:4200

cors.allowed.methods=GET,POST,PUT,DELETE,OPTIONS

cors.allowed.headers=* cors.allow.credentials=false

it doesnt work. Im really hope that anyone could help me at this point.

thanks!

cararuna
Champ on-the-rise
Champ on-the-rise

I did it.

My issue with cors was simple to solve.

I used proxy to mascarate my back end url as an api context, so they allow me to make requests.

1. Create a file on the same folder of package,json named proxy.conf.json

2. Inside this files, put:

{
  "target": "http://localhost:8080",
  "context": "/api",
  "pathRewrite": {
    "^/api": ""
  },
  "secure": false,
  "changeOrigin": true
}
 
3. when you make request on front end, rewrite your end point, changing a part. (before was localhost:8080/alfresco/api... because my back end is on 8080, i changed to localhost:4200/api/alfresco/api... and done, my front was on 4200. The proxy.conf.json tells that "api" context is allowed by the backend because only makes the request after accepting that is on a allowed end point. CHANGE: localhost:8080 -> localhost:4200/api