Search in sources :

Example 6 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project qi4j-sdk by Qi4j.

the class SecureJettyMixin method specializeHttp.

@Override
protected HttpConfiguration specializeHttp(HttpConfiguration httpConfig) {
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    return httpsConfig;
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 7 with SecureRequestCustomizer

use of org.eclipse.jetty.server.SecureRequestCustomizer in project jersey by jersey.

the class JettyHttpContainerFactory method createServer.

/**
     * Create a {@link Server} that registers an {@link org.eclipse.jetty.server.Handler} that
     * in turn manages all root resource and provider classes found by searching the
     * classes referenced in the java classpath.
     *
     * @param uri               the URI to create the http server. The URI scheme must be
     *                          equal to {@code https}. The URI user information and host
     *                          are ignored. If the URI port is not present then port
     *                          {@value org.glassfish.jersey.server.spi.Container#DEFAULT_HTTPS_PORT} will be
     *                          used. The URI path, query and fragment components are ignored.
     * @param sslContextFactory this is the SSL context factory used to configure SSL connector
     * @param handler           the container that handles all HTTP requests
     * @param start             if set to false, server will not get started, this allows end users to set
     *                          additional properties on the underlying listener.
     * @return newly created {@link Server}.
     *
     * @throws ProcessingException      in case of any failure when creating a new Jetty {@code Server} instance.
     * @throws IllegalArgumentException if {@code uri} is {@code null}.
     * @see JettyHttpContainer
     */
public static Server createServer(final URI uri, final SslContextFactory sslContextFactory, final JettyHttpContainer handler, final boolean start) {
    if (uri == null) {
        throw new IllegalArgumentException(LocalizationMessages.URI_CANNOT_BE_NULL());
    }
    final String scheme = uri.getScheme();
    int defaultPort = Container.DEFAULT_HTTP_PORT;
    if (sslContextFactory == null) {
        if (!"http".equalsIgnoreCase(scheme)) {
            throw new IllegalArgumentException(LocalizationMessages.WRONG_SCHEME_WHEN_USING_HTTP());
        }
    } else {
        if (!"https".equalsIgnoreCase(scheme)) {
            throw new IllegalArgumentException(LocalizationMessages.WRONG_SCHEME_WHEN_USING_HTTPS());
        }
        defaultPort = Container.DEFAULT_HTTPS_PORT;
    }
    final int port = (uri.getPort() == -1) ? defaultPort : uri.getPort();
    final Server server = new Server(new JettyConnectorThreadPool());
    final HttpConfiguration config = new HttpConfiguration();
    if (sslContextFactory != null) {
        config.setSecureScheme("https");
        config.setSecurePort(port);
        config.addCustomizer(new SecureRequestCustomizer());
        final ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config));
        https.setPort(port);
        server.setConnectors(new Connector[] { https });
    } else {
        final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config));
        http.setPort(port);
        server.setConnectors(new Connector[] { http });
    }
    if (handler != null) {
        server.setHandler(handler);
    }
    if (start) {
        try {
            // Start the server.
            server.start();
        } catch (final Exception e) {
            throw new ProcessingException(LocalizationMessages.ERROR_WHEN_CREATING_SERVER(), e);
        }
    }
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Example 8 with SecureRequestCustomizer

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

the class TestJettyHelper method createJettyServer.

private Server createJettyServer() {
    try {
        InetAddress localhost = InetAddress.getByName("localhost");
        String host = "localhost";
        ServerSocket ss = new ServerSocket(0, 50, localhost);
        int port = ss.getLocalPort();
        ss.close();
        Server server = new Server();
        ServerConnector conn = new ServerConnector(server);
        HttpConfiguration http_config = new HttpConfiguration();
        http_config.setRequestHeaderSize(JettyUtils.HEADER_SIZE);
        http_config.setResponseHeaderSize(JettyUtils.HEADER_SIZE);
        http_config.setSecureScheme("https");
        http_config.addCustomizer(new SecureRequestCustomizer());
        ConnectionFactory connFactory = new HttpConnectionFactory(http_config);
        conn.addConnectionFactory(connFactory);
        conn.setHost(host);
        conn.setPort(port);
        if (ssl) {
            SslContextFactory sslContextFactory = new SslContextFactory();
            sslContextFactory.setNeedClientAuth(false);
            sslContextFactory.setKeyStorePath(keyStore);
            sslContextFactory.setKeyStoreType(keyStoreType);
            sslContextFactory.setKeyStorePassword(keyStorePassword);
            conn.addFirstConnectionFactory(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()));
        }
        server.addConnector(conn);
        return server;
    } catch (Exception ex) {
        throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex);
    }
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServerSocket(java.net.ServerSocket) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) InetAddress(java.net.InetAddress)

Example 9 with SecureRequestCustomizer

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

the class JettyServer method createUnconfiguredSslServerConnector.

private ServerConnector createUnconfiguredSslServerConnector(Server server, HttpConfiguration httpConfiguration) {
    // add some secure config
    final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
    httpsConfiguration.setSecureScheme("https");
    httpsConfiguration.setSecurePort(props.getSslPort());
    httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
    // build the connector
    return new ServerConnector(server, new SslConnectionFactory(createSslContextFactory(), "http/1.1"), new HttpConnectionFactory(httpsConfiguration));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 10 with SecureRequestCustomizer

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

the class JettyWebSocketServer method createConnector.

private ServerConnector createConnector(final SslContextFactory sslContextFactory, final Integer listenPort) {
    final ServerConnector serverConnector;
    if (sslContextFactory == null) {
        serverConnector = new ServerConnector(server);
    } else {
        final HttpConfiguration httpsConfiguration = new HttpConfiguration();
        httpsConfiguration.setSecureScheme("https");
        httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
        serverConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfiguration));
    }
    serverConnector.setPort(listenPort);
    return serverConnector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

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