Search in sources :

Example 51 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class TestPutSolrContentStream method testHttpsUrlShouldRequireSSLContext.

@Test
public void testHttpsUrlShouldRequireSSLContext() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(PutSolrContentStream.class);
    runner.setProperty(SolrUtils.SOLR_TYPE, SolrUtils.SOLR_TYPE_STANDARD.getValue());
    runner.setProperty(SolrUtils.SOLR_LOCATION, "https://localhost:8443/solr");
    runner.assertNotValid();
    final SSLContextService sslContextService = new MockSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.enableControllerService(sslContextService);
    runner.setProperty(SolrUtils.SSL_CONTEXT_SERVICE, "ssl-context");
    runner.assertValid();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) SSLContextService(org.apache.nifi.ssl.SSLContextService) Test(org.junit.Test)

Example 52 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class TestPutSolrContentStream method testHttpUrlShouldNotAllowSSLContext.

@Test
public void testHttpUrlShouldNotAllowSSLContext() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(PutSolrContentStream.class);
    runner.setProperty(SolrUtils.SOLR_TYPE, SolrUtils.SOLR_TYPE_STANDARD.getValue());
    runner.setProperty(SolrUtils.SOLR_LOCATION, "http://localhost:8443/solr");
    runner.assertValid();
    final SSLContextService sslContextService = new MockSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.enableControllerService(sslContextService);
    runner.setProperty(SolrUtils.SSL_CONTEXT_SERVICE, "ssl-context");
    runner.assertNotValid();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) SSLContextService(org.apache.nifi.ssl.SSLContextService) Test(org.junit.Test)

Example 53 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class LivySessionController method onConfigured.

@OnEnabled
public void onConfigured(final ConfigurationContext context) {
    ComponentLog log = getLogger();
    final String livyHost = context.getProperty(LIVY_HOST).evaluateAttributeExpressions().getValue();
    final String livyPort = context.getProperty(LIVY_PORT).evaluateAttributeExpressions().getValue();
    final String sessionPoolSize = context.getProperty(SESSION_POOL_SIZE).evaluateAttributeExpressions().getValue();
    final String sessionKind = context.getProperty(SESSION_TYPE).getValue();
    final long sessionManagerStatusInterval = context.getProperty(SESSION_MGR_STATUS_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    final String jars = context.getProperty(JARS).evaluateAttributeExpressions().getValue();
    final String files = context.getProperty(FILES).evaluateAttributeExpressions().getValue();
    sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    sslContext = sslContextService == null ? null : sslContextService.createSSLContext(SSLContextService.ClientAuth.NONE);
    connectTimeout = Math.toIntExact(context.getProperty(CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS));
    this.livyUrl = "http" + (sslContextService != null ? "s" : "") + "://" + livyHost + ":" + livyPort;
    this.controllerKind = sessionKind;
    this.jars = jars;
    this.files = files;
    this.sessionPoolSize = Integer.valueOf(sessionPoolSize);
    this.enabled = true;
    livySessionManagerThread = new Thread(() -> {
        while (enabled) {
            try {
                manageSessions();
                Thread.sleep(sessionManagerStatusInterval);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                enabled = false;
            } catch (IOException ioe) {
                throw new ProcessException(ioe);
            }
        }
    });
    livySessionManagerThread.setName("Livy-Session-Manager-" + controllerKind);
    livySessionManagerThread.start();
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) SSLContextService(org.apache.nifi.ssl.SSLContextService) IOException(java.io.IOException) ComponentLog(org.apache.nifi.logging.ComponentLog) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 54 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class AbstractSiteToSiteReportingTask method setup.

@OnScheduled
public void setup(final ConfigurationContext context) throws IOException {
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT).asControllerService(SSLContextService.class);
    final SSLContext sslContext = sslContextService == null ? null : sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    final ComponentLog logger = getLogger();
    final EventReporter eventReporter = new EventReporter() {

        @Override
        public void reportEvent(final Severity severity, final String category, final String message) {
            switch(severity) {
                case WARNING:
                    logger.warn(message);
                    break;
                case ERROR:
                    logger.error(message);
                    break;
                default:
                    break;
            }
        }
    };
    final String destinationUrl = context.getProperty(DESTINATION_URL).evaluateAttributeExpressions().getValue();
    final SiteToSiteTransportProtocol mode = SiteToSiteTransportProtocol.valueOf(context.getProperty(TRANSPORT_PROTOCOL).getValue());
    final HttpProxy httpProxy = mode.equals(SiteToSiteTransportProtocol.RAW) || StringUtils.isEmpty(context.getProperty(HTTP_PROXY_HOSTNAME).getValue()) ? null : new HttpProxy(context.getProperty(HTTP_PROXY_HOSTNAME).getValue(), context.getProperty(HTTP_PROXY_PORT).asInteger(), context.getProperty(HTTP_PROXY_USERNAME).getValue(), context.getProperty(HTTP_PROXY_PASSWORD).getValue());
    siteToSiteClient = new SiteToSiteClient.Builder().urls(SiteToSiteRestApiClient.parseClusterUrls(destinationUrl)).portName(context.getProperty(PORT_NAME).getValue()).useCompression(context.getProperty(COMPRESS).asBoolean()).eventReporter(eventReporter).sslContext(sslContext).timeout(context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS).transportProtocol(mode).httpProxy(httpProxy).build();
}
Also used : HttpProxy(org.apache.nifi.remote.protocol.http.HttpProxy) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SSLContext(javax.net.ssl.SSLContext) SiteToSiteTransportProtocol(org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol) ComponentLog(org.apache.nifi.logging.ComponentLog) EventReporter(org.apache.nifi.events.EventReporter) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 55 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class ListenLumberjack method createDispatcher.

@Override
protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<LumberjackEvent> events) throws IOException {
    final EventFactory<LumberjackEvent> eventFactory = new LumberjackEventFactory();
    final ChannelHandlerFactory<LumberjackEvent, AsyncChannelDispatcher> handlerFactory = new LumberjackSocketChannelHandlerFactory<>();
    final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    // initialize the buffer pool based on max number of connections and the buffer size
    final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    SSLContext sslContext = null;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    }
    // if we decide to support SSL then get the context and pass it in here
    return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, charSet);
}
Also used : LumberjackEventFactory(org.apache.nifi.processors.lumberjack.event.LumberjackEventFactory) LumberjackSocketChannelHandlerFactory(org.apache.nifi.processors.lumberjack.handler.LumberjackSocketChannelHandlerFactory) Charset(java.nio.charset.Charset) SSLContext(javax.net.ssl.SSLContext) ByteBuffer(java.nio.ByteBuffer) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) LumberjackEvent(org.apache.nifi.processors.lumberjack.event.LumberjackEvent) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher)

Aggregations

SSLContextService (org.apache.nifi.ssl.SSLContextService)84 SSLContext (javax.net.ssl.SSLContext)29 Test (org.junit.Test)23 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)22 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)18 ArrayList (java.util.ArrayList)12 StandardRestrictedSSLContextService (org.apache.nifi.ssl.StandardRestrictedSSLContextService)12 IOException (java.io.IOException)11 ValidationResult (org.apache.nifi.components.ValidationResult)10 ComponentLog (org.apache.nifi.logging.ComponentLog)9 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)7 InetSocketAddress (java.net.InetSocketAddress)6 ProcessException (org.apache.nifi.processor.exception.ProcessException)6 Charset (java.nio.charset.Charset)5 InitializationException (org.apache.nifi.reporting.InitializationException)5 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 ByteBuffer (java.nio.ByteBuffer)4 ProviderCreationException (org.apache.nifi.authentication.exception.ProviderCreationException)4 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)4