Skip to content

Commit

Permalink
Move cors config to nflow-rest-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Fonsell committed May 11, 2016
1 parent 7e34e5d commit 1662f42
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
4 changes: 0 additions & 4 deletions nflow-jetty/src/main/resources/nflow-jetty.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ host=0.0.0.0
port=7500
terminate.timeout=30
extra.resource.directories=

nflow.rest.allow.origin=*
nflow.rest.allow.headers=X-Requested-With, Content-Type, Origin, Referer, User-Agent, Accept
nflow.rest.cors.enabled=true
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.nitorcreations.nflow.rest.config;

import static java.lang.Boolean.TRUE;

import javax.inject.Inject;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
Expand All @@ -20,15 +18,15 @@
@NflowCors
public class CorsHeaderContainerResponseFilter implements ContainerResponseFilter {

private final boolean enabled;
private final String origin;
private final String headers;
private final boolean enabled;

@Inject
public CorsHeaderContainerResponseFilter(final Environment env) {
enabled = env.getRequiredProperty("nflow.rest.cors.enabled", Boolean.class);
origin = env.getRequiredProperty("nflow.rest.allow.origin");
headers = env.getRequiredProperty("nflow.rest.allow.headers");
enabled = env.getProperty("nflow.rest.cors.enabled", Boolean.class, TRUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.nitorcreations.nflow.rest.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource("classpath:nflow-rest-api.properties")
public class NflowRestApiPropertiesConfiguration {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.nitorcreations.nflow.engine.internal.config.NFlow;

@Configuration
@Import(EngineConfiguration.class)
@Import({ EngineConfiguration.class, NflowRestApiPropertiesConfiguration.class })
@ComponentScan("com.nitorcreations.nflow.rest")
public class RestConfiguration {

Expand Down
3 changes: 3 additions & 0 deletions nflow-rest-api/src/main/resources/nflow-rest-api.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nflow.rest.cors.enabled=true
nflow.rest.allow.origin=*
nflow.rest.allow.headers=X-Requested-With, Content-Type, Origin, Referer, User-Agent, Accept
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CorsHeaderContainerResponseFilterTest {
public void setup() {
when(env.getRequiredProperty("nflow.rest.allow.origin")).thenReturn(HOST);
when(env.getRequiredProperty("nflow.rest.allow.headers")).thenReturn(HEADERS);
when(env.getProperty("nflow.rest.cors.enabled", Boolean.class, TRUE)).thenReturn(TRUE);
when(env.getRequiredProperty("nflow.rest.cors.enabled", Boolean.class)).thenReturn(TRUE);
filter = new CorsHeaderContainerResponseFilter(env);
when(responseContext.getHeaders()).thenReturn(headerMap);
}
Expand All @@ -55,7 +55,7 @@ public void addsHeaders() {

@Test
public void doesNotAddHeadersWhenDisabled() {
when(env.getProperty("nflow.rest.cors.enabled", Boolean.class, TRUE)).thenReturn(FALSE);
when(env.getRequiredProperty("nflow.rest.cors.enabled", Boolean.class)).thenReturn(FALSE);
filter = new CorsHeaderContainerResponseFilter(env);

filter.filter(requestContext, responseContext);
Expand Down

0 comments on commit 1662f42

Please sign in to comment.