Search in sources :

Example 1 with StandardSSLContextService

use of org.apache.nifi.ssl.StandardSSLContextService in project kylo by Teradata.

the class MetadataProviderSelectorServiceTest method createSslContextService.

private SSLContextService createSslContextService(TestRunner runner) throws InitializationException {
    SSLContextService service = new StandardSSLContextService();
    runner.addControllerService(SSL_SERVICE_NAME, service);
    runner.setProperty(service, StandardSSLContextService.KEYSTORE.getName(), "/Users/sr186054/tools/test-ssl/test/CN=kylo_OU=ThinkBig.p12");
    runner.setProperty(service, StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "RQDTSpm");
    runner.setProperty(service, StandardSSLContextService.KEYSTORE_TYPE.getName(), "PKCS12");
    runner.setProperty(service, StandardSSLContextService.TRUSTSTORE.getName(), "/Users/sr186054/tools/test-ssl/test/localhost/truststore.jks");
    runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "S1+cc2FKMzk2td/p6OJE0U6FUM3fV5jnlrYj46CoUSU");
    runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
    runner.enableControllerService(service);
    return service;
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService)

Example 2 with StandardSSLContextService

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

the class TestInvokeHttpSSL method before.

@Before
public void before() throws Exception {
    runner = TestRunners.newTestRunner(InvokeHTTP.class);
    final StandardSSLContextService sslService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslService, sslProperties);
    runner.enableControllerService(sslService);
    runner.setProperty(InvokeHTTP.PROP_SSL_CONTEXT_SERVICE, "ssl-context");
    // Allow time for the controller service to fully initialize
    Thread.sleep(500);
    // Provide more time to setup and run
    runner.setProperty(InvokeHTTP.PROP_READ_TIMEOUT, "30 secs");
    runner.setProperty(InvokeHTTP.PROP_CONNECT_TIMEOUT, "30 secs");
    server.clearHandlers();
}
Also used : StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Before(org.junit.Before)

Example 3 with StandardSSLContextService

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

the class TestPostHTTP method testSendAsFlowFileSecure.

@Test
public void testSendAsFlowFileSecure() throws Exception {
    final Map<String, String> sslProps = new HashMap<>();
    sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
    sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
    sslProps.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
    sslProps.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
    sslProps.put(TestServer.NEED_CLIENT_AUTH, "true");
    setup(sslProps);
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    runner.setProperty(PostHTTP.URL, server.getSecureUrl());
    runner.setProperty(PostHTTP.SEND_AS_FLOWFILE, "true");
    runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("abc", "cba");
    runner.enqueue("Hello".getBytes(), attrs);
    attrs.put("abc", "abc");
    attrs.put("filename", "xyz.txt");
    runner.enqueue("World".getBytes(), attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS);
    final byte[] lastPost = servlet.getLastPost();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ByteArrayInputStream bais = new ByteArrayInputStream(lastPost);
    FlowFileUnpackagerV3 unpacker = new FlowFileUnpackagerV3();
    // unpack first flowfile received
    Map<String, String> receivedAttrs = unpacker.unpackageFlowFile(bais, baos);
    byte[] contentReceived = baos.toByteArray();
    assertEquals("Hello", new String(contentReceived));
    assertEquals("cba", receivedAttrs.get("abc"));
    assertTrue(unpacker.hasMoreData());
    baos.reset();
    receivedAttrs = unpacker.unpackageFlowFile(bais, baos);
    contentReceived = baos.toByteArray();
    assertEquals("World", new String(contentReceived));
    assertEquals("abc", receivedAttrs.get("abc"));
    assertEquals("xyz.txt", receivedAttrs.get("filename"));
}
Also used : FlowFileUnpackagerV3(org.apache.nifi.util.FlowFileUnpackagerV3) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with StandardSSLContextService

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

the class TestPostHTTP method testTruststoreSSLOnly.

@Test
public void testTruststoreSSLOnly() throws Exception {
    final Map<String, String> sslProps = new HashMap<>();
    sslProps.put(TestServer.NEED_CLIENT_AUTH, "false");
    sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
    sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
    setup(sslProps);
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    runner.setProperty(PostHTTP.URL, server.getSecureUrl());
    runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
    runner.setProperty(PostHTTP.CHUNKED_ENCODING, "false");
    runner.enqueue("Hello world".getBytes());
    runner.run();
    runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS, 1);
}
Also used : HashMap(java.util.HashMap) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

Example 5 with StandardSSLContextService

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

the class TestPostHTTP method testOneWaySSLWhenServerConfiguredForTwoWay.

@Test
public void testOneWaySSLWhenServerConfiguredForTwoWay() throws Exception {
    final Map<String, String> sslProps = new HashMap<>();
    sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
    sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
    sslProps.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
    sslProps.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
    sslProps.put(TestServer.NEED_CLIENT_AUTH, "true");
    setup(sslProps);
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    runner.setProperty(PostHTTP.URL, server.getSecureUrl());
    runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
    runner.setProperty(PostHTTP.CHUNKED_ENCODING, "false");
    runner.enqueue("Hello world".getBytes());
    runner.run();
    runner.assertAllFlowFilesTransferred(PostHTTP.REL_FAILURE, 1);
}
Also used : HashMap(java.util.HashMap) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

Aggregations

StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)17 SSLContextService (org.apache.nifi.ssl.SSLContextService)11 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 Before (org.junit.Before)4 InitializationException (org.apache.nifi.reporting.InitializationException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 LivySessionController (org.apache.nifi.controller.livy.LivySessionController)1 ConsumeMQTT (org.apache.nifi.processors.mqtt.ConsumeMQTT)1 PublishMQTT (org.apache.nifi.processors.mqtt.PublishMQTT)1 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)1 StandardRestrictedSSLContextService (org.apache.nifi.ssl.StandardRestrictedSSLContextService)1 FlowFileUnpackagerV3 (org.apache.nifi.util.FlowFileUnpackagerV3)1 MockFlowFile (org.apache.nifi.util.MockFlowFile)1