Search in sources :

Example 1 with NiFiPropertiesWriter

use of org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter in project nifi by apache.

the class NifiPropertiesTlsClientConfigWriter method updateProperties.

protected void updateProperties(NiFiPropertiesWriter niFiPropertiesWriter, TlsClientConfig tlsClientConfig) throws IOException {
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_KEYSTORE, CONF + new File(tlsClientConfig.getKeyStore()).getName());
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_KEYSTORE_TYPE, tlsClientConfig.getKeyStoreType());
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_KEYSTORE_PASSWD, tlsClientConfig.getKeyStorePassword());
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_KEY_PASSWD, tlsClientConfig.getKeyPassword());
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE, CONF + new File(tlsClientConfig.getTrustStore()).getName());
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE_TYPE, tlsClientConfig.getTrustStoreType());
    niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, tlsClientConfig.getTrustStorePassword());
    getHostnamePropertyStream().forEach(s -> niFiPropertiesWriter.setPropertyValue(s, hostname));
    overlayProperties.stringPropertyNames().stream().filter(s -> !metaProperties.contains(s)).forEach(s -> niFiPropertiesWriter.setPropertyValue(s, overlayProperties.getProperty(s)));
    getIncrementingPropertyMap().entrySet().forEach(nameToIntegerEntry -> niFiPropertiesWriter.setPropertyValue(nameToIntegerEntry.getKey(), Integer.toString(nameToIntegerEntry.getValue())));
}
Also used : OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) Properties(java.util.Properties) Set(java.util.Set) IOException(java.io.IOException) StringUtils(org.apache.nifi.util.StringUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) HashSet(java.util.HashSet) NiFiPropertiesWriterFactory(org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriterFactory) Stream(java.util.stream.Stream) NiFiProperties(org.apache.nifi.util.NiFiProperties) TlsClientConfig(org.apache.nifi.toolkit.tls.configuration.TlsClientConfig) OutputStreamFactory(org.apache.nifi.toolkit.tls.util.OutputStreamFactory) Map(java.util.Map) NiFiPropertiesWriter(org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter) Collections(java.util.Collections) File(java.io.File)

Example 2 with NiFiPropertiesWriter

use of org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter in project nifi by apache.

the class NifiPropertiesTlsClientConfigWriter method write.

@Override
public void write(TlsClientConfig tlsClientConfig, OutputStreamFactory outputStreamFactory) throws IOException {
    NiFiPropertiesWriter niFiPropertiesWriter = niFiPropertiesWriterFactory.create();
    updateProperties(niFiPropertiesWriter, tlsClientConfig);
    try (OutputStream stream = outputStreamFactory.create(outputFile)) {
        niFiPropertiesWriter.writeNiFiProperties(stream);
    }
}
Also used : NiFiPropertiesWriter(org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter) OutputStream(java.io.OutputStream)

Example 3 with NiFiPropertiesWriter

use of org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter in project nifi by apache.

the class NifiPropertiesTlsClientConfigWriterTest method setup.

@Before
public void setup() throws IOException {
    testHostname = "testHostname";
    hostNum = 22;
    keyStore = "testKeyStore.jks";
    keyStoreType = TlsConfig.DEFAULT_KEY_STORE_TYPE;
    keyStorePassword = "badKeyStorePassword";
    keyPassword = "badKeyPassword";
    trustStore = "testTrustStore.jks";
    trustStoreType = TlsConfig.DEFAULT_KEY_STORE_TYPE;
    trustStorePassword = "badTrustStorePassword";
    outputFile = File.createTempFile("temp", "nifi");
    outputStream = new ByteArrayOutputStream();
    when(outputStreamFactory.create(outputFile)).thenReturn(outputStream);
    tlsClientConfig = new TlsClientConfig();
    tlsClientConfig.setKeyStore(keyStore);
    tlsClientConfig.setKeyStoreType(keyStoreType);
    tlsClientConfig.setKeyStorePassword(keyStorePassword);
    tlsClientConfig.setKeyPassword(keyPassword);
    tlsClientConfig.setTrustStore(trustStore);
    tlsClientConfig.setTrustStoreType(trustStoreType);
    tlsClientConfig.setTrustStorePassword(trustStorePassword);
    niFiPropertiesWriter = new NiFiPropertiesWriter(new ArrayList<>());
    when(niFiPropertiesWriterFactory.create()).thenReturn(niFiPropertiesWriter);
    nifiPropertiesTlsClientConfigWriter = new NifiPropertiesTlsClientConfigWriter(niFiPropertiesWriterFactory, outputFile, testHostname, hostNum);
    overlayProperties = nifiPropertiesTlsClientConfigWriter.getOverlayProperties();
}
Also used : NiFiPropertiesWriter(org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter) TlsClientConfig(org.apache.nifi.toolkit.tls.configuration.TlsClientConfig) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 4 with NiFiPropertiesWriter

use of org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter in project nifi by apache.

the class TlsToolkitStandaloneCommandLineTest method getProperties.

private Properties getProperties() throws IOException {
    NiFiPropertiesWriter niFiPropertiesWriter = tlsToolkitStandaloneCommandLine.createConfig().getNiFiPropertiesWriterFactory().create();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    niFiPropertiesWriter.writeNiFiProperties(byteArrayOutputStream);
    Properties properties = new Properties();
    properties.load(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
    return properties;
}
Also used : NiFiPropertiesWriter(org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Aggregations

NiFiPropertiesWriter (org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Properties (java.util.Properties)2 TlsClientConfig (org.apache.nifi.toolkit.tls.configuration.TlsClientConfig)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 NiFiPropertiesWriterFactory (org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriterFactory)1 OutputStreamFactory (org.apache.nifi.toolkit.tls.util.OutputStreamFactory)1 NiFiProperties (org.apache.nifi.util.NiFiProperties)1