Search in sources :

Example 1 with IdentityMapping

use of org.apache.nifi.authorization.util.IdentityMapping 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 2 with IdentityMapping

use of org.apache.nifi.authorization.util.IdentityMapping 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 3 with IdentityMapping

use of org.apache.nifi.authorization.util.IdentityMapping 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 4 with IdentityMapping

use of org.apache.nifi.authorization.util.IdentityMapping in project nifi by apache.

the class NiFiAuthenticationProviderTest method testPatternPropertyWithNoCorrespondingValueProperty.

@Test
public void testPatternPropertyWithNoCorrespondingValueProperty() {
    Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.dn", "");
    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 5 with IdentityMapping

use of org.apache.nifi.authorization.util.IdentityMapping in project nifi by apache.

the class NiFiAuthenticationProviderTest method testMultipleMappings.

@Test
public void testMultipleMappings() {
    Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.1", "pattern1");
    properties.setProperty("nifi.security.identity.mapping.value.1", "value1");
    properties.setProperty("nifi.security.identity.mapping.pattern.2", "pattern2");
    properties.setProperty("nifi.security.identity.mapping.value.2", "value2");
    properties.setProperty("nifi.security.identity.mapping.pattern.3", "pattern3");
    properties.setProperty("nifi.security.identity.mapping.value.3", "value3");
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    List<IdentityMapping> mappings = provider.getMappings();
    assertEquals(3, 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)

Aggregations

Properties (java.util.Properties)5 IdentityMapping (org.apache.nifi.authorization.util.IdentityMapping)5 NiFiProperties (org.apache.nifi.util.NiFiProperties)5 Test (org.junit.Test)5 Mockito.anyString (org.mockito.Mockito.anyString)2