private void addDispatcherContext(ServletContext container) { // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(SpringDispatcherConfig.class); // Declare <servlet> and <servlet-mapping> for the DispatcherServlet ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet", new DispatcherServlet(dispatcherContext)); dispatcher.addMapping("*.html"); dispatcher.setLoadOnStartup(1); FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter()); corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE"); corsFilter.addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter()); filter.addMappingForServletNames(null, true, "/*"); FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter()); multipartFilter.addMappingForUrlPatterns(null, true, "/*"); }
@Override protected void configureServlets() { getServletContext().addListener(new org.everrest.websockets.WSConnectionTracker()); final Map<String, String> corsFilterParams = new HashMap<>(); corsFilterParams.put("cors.allowed.origins", "*"); corsFilterParams.put( "cors.allowed.methods", "GET," + "POST," + "HEAD," + "OPTIONS," + "PUT," + "DELETE"); corsFilterParams.put( "cors.allowed.headers", "Content-Type," + "X-Requested-With," + "accept," + "Origin," + "Access-Control-Request-Method," + "Access-Control-Request-Headers"); corsFilterParams.put("cors.support.credentials", "true"); // preflight cache is available for 10 minutes corsFilterParams.put("cors.preflight.maxage", "10"); bind(CorsFilter.class).in(Singleton.class); filter("/*").through(CorsFilter.class, corsFilterParams); filter("/*").through(RequestIdLoggerFilter.class); serveRegex("^/(?!ws$|ws/|websocket.?)(.*)").with(GuiceEverrestServlet.class); install(new org.eclipse.che.swagger.deploy.BasicSwaggerConfigurationModule()); if (Boolean.valueOf(System.getenv("CHE_MULTIUSER"))) { configureMultiUserMode(); } else { configureSingleUserMode(); } }
@Override protected void configureServlets() { filter(pathForLoginFilter).through(com.codenvy.auth.sso.client.LoginFilter.class); // comma separated list of paths like "/service1,/service2" bindConstant().annotatedWith(Names.named("csrf_filter.paths_accepting_parameters")).to("/ssh"); filter(pathForLoginFilter).through(CodenvyCsrfFilter.class); final Map<String, String> corsFilterParams = new HashMap<>(); corsFilterParams.put("cors.allowed.origins", DEFAULT_ALLOWED_ORIGINS); corsFilterParams.put( "cors.allowed.methods", "GET," + "POST," + "HEAD," + "OPTIONS," + "PUT," + "DELETE"); corsFilterParams.put( "cors.allowed.headers", "Content-Type," + "X-Requested-With," + "accept," + "Origin," + "Access-Control-Request-Method," + "Access-Control-Request-Headers"); corsFilterParams.put("cors.support.credentials", "true"); // preflight cache is available for 10 minutes corsFilterParams.put("cors.preflight.maxage", "10"); bind(CorsFilter.class).in(Singleton.class); filter("/*").through(CorsFilter.class, corsFilterParams); bind(com.codahale.metrics.servlets.ThreadDumpServlet.class).in(Singleton.class); bind(com.codahale.metrics.servlets.PingServlet.class).in(Singleton.class); serve("/metrics/ping").with(com.codahale.metrics.servlets.PingServlet.class); serve("/metrics/threaddump").with(com.codahale.metrics.servlets.ThreadDumpServlet.class); serve("/oauth").with(com.codenvy.auth.sso.oauth.OAuthLoginServlet.class); filter("/oauth").through(com.codenvy.auth.sso.oauth.OauthLoginFilter.class); install(new com.codenvy.auth.sso.client.deploy.SsoClientServletModule()); serveRegex("^((?!(\\/(ws|eventbus|websocket)($|\\/.*)))\\/.*)") .with(org.everrest.guice.servlet.GuiceEverrestServlet.class); getServletContext().addListener(new WSConnectionTracker()); install(new com.codenvy.auth.sso.client.deploy.SsoClientServletModule()); install(new BasicSwaggerConfigurationModule()); }
@Override public void init(FilterConfig filterConfig) throws ServletException { corsFilter = new CorsFilter(); corsFilter.init(new CheCorsFilterConfig()); }
public CorsValve() throws ServletException { super(new CorsFilter()); }