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);
}
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));
}
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());
}
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());
}
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);
}
Aggregations