Search in sources :

Example 61 with SSLContextService

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

the class JmsFactory method createConnectionFactory.

private static ConnectionFactory createConnectionFactory(final ProcessContext context) throws JMSException {
    final URI uri;
    try {
        uri = new URI(context.getProperty(URL).getValue());
    } catch (URISyntaxException e) {
        // Should not happen - URI was validated
        throw new IllegalArgumentException("Validated URI [" + context.getProperty(URL) + "] was invalid", e);
    }
    final int timeoutMillis = context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
    final String provider = context.getProperty(JMS_PROVIDER).getValue();
    if (isSSL(uri)) {
        final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
        if (sslContextService == null) {
            throw new IllegalArgumentException("Attempting to initiate SSL JMS connection and SSL Context is not set.");
        }
        return createSslConnectionFactory(uri, timeoutMillis, provider, sslContextService.getKeyStoreFile(), sslContextService.getKeyStorePassword(), sslContextService.getTrustStoreFile(), sslContextService.getTrustStorePassword());
    } else {
        return createConnectionFactory(uri, timeoutMillis, provider);
    }
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 62 with SSLContextService

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

the class TestListenHTTP method testSecurePOSTRequestsReturnCodeReceivedWithEL.

@Test
public void testSecurePOSTRequestsReturnCodeReceivedWithEL() throws Exception {
    SSLContextService sslContextService = configureProcessorSslContextService();
    runner.setProperty(sslContextService, StandardRestrictedSSLContextService.RESTRICTED_SSL_ALGORITHM, "TLSv1.2");
    runner.enableControllerService(sslContextService);
    runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
    runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
    runner.setProperty(ListenHTTP.RETURN_CODE, Integer.toString(HttpServletResponse.SC_NO_CONTENT));
    runner.assertValid();
    testPOSTRequestsReceived(HttpServletResponse.SC_NO_CONTENT);
}
Also used : StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

Example 63 with SSLContextService

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

the class TestListenHTTP method executePOST.

private int executePOST(String message) throws Exception {
    final SSLContextService sslContextService = runner.getControllerService(SSL_CONTEXT_SERVICE_IDENTIFIER, SSLContextService.class);
    final boolean secure = (sslContextService != null);
    final String scheme = secure ? "https" : "http";
    final URL url = new URL(scheme + "://localhost:" + availablePort + "/" + HTTP_BASE_PATH);
    HttpURLConnection connection;
    if (secure) {
        final HttpsURLConnection sslCon = (HttpsURLConnection) url.openConnection();
        final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.WANT);
        sslCon.setSSLSocketFactory(sslContext.getSocketFactory());
        connection = sslCon;
    } else {
        connection = (HttpURLConnection) url.openConnection();
    }
    connection.setRequestMethod(HTTP_POST_METHOD);
    connection.setDoOutput(true);
    final DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
    if (message != null) {
        wr.writeBytes(message);
    }
    wr.flush();
    wr.close();
    return connection.getResponseCode();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) DataOutputStream(java.io.DataOutputStream) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) SSLContext(javax.net.ssl.SSLContext) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 64 with SSLContextService

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

the class TestListenHTTP method testSecurePOSTRequestsReturnCodeReceivedWithoutEL.

@Test
public void testSecurePOSTRequestsReturnCodeReceivedWithoutEL() throws Exception {
    SSLContextService sslContextService = configureProcessorSslContextService();
    runner.setProperty(sslContextService, StandardRestrictedSSLContextService.RESTRICTED_SSL_ALGORITHM, "TLSv1.2");
    runner.enableControllerService(sslContextService);
    runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
    runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
    runner.setProperty(ListenHTTP.RETURN_CODE, Integer.toString(HttpServletResponse.SC_NO_CONTENT));
    runner.assertValid();
    testPOSTRequestsReceived(HttpServletResponse.SC_NO_CONTENT);
}
Also used : StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

Example 65 with SSLContextService

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

the class TestListenHTTP method testSecurePOSTRequestsReceivedWithEL.

@Test
public void testSecurePOSTRequestsReceivedWithEL() throws Exception {
    SSLContextService sslContextService = configureProcessorSslContextService();
    runner.setProperty(sslContextService, StandardRestrictedSSLContextService.RESTRICTED_SSL_ALGORITHM, "TLSv1.2");
    runner.enableControllerService(sslContextService);
    runner.setProperty(ListenHTTP.PORT, HTTP_SERVER_PORT_EL);
    runner.setProperty(ListenHTTP.BASE_PATH, HTTP_SERVER_BASEPATH_EL);
    runner.assertValid();
    testPOSTRequestsReceived(HttpServletResponse.SC_OK);
}
Also used : StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

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