You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by bh...@apache.org on 2019/09/16 11:03:29 UTC

[incubator-dlab] branch develop updated: DLAB-000 enabling CORS for dev mode

This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new b663f2b  DLAB-000 enabling CORS for dev mode
b663f2b is described below

commit b663f2b1021fc3db095194b350ba87e1ab4b4e13
Author: bhliva <bo...@epam.com>
AuthorDate: Mon Sep 16 14:03:09 2019 +0300

    DLAB-000 enabling CORS for dev mode
---
 .../com/epam/dlab/backendapi/modules/DevModule.java   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/modules/DevModule.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/modules/DevModule.java
index dc24362..02117ab 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/modules/DevModule.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/modules/DevModule.java
@@ -37,9 +37,13 @@ import com.epam.dlab.rest.dto.ErrorDTO;
 import com.google.inject.name.Names;
 import io.dropwizard.auth.Authorizer;
 import io.dropwizard.setup.Environment;
+import org.eclipse.jetty.servlets.CrossOriginFilter;
 
+import javax.servlet.DispatcherType;
+import javax.servlet.FilterRegistration;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import java.util.EnumSet;
 import java.util.Optional;
 
 /**
@@ -64,6 +68,7 @@ public class DevModule extends ModuleBase<SelfServiceApplicationConfiguration> i
 
 	@Override
 	protected void configure() {
+		configureCors(environment);
 		bind(SelfServiceApplicationConfiguration.class).toInstance(configuration);
 		bind(MongoService.class).toInstance(configuration.getMongoFactory().build(environment));
 		bind(RESTService.class).annotatedWith(Names.named(ServiceConsts.SECURITY_SERVICE_NAME))
@@ -127,6 +132,20 @@ public class DevModule extends ModuleBase<SelfServiceApplicationConfiguration> i
 		return userInfo;
 	}
 
+	private void configureCors(Environment environment) {
+		final FilterRegistration.Dynamic cors =
+				environment.servlets().addFilter("CORS", CrossOriginFilter.class);
+
+		cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
+		cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin," +
+				"Authorization");
+		cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "OPTIONS,GET,PUT,POST,DELETE,HEAD");
+		cors.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "true");
+
+		cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
+
+	}
+
 	/**
 	 * Creates and returns the mock object for authentication service.
 	 */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org