Commit 208f85db authored by Spencer Sutton's avatar Spencer Sutton
Browse files

CORS fix

commit 572cc9de 
Author: Sutton <suttonsp@147dda3a90de.ant.amazon.com> 
Date: Fri Feb 05 2021 15:49:00 GMT-0600 (Central Standard Time) 

    Incrementing to latest core lib aws


commit ae5e60f1 
Author: Sutton <suttonsp@147dda3a90de.ant.amazon.com> 
Date: Fri Feb 05 2021 14:09:34 GMT-0600 (Central Standard Time) 

    Merge branch 'dev' of codecommit::us-east-1://default@os-schema into bug/CORS


commit 3fb0110d 
Author: Sutton <suttonsp@147dda3a90de.ant.amazon.com> 
Date: Wed Feb 03 2021 16:26:13 GMT-0600 (Central Standard Time) 

    core lib update


commit e5393d79 
Author: Sutton <suttonsp@147dda3a90de.ant.amazon.com> 
Date: Wed Feb 03 2021 15:01:01 GMT-0600 (Central Standard Time) 

    Updating unit tests for cors


commit c75af3b0 
Author: Sutton <suttonsp@147dda3a90de.ant.amazon.com> 
Date: Wed Feb 03 2021 14:53:39 GMT-0600 (Central Standard Time) 

    Cors fix
parent 8122a69f
......@@ -69,7 +69,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.3.16</version>
<version>0.3.17</version>
</dependency>
<dependency>
......
......@@ -15,7 +15,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.27</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