Search in sources :

Example 81 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TestRangerNiFiAuthorizer method testKerberosEnabled.

@Test
public void testKerberosEnabled() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP))).thenReturn(new MockPropertyValue("true"));
    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("test");
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("test");
    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);
    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // getting a LoginException here means we attempted to login which is what we want
        boolean foundLoginException = false;
        Throwable cause = e.getCause();
        while (cause != null) {
            if (cause instanceof LoginException) {
                foundLoginException = true;
                break;
            }
            cause = cause.getCause();
        }
        assertTrue(foundLoginException);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) LoginException(javax.security.auth.login.LoginException) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Test(org.junit.Test)

Example 82 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class RecordReaders method isEncryptionAvailable.

private static boolean isEncryptionAvailable() {
    if (encryptionPropertiesRead) {
        return isEncryptionAvailable;
    } else {
        try {
            NiFiProperties niFiProperties = NiFiPropertiesLoader.loadDefaultWithKeyFromBootstrap();
            isEncryptionAvailable = CryptoUtils.isProvenanceRepositoryEncryptionConfigured(niFiProperties);
            encryptionPropertiesRead = true;
        } catch (IOException e) {
            logger.error("Encountered an error checking the provenance repository encryption configuration: ", e);
            isEncryptionAvailable = false;
        }
        return isEncryptionAvailable;
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) IOException(java.io.IOException)

Example 83 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class NifiPropertiesTlsClientConfigWriterTest method testNoHostnameProperties.

@Test
public void testNoHostnameProperties() throws IOException {
    nifiPropertiesTlsClientConfigWriter.getOverlayProperties().setProperty(NifiPropertiesTlsClientConfigWriter.HOSTNAME_PROPERTIES, "");
    nifiPropertiesTlsClientConfigWriter.write(tlsClientConfig, outputStreamFactory);
    testHostnamesAndPorts();
    Properties nifiProperties = getNifiProperties();
    nifiProperties.stringPropertyNames().forEach(s -> assertNotEquals(testHostname, nifiProperties.getProperty(s)));
}
Also used : Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 84 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TlsToolkitStandaloneTest method testFileArg.

@Test
public void testFileArg() throws Exception {
    runAndAssertExitCode(ExitCode.SUCCESS, "-o", tempDir.getAbsolutePath(), "-f", TEST_NIFI_PROPERTIES, "-n", TlsConfig.DEFAULT_HOSTNAME);
    X509Certificate x509Certificate = checkLoadCertPrivateKey(TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
    Properties nifiProperties = checkHostDirAndReturnNifiProperties(TlsConfig.DEFAULT_HOSTNAME, x509Certificate);
    assertEquals(FAKE_VALUE, nifiProperties.get(NIFI_FAKE_PROPERTY));
}
Also used : Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test) TlsHelperTest(org.apache.nifi.toolkit.tls.util.TlsHelperTest) TlsCertificateAuthorityTest(org.apache.nifi.toolkit.tls.service.TlsCertificateAuthorityTest)

Example 85 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TlsToolkitStandaloneTest method testTrustStorePasswordArg.

@Test
public void testTrustStorePasswordArg() throws Exception {
    String testTrustStore = "testTrustStore";
    runAndAssertExitCode(ExitCode.SUCCESS, "-o", tempDir.getAbsolutePath(), "-P", testTrustStore, "-n", TlsConfig.DEFAULT_HOSTNAME);
    X509Certificate x509Certificate = checkLoadCertPrivateKey(TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
    Properties nifiProperties = checkHostDirAndReturnNifiProperties(TlsConfig.DEFAULT_HOSTNAME, x509Certificate);
    assertEquals(testTrustStore, nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD));
}
Also used : Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test) TlsHelperTest(org.apache.nifi.toolkit.tls.util.TlsHelperTest) TlsCertificateAuthorityTest(org.apache.nifi.toolkit.tls.service.TlsCertificateAuthorityTest)

Aggregations

NiFiProperties (org.apache.nifi.util.NiFiProperties)98 Test (org.junit.Test)63 HashMap (java.util.HashMap)28 Properties (java.util.Properties)24 File (java.io.File)16 Bundle (org.apache.nifi.bundle.Bundle)13 Matchers.anyString (org.mockito.Matchers.anyString)13 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Map (java.util.Map)8 X509Certificate (java.security.cert.X509Certificate)7 Mockito.anyString (org.mockito.Mockito.anyString)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SystemBundle (org.apache.nifi.nar.SystemBundle)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IdentityMapping (org.apache.nifi.authorization.util.IdentityMapping)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4