Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CORS filter added, to support alternate gui #3819

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion opal-core/src/main/resources/META-INF/defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ apps.discovery.interval = 10000

# CSRF
# allowed referers, comma separated <host:port>
csrf.allowed=
csrf.allowed=

# CORS
# use * as wildcard, separate origins with commas
cors.allowed=
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.security.Constraint;
Expand Down Expand Up @@ -240,6 +241,17 @@ private void initEventListeners() {
private void initFilters(Properties properties) {
servletContextHandler.addFilter(OpalVersionFilter.class, "/*", EnumSet.of(REQUEST));

// Add the CrossOriginFilter
String corsAllowed = properties.getProperty("cors.allowed");
if (!Strings.isNullOrEmpty(corsAllowed)) {
FilterHolder cors = servletContextHandler.addFilter(CrossOriginFilter.class, "/*", EnumSet.of(REQUEST));
cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, corsAllowed);
cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "Content-Type,Access-Control-Allow-Origin");
cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,POST,PUT,DELETE,OPTIONS");
cors.setInitParameter(CrossOriginFilter.EXPOSED_HEADERS_PARAM, "X-Opal-Version,Location,X-TOTP");
cors.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "true");
}

initOIDCFilter(properties);

FilterHolder authenticationFilterHolder = new FilterHolder(DelegatingFilterProxy.class);
Expand Down