Search in sources :

Example 91 with NiFiProperties

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());
}
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 92 with NiFiProperties

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;
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mockito.anyString(org.mockito.Mockito.anyString)

Example 93 with 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);
}
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 94 with NiFiProperties

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);
}
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 95 with NiFiProperties

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);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ApplicationContext(org.springframework.context.ApplicationContext) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) RequestReplicator(org.apache.nifi.cluster.coordination.http.replication.RequestReplicator) FlowController(org.apache.nifi.controller.FlowController) IOException(java.io.IOException) RepositoryPurgeException(org.apache.nifi.controller.repository.RepositoryPurgeException) FlowService(org.apache.nifi.services.FlowService) BeansException(org.springframework.beans.BeansException)

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