/** * Add an internal servlet in the server, specifying whether or not to * protect with Kerberos authentication. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For + * servlets added using this method, filters (except internal Kerberos * filters) are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @param requireAuth Require Kerberos authenticate to access servlet */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); if(requireAuth && UserGroupInformation.isSecurityEnabled()) { LOG.info("Adding Kerberos (SPNEGO) filter to " + name); ServletHandler handler = webAppContext.getServletHandler(); FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(SPNEGO_FILTER); fmap.setDispatches(FilterMapping.ALL); handler.addFilterMapping(fmap); } }
/** * Define a filter for a context and set up default url mappings. */ public static void defineFilter(ServletContextHandler handler, String name, String classname, Map<String,String> parameters, String[] urls) { FilterHolder holder = new FilterHolder(); holder.setName(name); holder.setClassName(classname); if (parameters != null) { holder.setInitParameters(parameters); } FilterMapping fmap = new FilterMapping(); fmap.setPathSpecs(urls); fmap.setDispatches(FilterMapping.ALL); fmap.setFilterName(name); handler.getServletHandler().addFilter(holder, fmap); }
/** * Add the path spec to the filter path mapping. * @param pathSpec The path spec * @param webAppCtx The WebApplicationContext to add to */ protected void addFilterPathMapping(String pathSpec, WebAppContext webAppCtx) { for(String name : filterNames) { FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(name); fmap.setDispatches(FilterMapping.ALL); webAppCtx.getServletHandler().addFilterMapping(fmap); } }
private void createServer() throws MalformedURLException { server = new Server(port); if (Boolean.parseBoolean(Config.getBlurConfig().get("blur.console.ssl.enable", "false"))) { SslContextFactory factory = new SslContextFactory(Boolean.parseBoolean(Config.getBlurConfig().get("blur.console.ssl.hostname.match", "true"))); factory.setKeyStorePath(Config.getBlurConfig().get("blur.console.ssl.keystore.path")); factory.setKeyStorePassword(Config.getBlurConfig().get("blur.console.ssl.keystore.password")); factory.setTrustStore(Config.getBlurConfig().get("blur.console.ssl.truststore.path")); factory.setTrustStorePassword(Config.getBlurConfig().get("blur.console.ssl.truststore.password")); SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(factory); sslConnector.setPort(port); server.addConnector(sslConnector); } // for localhost:port/console/index.html and whatever else is in the webapp directory URL warUrl = null; if (devMode) { warUrl = new URL("file://" + new File(DEV_WEBAPPDIR).getAbsolutePath()); } else { warUrl = this.getClass().getClassLoader().getResource(PROD_WEBAPPDIR); } String warUrlString = warUrl.toExternalForm(); WebAppContext staticContext = new WebAppContext(warUrlString, CONTEXTPATH); staticContext.setSessionHandler(new SessionHandler()); // service calls // ContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); // servletContext.setContextPath("/console/service"); ServletHandler serviceHandler = new ServletHandler(); serviceHandler.addServletWithMapping(AuthServlet.class, "/service/auth/*"); serviceHandler.addServletWithMapping(NodesServlet.class, "/service/nodes/*"); serviceHandler.addServletWithMapping(TablesServlet.class, "/service/tables/*"); serviceHandler.addServletWithMapping(QueriesServlet.class, "/service/queries/*"); serviceHandler.addServletWithMapping(SearchServlet.class, "/service/search/*"); serviceHandler.addServletWithMapping(JavascriptServlet.class, "/service/config.js"); serviceHandler.addFilterWithMapping(LoggedInFilter.class, "/service/*", FilterMapping.REQUEST); // servletContext.setHandler(serviceHandler); staticContext.setServletHandler(serviceHandler); // ContextHandlerCollection handlers = new ContextHandlerCollection(); // handlers.setHandlers(new Handler[] { /*servletContext,*/ staticContext }); server.setHandler(staticContext); System.out.println("started server on http://localhost:" + port + CONTEXTPATH); try { server.start(); System.out.println(server.getHandlers()[0]); } catch (Exception e) { log.error("Error starting Blur Console Jetty Server. Exiting", e); System.exit(1); } }