# Flowable-task/process-api cors configuration

**URL:** https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085
**Category:** Uncategorized
**Created:** [October 22, 2017, 7:16pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085 "2017-10-22T19:16:05Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fabianyvidal](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fabianyvidal/32/275_2.png) [@fabianyvidal](https://forum.flowable.org/u/fabianyvidal)
#### Post date: [October 22, 2017, 7:16pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/1 "2017-10-22T19:16:05Z")

</div>

I am working with cloned project locally and I have tried to connect to from flowable-task/process-api from a third party application that is running on localhost:4200, but I am getting CORS problems:

_**Failed to load [http://localhost:8080/flowable-task/process-api/query/tasks:](http://localhost:8080/flowable-task/process-api/query/tasks:) Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://localhost:4200](http://localhost:4200)’ is therefore not allowed access. The response had HTTP status code 401.**_

Based on error above I have tried to add a global CORS configuration as it is recommended in spring documentation but it does not work:

package org.flowable.app.conf;  
import org.springframework.context.annotation.Configuration;  
import org.springframework.web.servlet.config.annotation.CorsRegistry;  
import org.springframework.web.servlet.config.annotation.EnableWebMvc;  
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration  
@EnableWebMvc  
public class WebConfig extends WebMvcConfigurerAdapter {

```
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
    .allowCredentials(true)
    .allowedMethods("POST"," GET","PUT", "OPTIONS", "DELETE", "PATCH")
    .maxAge(3600)
    .allowedHeaders("Authorization", "X-Requested-with","Accept","Content-Type")  
    .allowedOrigins("http://localhost:4200")
    ;
}

```

}

How could I solved the CORS problem?

Thanks in advace!!

---

<div class="post-metadata">

### Author: ![horsey](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/horsey/32/291_2.png) [@horsey](https://forum.flowable.org/u/horsey)
#### Post date: [October 22, 2017, 7:49pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/2 "2017-10-22T19:49:58Z")

</div>

@fabianyvidal,  
Spring security documentation on this helped me solve the problem that you are having:  
[https://docs.spring.io/spring-security/site/docs/current/reference/html/cors.html](https://docs.spring.io/spring-security/site/docs/current/reference/html/cors.html)

---

<div class="post-metadata">

### Author: ![fabianyvidal](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fabianyvidal/32/275_2.png) [@fabianyvidal](https://forum.flowable.org/u/fabianyvidal)
#### Post date: [October 24, 2017, 1:10pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/4 "2017-10-24T13:10:49Z")

</div>

thanks @horsey, based on your answer I realized that the key point was to make cors be processed before Spring Security, so I create a filter and use .addfilterBefore() in ApiWebSecurityConfigurationAdapter and it worked:

```
@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
    protected void configure(HttpSecurity http) throws Exception {
        http
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .csrf()
                .disable()
                .antMatcher("/*-api/**").authorizeRequests()
                .antMatchers("/*-api/**").authenticated()                    
                .and().httpBasic().and().addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class);
    }            
}

```

I created filter as:

```
 @Component
public class CORSFilter implements Filter{
    static Logger logger = LoggerFactory.getLogger(CORSFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
      
    	HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		
		response.setHeader("Access-Control-Allow-Origin","http://localhost:4200");
		response.setHeader("Access-Control-Allow-Credentials", "true");
		response.setHeader("Access-Control-Allow-Methods", "POST, GET,PUT, OPTIONS, DELETE");
		response.setHeader("Access-Control-Max-Age", "3600");
		response.setHeader("Access-Control-Allow-Headers", "Authorization, X-Requested-with,Accept,Content-Type");
		
		if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {			
	        response.setStatus(HttpServletResponse.SC_OK);
	    } else {
	    	
	        chain.doFilter(req, res);
	    }         
    }

    public void destroy() {}
}
```

---

<div class="post-metadata">

### Author: ![nunesigor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/nunesigor/32/659_2.png) [@nunesigor](https://forum.flowable.org/u/nunesigor)
#### Post date: [July 13, 2018, 5:40pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/5 "2018-07-13T17:40:15Z")

</div>

Did you put this on separated jar, or, overwrite flowable class and rebuild ? I’m with same problem but I don’t have much experience with spring boot.

---

<div class="post-metadata">

### Author: ![biyat](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@biyat](https://forum.flowable.org/u/biyat)
#### Post date: [September 7, 2018, 3:53pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/6 "2018-09-07T15:53:27Z")

</div>

Can’t we configure CORS for Flowable without touching Flowable Source Code?

---

<div class="post-metadata">

### Author: ![shamalk](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@shamalk](https://forum.flowable.org/u/shamalk)
#### Post date: [January 3, 2020, 6:20am UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/7 "2020-01-03T06:20:49Z")

</div>

I’m also looking for a solution for this. Without touching code.

---

<div class="post-metadata">

### Author: ![namanchopra21087](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/namanchopra21087/32/1522_2.png) [@namanchopra21087](https://forum.flowable.org/u/namanchopra21087)
#### Post date: [January 6, 2020, 12:48pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/8 "2020-01-06T12:48:00Z")

</div>

Hi All,

I am also struck in browser same-origin policy and need to enable CORS inside flowable to make communication between angular–\>flowable.

Please help in case someone has resolved this issue without changing flowable source-code.

Regards  
Naman Chopra

---

<div class="post-metadata">

### Author: ![RishikeshVIncture](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/rishikeshvincture/32/3487_2.png) [@RishikeshVIncture](https://forum.flowable.org/u/RishikeshVIncture)
#### Post date: [May 20, 2024, 12:16pm UTC](https://forum.flowable.org/t/flowable-task-process-api-cors-configuration/1085/9 "2024-05-20T12:16:56Z")

</div>

Dear @fabianyvidal and @martin.grofcik

I’m reaching out regarding an issue I’m encountering while trying to access APIs through a React application. I’m experiencing CORS (Cross-Origin Resource Sharing) problems and have attempted various solutions without success. I have also tried your approach @fabianyvidal but yet still facing issues with the CORS, maybe somewhere I might have missed some implementation.

I would be grateful if you could share any insights or suggestions you might have to resolve this issue. Any relevant experience or workaround strategies you could provide would be greatly appreciated.

Thank you for your time and assistance.

Sincerely,  
@RishikeshVIncture
