use of org.apache.nifi.util.NiFiProperties 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());
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NiFiAuthenticationProviderTest method getNiFiProperties.
private NiFiProperties getNiFiProperties(final Properties properties) {
final NiFiProperties nifiProperties = mock(NiFiProperties.class);
when(nifiProperties.getPropertyKeys()).thenReturn(properties.stringPropertyNames());
when(nifiProperties.getProperty(anyString())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocationOnMock) throws Throwable {
return properties.getProperty((String) invocationOnMock.getArguments()[0]);
}
});
return nifiProperties;
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NiFiAuthenticationProviderTest method testMapIdentityWithNoGroupReference.
@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);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NiFiAuthenticationProviderTest method testMapIdentityWithIncorrectGroupReference.
@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);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class ApplicationStartupContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
final NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class);
try {
flowService = ctx.getBean("flowService", FlowService.class);
flowController = ctx.getBean("flowController", FlowController.class);
requestReplicator = ctx.getBean("requestReplicator", RequestReplicator.class);
// the flow loading here when not clustered resolves this.
if (!properties.isNode()) {
logger.info("Starting Flow Controller...");
// start and load the flow
flowService.start();
flowService.load(null);
/*
* Start up all processors if specified.
*
* When operating as the node, the cluster manager controls
* which processors should start. As part of the flow
* reloading actions, the node will start the necessary
* processors.
*/
flowController.onFlowInitialized(properties.getAutoResumeState());
logger.info("Flow Controller started successfully.");
}
} catch (BeansException | RepositoryPurgeException | IOException e) {
shutdown();
throw new NiFiCoreException("Unable to start Flow Controller.", e);
}
try {
// attempt to get a few beans that we want to to ensure properly created since they are lazily initialized
ctx.getBean("loginIdentityProvider", LoginIdentityProvider.class);
ctx.getBean("authorizer", Authorizer.class);
} catch (final BeansException e) {
shutdown();
throw new NiFiCoreException("Unable to start Flow Controller.", e);
}
}
Aggregations