Search in sources :

Example 31 with NiFiProperties

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

the class NiFiAuthenticationProviderTest method testMapIdentityWithMultipleMatchingPatterns.

@Test
public void testMapIdentityWithMultipleMatchingPatterns() {
    // create two pattern properties that are the same, but the value properties are different
    final Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.dn2", "^cn=(.*?),dc=(.*?),dc=(.*?)$");
    properties.setProperty("nifi.security.identity.mapping.value.dn2", "$1_$2_$3");
    properties.setProperty("nifi.security.identity.mapping.pattern.dn1", "^cn=(.*?),dc=(.*?),dc=(.*?)$");
    properties.setProperty("nifi.security.identity.mapping.value.dn1", "$1 $2 $3");
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    final TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    // the mapping should always use dn1 because it is sorted
    final String identity = "cn=jsmith,dc=aaa,dc=bbb";
    final String mappedIdentity = provider.mapIdentity(identity);
    assertEquals("jsmith aaa bbb", mappedIdentity);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 32 with NiFiProperties

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

the class NiFiAuthenticationProviderTest method testNoMappings.

@Test
public void testNoMappings() {
    Properties properties = new Properties();
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    List<IdentityMapping> mappings = provider.getMappings();
    assertEquals(0, mappings.size());
    final String identity = "john";
    assertEquals(identity, provider.mapIdentity(identity));
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) IdentityMapping(org.apache.nifi.authorization.util.IdentityMapping) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 33 with NiFiProperties

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

the class NiFiAuthenticationProviderTest method testPatternPropertyWithNoValue.

@Test
public void testPatternPropertyWithNoValue() {
    Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.dn", "");
    properties.setProperty("nifi.security.identity.mapping.value.dn", "value");
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    List<IdentityMapping> mappings = provider.getMappings();
    assertEquals(0, mappings.size());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) IdentityMapping(org.apache.nifi.authorization.util.IdentityMapping) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 34 with NiFiProperties

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

the class NiFiAuthenticationProviderTest method testValidPropertiesProvided.

@Test
public void testValidPropertiesProvided() {
    final String pattern = "^cn=(.*?),dc=(.*?),dc=(.*?)$";
    final String value = "$1@$2.$3";
    Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.dn", pattern);
    properties.setProperty("nifi.security.identity.mapping.value.dn", value);
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    List<IdentityMapping> mappings = provider.getMappings();
    assertEquals(1, mappings.size());
    assertEquals("dn", mappings.get(0).getKey());
    assertEquals(pattern, mappings.get(0).getPattern().pattern());
    assertEquals(value, mappings.get(0).getReplacementValue());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) IdentityMapping(org.apache.nifi.authorization.util.IdentityMapping) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 35 with NiFiProperties

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

the class NiFiAuthenticationProviderTest method testMapIdentityWithSingleMapping.

@Test
public void testMapIdentityWithSingleMapping() {
    final Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.dn", "^cn=(.*?),dc=(.*?),dc=(.*?)$");
    properties.setProperty("nifi.security.identity.mapping.value.dn", "$1@$2.$3");
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    final TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    final String identity = "cn=jsmith,dc=aaa,dc=bbb";
    final String mappedIdentity = provider.mapIdentity(identity);
    assertEquals("jsmith@aaa.bbb", mappedIdentity);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

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