Commit b17ef0a0 authored by Spencer Sutton's avatar Spencer Sutton
Browse files

Merge branch 'aws-integration-only' into 'master'

CORS Fix Update

See merge request !89
parents 573edb63 7c887764
Pipeline #30634 passed with stages
in 30 minutes
......@@ -30,7 +30,7 @@
<properties>
<osdu.corelibazure.version>0.0.40</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.3.18</osdu.oscorecommon.version>
<osdu.oscorecommon.version>0.3.28</osdu.oscorecommon.version>
<osdu.os-schema-core.version>0.6.0-SNAPSHOT</osdu.os-schema-core.version>
<mockito.version>1.10.19</mockito.version>
<cucumber.version>5.4.0</cucumber.version>
......@@ -45,6 +45,12 @@
<version>${osdu.corelibazure.version}</version>
<type>pom</type>
<scope>import</scope>
<exclusions>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -63,14 +69,14 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>${osdu.corelibazure.version}</version>
<artifactId>os-core-common</artifactId>
<version>${osdu.oscorecommon.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>${osdu.oscorecommon.version}</version>
<artifactId>core-lib-azure</artifactId>
<version>${osdu.corelibazure.version}</version>
</dependency>
<dependency>
......
......@@ -13,7 +13,7 @@
<properties>
<springfox-version>2.7.0</springfox-version>
<os-core-common.version>0.3.23</os-core-common.version>
<os-core-common.version>0.3.28</os-core-common.version>
</properties>
<dependencies>
......
......@@ -27,9 +27,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.http.ResponseHeaders;
import org.opengroup.osdu.core.common.http.ResponseHeadersFactory;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
......@@ -40,6 +41,12 @@ public class ResponseHeaderFIlter implements Filter {
@Autowired
private DpsHeaders dpsHeaders;
// defaults to * for any front-end, string must be comma-delimited if more than one domain
@Value("${ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS:*}")
String ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS;
private ResponseHeadersFactory responseHeadersFactory = new ResponseHeadersFactory();
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
......@@ -49,8 +56,8 @@ public class ResponseHeaderFIlter implements Filter {
HttpServletResponse httpResponse = (HttpServletResponse) response;
this.dpsHeaders.addCorrelationIdIfMissing();
Map<String, List<Object>> standardHeaders = ResponseHeaders.STANDARD_RESPONSE_HEADERS;
for (Map.Entry<String, List<Object>> header : standardHeaders.entrySet()) {
Map<String, String> responseHeaders = responseHeadersFactory.getResponseHeaders(ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS);
for(Map.Entry<String, String> header : responseHeaders.entrySet()){
httpResponse.addHeader(header.getKey(), header.getValue().toString());
}
httpResponse.addHeader(DpsHeaders.CORRELATION_ID, this.dpsHeaders.getCorrelationId());
......
......@@ -39,6 +39,7 @@ public class ResponseHeaderFilterTest {
public void test_ResponseHeaderFiler_Options() throws IOException, ServletException {
Mockito.when(httpServletRequest.getMethod()).thenReturn("OPTIONS");
org.springframework.test.util.ReflectionTestUtils.setField(responseHeaderFIlter, "ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS", "custom-domain");
responseHeaderFIlter.doFilter(httpServletRequest, httpServletResponse, chain);
assertNotNull(httpServletResponse);
responseHeaderFIlter.destroy();
......@@ -49,6 +50,7 @@ public class ResponseHeaderFilterTest {
public void test_ResponseHeaderFiler_Get() throws IOException, ServletException {
Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
org.springframework.test.util.ReflectionTestUtils.setField(responseHeaderFIlter, "ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS", "custom-domain");
responseHeaderFIlter.doFilter(httpServletRequest, httpServletResponse, chain);
assertNotNull(httpServletResponse);
responseHeaderFIlter.destroy();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment