Search in sources :

Example 71 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project oozie by apache.

the class SSLServerConnectorFactory method getHttpsConfiguration.

private HttpConfiguration getHttpsConfiguration() {
    HttpConfiguration https = new HttpConfigurationWrapper(conf).getDefaultHttpConfiguration();
    https.setSecureScheme("https");
    https.addCustomizer(new SecureRequestCustomizer());
    return https;
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 72 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project wicket by apache.

the class StartJavaScriptTests method main.

/**
 * Main function, starts the jetty server.
 *
 * @param args
 */
public static void main(String[] args) {
    System.setProperty("wicket.configuration", "development");
    Server server = new Server();
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
    http.setPort(8080);
    http.setIdleTimeout(1000 * 60 * 60);
    server.addConnector(http);
    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
        // if a keystore for a SSL certificate is available, start a SSL
        // connector on port 8443.
        // By default, the quickstart comes with a Apache Wicket Quickstart
        // Certificate that expires about half way september 2021. Do not
        // use this certificate anywhere important as the passwords are
        // available in the source.
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStoreResource(keystore);
        sslContextFactory.setKeyStorePassword("wicket");
        sslContextFactory.setKeyManagerPassword("wicket");
        HttpConfiguration https_config = new HttpConfiguration(http_config);
        https_config.addCustomizer(new SecureRequestCustomizer());
        ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
        https.setPort(8443);
        https.setIdleTimeout(500000);
        server.addConnector(https);
        System.out.println("SSL access to the examples has been enabled on port 8443");
        System.out.println("You can access the application using SSL on https://localhost:8443");
        System.out.println();
    }
    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/ajax-tests");
    bb.setWar("../../wicket-core/src");
    // uncomment next line if you want to test with JSESSIONID encoded in the urls
    // ((AbstractSessionManager)
    // bb.getSessionHandler().getSessionManager()).setUsingCookies(false);
    server.setHandler(bb);
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    server.addEventListener(mBeanContainer);
    server.addBean(mBeanContainer);
    try {
        server.start();
        browse();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Resource(org.eclipse.jetty.util.resource.Resource) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) MBeanServer(javax.management.MBeanServer)

Example 73 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project cia by Hack23.

the class CitizenIntelligenceAgencyServer method init.

/**
 * Inits the.
 *
 * @throws Exception
 *             the exception
 */
public final void init() throws Exception {
    initialised = true;
    server = new Server();
    Security.addProvider(new BouncyCastleProvider());
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // Enable parsing of jndi-related parts of web.xml and jetty-env.xml
    final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    final HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(28443);
    final HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStorePath("target/keystore.jks");
    sslContextFactory.setTrustStorePath("target/keystore.jks");
    sslContextFactory.setKeyStorePassword("changeit");
    sslContextFactory.setTrustStorePassword("changeit");
    sslContextFactory.setKeyManagerPassword("changeit");
    sslContextFactory.setCertAlias("jetty");
    sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
    sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
    sslContextFactory.setIncludeProtocols("TLSv1.2");
    final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
    sslConnector.setPort(PORT);
    server.setConnectors(new ServerConnector[] { sslConnector });
    final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
    handler.setExtraClasspath("target/classes");
    handler.setParentLoaderPriority(true);
    handler.setConfigurationDiscovered(true);
    handler.setClassLoader(Thread.currentThread().getContextClassLoader());
    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    server.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 74 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project winstone by jenkinsci.

the class Http2ConnectorFactory method start.

@Override
public boolean start(Map args, Server server) throws IOException {
    int listenPort = Option.HTTP2_PORT.get(args);
    String listenAddress = Option.HTTP2_LISTEN_ADDRESS.get(args);
    if (listenPort < 0) {
        // not running HTTP2 listener
        return false;
    }
    try {
        configureSsl(args, server);
        SslContextFactory sslContextFactory = getSSLContext(args);
        sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
        // HTTPS Configuration
        HttpConfiguration https_config = new HttpConfiguration();
        https_config.setSecureScheme("https");
        https_config.setSecurePort(listenPort);
        https_config.addCustomizer(new SecureRequestCustomizer());
        // HTTP/2 Connection Factory
        HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
        ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
        alpn.setDefaultProtocol("h2");
        // SSL Connection Factory
        SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
        // HTTP/2 Connector
        ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
        http2Connector.setPort(listenPort);
        http2Connector.setHost(listenAddress);
        server.addConnector(http2Connector);
        server.setDumpAfterStart(Boolean.getBoolean("dumpAfterStart"));
        ALPN.debug = Boolean.getBoolean("alpnDebug");
        return true;
    } catch (IllegalStateException e) {
        Logger.log(Logger.WARNING, Launcher.RESOURCES, "Http2ConnectorFactory.FailedStart.ALPN", e);
    }
    return false;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 75 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project nifi-minifi by apache.

the class JettyServer method main.

public static void main(String[] args) throws Exception {
    C2Properties properties = C2Properties.getInstance();
    final HandlerCollection handlers = new HandlerCollection();
    for (Path path : Files.list(Paths.get(C2_SERVER_HOME, "webapps")).collect(Collectors.toList())) {
        handlers.addHandler(loadWar(path.toFile(), "/c2", JettyServer.class.getClassLoader()));
    }
    Server server;
    int port = Integer.parseInt(properties.getProperty("minifi.c2.server.port", "10080"));
    if (properties.isSecure()) {
        SslContextFactory sslContextFactory = properties.getSslContextFactory();
        HttpConfiguration config = new HttpConfiguration();
        config.setSecureScheme("https");
        config.setSecurePort(port);
        config.addCustomizer(new SecureRequestCustomizer());
        server = new Server();
        ServerConnector serverConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config));
        serverConnector.setPort(port);
        server.addConnector(serverConnector);
    } else {
        server = new Server(port);
    }
    server.setHandler(handlers);
    server.start();
    // ensure everything started successfully
    for (Handler handler : server.getChildHandlers()) {
        // see if the handler is a web app
        if (handler instanceof WebAppContext) {
            WebAppContext context = (WebAppContext) handler;
            // cause it to be unavailable
            if (context.getUnavailableException() != null) {
                System.err.println("Failed to start web server: " + context.getUnavailableException().getMessage());
                System.err.println("Shutting down...");
                logger.warn("Failed to start web server... shutting down.", context.getUnavailableException());
                server.stop();
                System.exit(1);
            }
        }
    }
    server.dumpStdErr();
    server.join();
}
Also used : Path(java.nio.file.Path) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Handler(org.eclipse.jetty.server.Handler) C2Properties(org.apache.nifi.minifi.c2.api.properties.C2Properties) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Aggregations

SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)91 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)89 ServerConnector (org.eclipse.jetty.server.ServerConnector)87 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)85 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)82 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)74 Server (org.eclipse.jetty.server.Server)50 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)16 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)16 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)13 File (java.io.File)12 IOException (java.io.IOException)12 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)10 Connector (org.eclipse.jetty.server.Connector)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10 ServletException (javax.servlet.ServletException)9 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)8 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)8 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6