Search in sources :

Example 21 with NiFiProperties

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

the class LdapUserGroupProviderTest method getNiFiProperties.

private NiFiProperties getNiFiProperties(final Properties properties) {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getPropertyKeys()).thenReturn(properties.stringPropertyNames());
    when(nifiProperties.getProperty(anyString())).then(invocationOnMock -> properties.getProperty((String) invocationOnMock.getArguments()[0]));
    return nifiProperties;
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Matchers.anyString(org.mockito.Matchers.anyString)

Example 22 with NiFiProperties

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

the class LdapUserGroupProviderTest method testUserIdentityMapping.

@Test
public void testUserIdentityMapping() throws Exception {
    final Properties props = new Properties();
    props.setProperty("nifi.security.identity.mapping.pattern.dn1", "^cn=(.*?),o=(.*?)$");
    props.setProperty("nifi.security.identity.mapping.value.dn1", "$1");
    final NiFiProperties properties = getNiFiProperties(props);
    ldapUserGroupProvider.setNiFiProperties(properties);
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(USER_SEARCH_BASE, null);
    when(configurationContext.getProperty(PROP_USER_SEARCH_FILTER)).thenReturn(new StandardPropertyValue("(uid=user1)", null));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertEquals(1, ldapUserGroupProvider.getUsers().size());
    assertNotNull(ldapUserGroupProvider.getUserByIdentity("User 1,ou=users"));
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 23 with NiFiProperties

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

the class TestRangerNiFiAuthorizer method testKerberosEnabledWithoutKeytabOrPrincipal.

@Test
public void testKerberosEnabledWithoutKeytabOrPrincipal() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP))).thenReturn(new MockPropertyValue("true"));
    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("");
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("");
    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);
    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Test(org.junit.Test)

Example 24 with NiFiProperties

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

the class TestRangerNiFiAuthorizer method testKerberosEnabledWithoutKeytab.

@Test
public void testKerberosEnabledWithoutKeytab() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP))).thenReturn(new MockPropertyValue("true"));
    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("");
    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);
    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Test(org.junit.Test)

Example 25 with NiFiProperties

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

the class NifiPropertiesTlsClientConfigWriterTest method testHostnamesAndPorts.

private void testHostnamesAndPorts() {
    Properties nifiProperties = getNifiProperties();
    assertEquals(NifiPropertiesTlsClientConfigWriter.CONF + keyStore, nifiProperties.getProperty(NiFiProperties.SECURITY_KEYSTORE));
    assertEquals(keyStoreType, nifiProperties.getProperty(NiFiProperties.SECURITY_KEYSTORE_TYPE));
    assertEquals(keyStorePassword, nifiProperties.getProperty(NiFiProperties.SECURITY_KEYSTORE_PASSWD));
    assertEquals(keyPassword, nifiProperties.getProperty(NiFiProperties.SECURITY_KEY_PASSWD));
    assertEquals(NifiPropertiesTlsClientConfigWriter.CONF + trustStore, nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE));
    assertEquals(trustStoreType, nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_TYPE));
    assertEquals(trustStorePassword, nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD));
    assertEquals("", nifiProperties.getProperty(NiFiProperties.WEB_HTTP_HOST));
    assertEquals("", nifiProperties.getProperty(NiFiProperties.WEB_HTTP_PORT));
    assertEquals(Boolean.toString(true), nifiProperties.getProperty(NiFiProperties.SITE_TO_SITE_SECURE));
    assertEquals(Boolean.toString(true), nifiProperties.getProperty(NiFiProperties.CLUSTER_PROTOCOL_IS_SECURE));
    nifiPropertiesTlsClientConfigWriter.getHostnamePropertyStream().forEach(s -> assertEquals(testHostname, nifiProperties.getProperty(s)));
    nifiPropertiesTlsClientConfigWriter.getIncrementingPropertyMap().entrySet().forEach(propertyToPortEntry -> {
        assertEquals(Integer.toString(propertyToPortEntry.getValue()), nifiProperties.getProperty(propertyToPortEntry.getKey()));
        assertEquals(Integer.parseInt(overlayProperties.getProperty(propertyToPortEntry.getKey())) + hostNum - 1, propertyToPortEntry.getValue().intValue());
    });
}
Also used : Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties)

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