Search in sources :

Example 1 with SSLService

use of org.apache.knox.gateway.services.security.SSLService in project knox by apache.

the class GatewayServer method createConnector.

/**
 * Create a connector for Gateway Server to listen on.
 *
 * @param server       Jetty server
 * @param config       GatewayConfig
 * @param port         If value is > 0 then the given value is used else we
 *                     use the port provided in GatewayConfig.
 * @param topologyName Connector name, only used when not null
 * @return
 * @throws IOException
 * @throws CertificateException
 * @throws NoSuchAlgorithmException
 * @throws KeyStoreException
 */
private static Connector createConnector(final Server server, final GatewayConfig config, final int port, final String topologyName) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
    ServerConnector connector;
    // Determine the socket address and check availability.
    InetSocketAddress address = config.getGatewayAddress();
    checkAddressAvailability(address);
    final int connectorPort = port > 0 ? port : address.getPort();
    checkPortConflict(connectorPort, topologyName, config);
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setRequestHeaderSize(config.getHttpServerRequestHeaderBuffer());
    // httpConfig.setRequestBufferSize( config.getHttpServerRequestBuffer() );
    httpConfig.setResponseHeaderSize(config.getHttpServerResponseHeaderBuffer());
    httpConfig.setOutputBufferSize(config.getHttpServerResponseBuffer());
    if (config.isSSLEnabled()) {
        HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
        httpsConfig.setSecureScheme("https");
        httpsConfig.setSecurePort(connectorPort);
        httpsConfig.addCustomizer(new SecureRequestCustomizer());
        SSLService ssl = services.getService("SSLService");
        String keystoreFileName = config.getGatewaySecurityDir() + File.separatorChar + "keystores" + File.separatorChar + "gateway.jks";
        SslContextFactory sslContextFactory = (SslContextFactory) ssl.buildSslContextFactory(keystoreFileName);
        connector = new ServerConnector(server, sslContextFactory, new HttpConnectionFactory(httpsConfig));
    } else {
        connector = new ServerConnector(server);
    }
    connector.setHost(address.getHostName());
    connector.setPort(connectorPort);
    if (!StringUtils.isBlank(topologyName)) {
        connector.setName(topologyName);
    }
    long idleTimeout = config.getGatewayIdleTimeout();
    if (idleTimeout > 0l) {
        connector.setIdleTimeout(idleTimeout);
    }
    return connector;
}
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) InetSocketAddress(java.net.InetSocketAddress) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SSLService(org.apache.knox.gateway.services.security.SSLService)

Example 2 with SSLService

use of org.apache.knox.gateway.services.security.SSLService in project knox by apache.

the class DefaultGatewayServices method start.

public void start() throws ServiceLifecycleException {
    ms.start();
    ks.start();
    DefaultAliasService alias = (DefaultAliasService) services.get(ALIAS_SERVICE);
    alias.start();
    SSLService ssl = (SSLService) services.get(SSL_SERVICE);
    ssl.start();
    ServerInfoService sis = (ServerInfoService) services.get(SERVER_INFO_SERVICE);
    sis.start();
    RemoteConfigurationRegistryClientService clientService = (RemoteConfigurationRegistryClientService) services.get(REMOTE_REGISTRY_CLIENT_SERVICE);
    clientService.start();
    (services.get(CLUSTER_CONFIGURATION_MONITOR_SERVICE)).start();
    DefaultTopologyService tops = (DefaultTopologyService) services.get(TOPOLOGY_SERVICE);
    tops.start();
    DefaultMetricsService metricsService = (DefaultMetricsService) services.get(METRICS_SERVICE);
    metricsService.start();
}
Also used : DefaultAliasService(org.apache.knox.gateway.services.security.impl.DefaultAliasService) DefaultTopologyService(org.apache.knox.gateway.services.topology.impl.DefaultTopologyService) DefaultMetricsService(org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) JettySSLService(org.apache.knox.gateway.services.security.impl.JettySSLService) SSLService(org.apache.knox.gateway.services.security.SSLService)

Example 3 with SSLService

use of org.apache.knox.gateway.services.security.SSLService in project knox by apache.

the class DefaultGatewayServices method stop.

public void stop() throws ServiceLifecycleException {
    ms.stop();
    ks.stop();
    (services.get(CLUSTER_CONFIGURATION_MONITOR_SERVICE)).stop();
    DefaultAliasService alias = (DefaultAliasService) services.get(ALIAS_SERVICE);
    alias.stop();
    SSLService ssl = (SSLService) services.get(SSL_SERVICE);
    ssl.stop();
    ServerInfoService sis = (ServerInfoService) services.get(SERVER_INFO_SERVICE);
    sis.stop();
    DefaultTopologyService tops = (DefaultTopologyService) services.get(TOPOLOGY_SERVICE);
    tops.stop();
    DefaultMetricsService metricsService = (DefaultMetricsService) services.get(METRICS_SERVICE);
    metricsService.stop();
}
Also used : DefaultAliasService(org.apache.knox.gateway.services.security.impl.DefaultAliasService) DefaultTopologyService(org.apache.knox.gateway.services.topology.impl.DefaultTopologyService) DefaultMetricsService(org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService) JettySSLService(org.apache.knox.gateway.services.security.impl.JettySSLService) SSLService(org.apache.knox.gateway.services.security.SSLService)

Aggregations

SSLService (org.apache.knox.gateway.services.security.SSLService)3 DefaultMetricsService (org.apache.knox.gateway.services.metrics.impl.DefaultMetricsService)2 DefaultAliasService (org.apache.knox.gateway.services.security.impl.DefaultAliasService)2 JettySSLService (org.apache.knox.gateway.services.security.impl.JettySSLService)2 DefaultTopologyService (org.apache.knox.gateway.services.topology.impl.DefaultTopologyService)2 InetSocketAddress (java.net.InetSocketAddress)1 RemoteConfigurationRegistryClientService (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1