From 6c8f95c5bec95b35ac806df026335a7493ba271d Mon Sep 17 00:00:00 2001 From: Martin Lowe <martin.lowe@eclipse-foundation.org> Date: Mon, 30 Nov 2020 09:48:32 -0500 Subject: [PATCH] Updated CORS filter to explicitly allow all filters (#16) * Updated CORS filter to explicitly allow all filters Signed-off-by: Martin Lowe <martin.lowe@eclipse-foundation.org> * Add explicit CORS header filter (baked in not working as intended) Signed-off-by: Martin Lowe <martin.lowe@eclipse-foundation.org> --- .../adopters/response/CORSFilter.java | 34 +++++++++++++++++++ src/main/resources/application.properties | 4 +++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/org/eclipsefoundation/adopters/response/CORSFilter.java diff --git a/src/main/java/org/eclipsefoundation/adopters/response/CORSFilter.java b/src/main/java/org/eclipsefoundation/adopters/response/CORSFilter.java new file mode 100644 index 0000000..b691ef3 --- /dev/null +++ b/src/main/java/org/eclipsefoundation/adopters/response/CORSFilter.java @@ -0,0 +1,34 @@ +/** + * ***************************************************************************** Copyright (C) 2020 + * Eclipse Foundation + * + * <p>This program and the accompanying materials are made available under the terms of the Eclipse + * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * <p>SPDX-License-Identifier: EPL-2.0 + * **************************************************************************** + */ +package org.eclipsefoundation.adopters.response; + +import java.io.IOException; +import java.util.Arrays; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.ext.Provider; + +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@Provider +public class CORSFilter implements ContainerResponseFilter { + @ConfigProperty(name = "quarkus.http.cors.exposed-headers") + String exposedHeaders; + + @Override + public void filter( + ContainerRequestContext requestContext, ContainerResponseContext responseContext) + throws IOException { + responseContext.getHeaders().put("Access-Control-Expose-Headers", Arrays.asList(exposedHeaders)); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a251389..7626e02 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,10 @@ org.eclipsefoundation.adopters.api.ProjectsAPI/mp-rest/url=https://projects.ecli quarkus.http.port=8080 quarkus.http.root-path=/adopters +## CORS settings +quarkus.http.cors=true +quarkus.http.cors.exposed-headers=Etag,Link,Content-Type + ## Adopters raw location eclipse.adopters.path.json=/config/adopters.json %dev.eclipse.adopters.path.json=/tmp/config/adopters.json \ No newline at end of file -- GitLab