### Question:
NiFiAuthenticationProvider implements AuthenticationProvider { protected String mapIdentity(final String identity) { return IdentityMappingUtil.mapIdentity(identity, mappings); } NiFiAuthenticationProvider(final NiFiProperties properties); List<IdentityMapping> getMappings();  }### Answer:
@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); }
@Test public void testMapIdentityWithIncorrectGroupReference() { 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.$4"); 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.$4", mappedIdentity); }
@Test public void testMapIdentityWithNoGroupReference() { final Properties properties = new Properties(); properties.setProperty("nifi.security.identity.mapping.pattern.dn", "^cn=(.*?),dc=(.*?),dc=(.*?)$"); properties.setProperty("nifi.security.identity.mapping.value.dn", "this makes no sense"); 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("this makes no sense", mappedIdentity); }
@Test public void testMapIdentityWithMultipleMatchingPatterns() { 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); final String identity = "cn=jsmith,dc=aaa,dc=bbb"; final String mappedIdentity = provider.mapIdentity(identity); assertEquals("jsmith aaa bbb", mappedIdentity); }