Search in sources :

Example 16 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project jetty.project by eclipse.

the class DatabaseLoginServiceTestServer method configureServer.

protected void configureServer() throws Exception {
    _protocol = "http";
    _server.addBean(_loginService);
    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    _server.setHandler(security);
    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[] { "user", "admin" });
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);
    Set<String> knownRoles = new HashSet<>();
    knownRoles.add("user");
    knownRoles.add("admin");
    security.setConstraintMappings(Collections.singletonList(mapping), knownRoles);
    security.setAuthenticator(new BasicAuthenticator());
    security.setLoginService(_loginService);
    ServletContextHandler root = new ServletContextHandler();
    root.setContextPath("/");
    root.setResourceBase(_resourceBase);
    ServletHolder servletHolder = new ServletHolder(new DefaultServlet());
    servletHolder.setInitParameter("gzip", "true");
    root.addServlet(servletHolder, "/*");
    _handler = new TestHandler(_resourceBase);
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { _handler, root });
    security.setHandler(handlers);
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) HashSet(java.util.HashSet)

Example 17 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project camel by apache.

the class WebsocketComponent method createStaticResourcesServer.

protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {
    context.setContextPath("/");
    SessionHandler sh = new SessionHandler();
    context.setSessionHandler(sh);
    if (home != null) {
        String[] resources = home.split(":");
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
        }
        if (resources[0].equals("classpath")) {
            context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
        } else if (resources[0].equals("file")) {
            context.setBaseResource(Resource.newResource(resources[1]));
        }
        DefaultServlet defaultServlet = new DefaultServlet();
        ServletHolder holder = new ServletHolder(defaultServlet);
        // avoid file locking on windows
        // http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages
        holder.setInitParameter("useFileMappedBuffer", "false");
        context.addServlet(holder, "/");
    }
    server.setHandler(context);
    return server;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 18 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project druid by druid-io.

the class RouterJettyServerInitializer method initialize.

@Override
public void initialize(Server server, Injector injector) {
    final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    ServletHolder queryServletHolder = buildServletHolder(asyncQueryForwardingServlet, routerHttpClientConfig);
    root.addServlet(queryServletHolder, "/druid/v2/*");
    root.addServlet(queryServletHolder, "/druid/v1/lookups/*");
    if (managementProxyConfig.isEnabled()) {
        ServletHolder managementForwardingServletHolder = buildServletHolder(asyncManagementForwardingServlet, globalHttpClientConfig);
        root.addServlet(managementForwardingServletHolder, "/druid/coordinator/*");
        root.addServlet(managementForwardingServletHolder, "/druid/indexer/*");
        root.addServlet(managementForwardingServletHolder, "/proxy/*");
    }
    final ObjectMapper jsonMapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
    final AuthenticatorMapper authenticatorMapper = injector.getInstance(AuthenticatorMapper.class);
    AuthenticationUtils.addSecuritySanityCheckFilter(root, jsonMapper);
    // perform no-op authorization/authentication for these resources
    AuthenticationUtils.addNoopAuthenticationAndAuthorizationFilters(root, UNSECURED_PATHS);
    WebConsoleJettyServerInitializer.intializeServerForWebConsoleRoot(root);
    AuthenticationUtils.addNoopAuthenticationAndAuthorizationFilters(root, authConfig.getUnsecuredPaths());
    final List<Authenticator> authenticators = authenticatorMapper.getAuthenticatorChain();
    AuthenticationUtils.addAuthenticationFilterChain(root, authenticators);
    AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());
    JettyServerInitUtils.addAllowHttpMethodsFilter(root, serverConfig.getAllowedHttpMethods());
    JettyServerInitUtils.addExtensionFilters(root, injector);
    // Check that requests were authorized before sending responses
    AuthenticationUtils.addPreResponseAuthorizationCheckFilter(root, authenticators, jsonMapper);
    // Can't use '/*' here because of Guice conflicts with AsyncQueryForwardingServlet path
    root.addFilter(GuiceFilter.class, "/status/*", null);
    root.addFilter(GuiceFilter.class, "/druid/router/*", null);
    root.addFilter(GuiceFilter.class, "/druid-ext/*", null);
    final HandlerList handlerList = new HandlerList();
    handlerList.setHandlers(new Handler[] { WebConsoleJettyServerInitializer.createWebConsoleRewriteHandler(), JettyServerInitUtils.getJettyRequestLogHandler(), JettyServerInitUtils.wrapWithDefaultGzipHandler(root, serverConfig.getInflateBufferSize(), serverConfig.getCompressionLevel()) });
    server.setHandler(handlerList);
}
Also used : AuthenticatorMapper(org.apache.druid.server.security.AuthenticatorMapper) HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) Json(org.apache.druid.guice.annotations.Json) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Authenticator(org.apache.druid.server.security.Authenticator)

Example 19 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project SSM by Intel-bigdata.

the class SmartZeppelinServer method setupWebAppContext.

private WebAppContext setupWebAppContext(ContextHandlerCollection contexts) {
    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath(zconf.getServerContextPath());
    if (!isZeppelinWebEnabled()) {
        webApp.setResourceBase("");
        contexts.addHandler(webApp);
        return webApp;
    }
    File warPath = new File(zconf.getString(ConfVars.ZEPPELIN_WAR));
    // File warPath = new File("../dist/zeppelin-web-0.7.2.war");
    if (warPath.isDirectory()) {
        // Development mode, read from FS
        // webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
        webApp.setResourceBase(warPath.getPath());
        webApp.setParentLoaderPriority(true);
    } else {
        // use packaged WAR
        webApp.setWar(warPath.getAbsolutePath());
        File warTempDirectory = new File(zconf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
        warTempDirectory.mkdir();
        LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
        webApp.setTempDirectory(warTempDirectory);
    }
    // Explicit bind to root
    webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
    contexts.addHandler(webApp);
    webApp.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class));
    return webApp;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 20 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project platformlayer by platformlayer.

the class StandaloneXaasWebserver method start.

public boolean start() throws Exception {
    LogbackHook.attachToRootLogger();
    this.server = new Server();
    {
        SslContextFactory sslContextFactory = new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH);
        {
            CertificateAndKey certificateAndKey = encryptionStore.getCertificateAndKey("https");
            String secret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
            KeyStore keystore = KeyStoreUtils.createEmpty(secret);
            String alias = "https";
            KeyStoreUtils.put(keystore, alias, certificateAndKey, secret);
            sslContextFactory.setKeyStore(keystore);
            sslContextFactory.setKeyStorePassword(secret);
            sslContextFactory.setCertAlias(alias);
        }
        // TODO: Preconfigure a better SSLContext??
        SSLContext sslContext = SSLContext.getDefault();
        sslContextFactory.setIncludeCipherSuites(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledCipherSuites());
        sslContextFactory.setIncludeProtocols(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledProtocols());
        SslSelectChannelConnector connector = new SslSelectChannelConnector(sslContextFactory);
        connector.setPort(PORT);
        String host = configuration.lookup("http.host", null);
        if (host != null) {
            connector.setHost(host);
        }
        server.setConnectors(new Connector[] { connector });
    }
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    {
        ServletContextHandler context = new ServletContextHandler(contexts, "/api");
        // context.setContextPath("/");
        context.addEventListener(guiceServletConfig);
        // Must add DefaultServlet for embedded Jetty
        // Failing to do this will cause 404 errors.
        context.addServlet(DefaultServlet.class, "/");
        FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
        context.addFilter(filterHolder, "*", EnumSet.of(DispatcherType.REQUEST));
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
    }
    for (Entry<String, File> entry : wars.entrySet()) {
        String contextPath = entry.getKey();
        File war = entry.getValue();
        WebAppContext context = new WebAppContext();
        context.setWar(war.getAbsolutePath());
        context.setContextPath(contextPath);
        context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        context.addFilter(GwtCacheHeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
        contexts.addHandler(context);
    }
    server.setHandler(contexts);
    server.addLifeCycleListener(new CloseOnFailLifecycleListener());
    server.start();
    if (!server.isStarted()) {
        return false;
    }
    if (configuration.lookup("jobrunner.enabled", true)) {
        scheduler.start();
        jobPoller.start();
    }
    return true;
}
Also used : SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) GuiceFilter(com.google.inject.servlet.GuiceFilter) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) CertificateAndKey(com.fathomdb.crypto.CertificateAndKey) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Aggregations

DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)21 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)9 HandlerList (org.eclipse.jetty.server.handler.HandlerList)7 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)7 File (java.io.File)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)4 Json (org.apache.druid.guice.annotations.Json)3 Authenticator (org.apache.druid.server.security.Authenticator)3 AuthenticatorMapper (org.apache.druid.server.security.AuthenticatorMapper)3 Server (org.eclipse.jetty.server.Server)3 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)3 DispatcherType (javax.servlet.DispatcherType)2 HttpServer (org.apache.samza.coordinator.server.HttpServer)2 Handler (org.eclipse.jetty.server.Handler)2 Before (org.junit.Before)2 GroovityServletContainer (com.disney.groovity.servlet.container.GroovityServletContainer)1 GroovityServletContainerBuilder (com.disney.groovity.servlet.container.GroovityServletContainerBuilder)1 CertificateAndKey (com.fathomdb.crypto.CertificateAndKey)1