Search in sources :

Example 11 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class NiFi method main.

/**
 * Main entry point of the application.
 *
 * @param args things which are ignored
 */
public static void main(String[] args) {
    LOGGER.info("Launching NiFi...");
    try {
        NiFiProperties properties = convertArgumentsToValidatedNiFiProperties(args);
        new NiFi(properties);
    } catch (final Throwable t) {
        LOGGER.error("Failure to launch NiFi due to " + t, t);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties)

Example 12 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class NiFi method convertArgumentsToValidatedNiFiProperties.

protected static NiFiProperties convertArgumentsToValidatedNiFiProperties(String[] args) throws IOException {
    final ClassLoader bootstrap = createBootstrapClassLoader();
    NiFiProperties properties = initializeProperties(args, bootstrap);
    properties.validate();
    return properties;
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) URLClassLoader(java.net.URLClassLoader)

Example 13 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class NiFi method initializeProperties.

private static NiFiProperties initializeProperties(final String[] args, final ClassLoader boostrapLoader) {
    // Try to get key
    // If key doesn't exist, instantiate without
    // Load properties
    // If properties are protected and key missing, throw RuntimeException
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    final String key;
    try {
        key = loadFormattedKey(args);
    // The key might be empty or null when it is passed to the loader
    } catch (IllegalArgumentException e) {
        final String msg = "The bootstrap process did not provide a valid key";
        throw new IllegalArgumentException(msg, e);
    }
    Thread.currentThread().setContextClassLoader(boostrapLoader);
    try {
        final Class<?> propsLoaderClass = Class.forName("org.apache.nifi.properties.NiFiPropertiesLoader", true, boostrapLoader);
        final Method withKeyMethod = propsLoaderClass.getMethod("withKey", String.class);
        final Object loaderInstance = withKeyMethod.invoke(null, key);
        final Method getMethod = propsLoaderClass.getMethod("get");
        final NiFiProperties properties = (NiFiProperties) getMethod.invoke(loaderInstance);
        LOGGER.info("Loaded {} properties", properties.size());
        return properties;
    } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException reex) {
        final String msg = "Unable to access properties loader in the expected manner - apparent classpath or build issue";
        throw new IllegalArgumentException(msg, reex);
    } catch (final RuntimeException e) {
        final String msg = "There was an issue decrypting protected properties";
        throw new IllegalArgumentException(msg, e);
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) URLClassLoader(java.net.URLClassLoader)

Example 14 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TestStandardRootGroupPort method testCheckUserAuthorizationByMappedDn.

@Test
public void testCheckUserAuthorizationByMappedDn() {
    final NiFiProperties nifiProperties = mock(NiFiProperties.class);
    final String mapKey = ".dn";
    Set<String> propertyKeys = new LinkedHashSet<>();
    propertyKeys.add(NiFiProperties.SECURITY_IDENTITY_MAPPING_PATTERN_PREFIX + mapKey);
    propertyKeys.add(NiFiProperties.SECURITY_IDENTITY_MAPPING_VALUE_PREFIX + mapKey);
    doReturn(propertyKeys).when(nifiProperties).getPropertyKeys();
    final String mapPattern = "^CN=(.*?), OU=(.*?)$";
    final String mapValue = "$1@$2";
    doReturn(mapPattern).when(nifiProperties).getProperty(eq(NiFiProperties.SECURITY_IDENTITY_MAPPING_PATTERN_PREFIX + mapKey));
    doReturn(mapValue).when(nifiProperties).getProperty(eq(NiFiProperties.SECURITY_IDENTITY_MAPPING_VALUE_PREFIX + mapKey));
    final RootGroupPort port = createRootGroupPort(nifiProperties);
    PortAuthorizationResult authResult = port.checkUserAuthorization("CN=node2, OU=nifi.test");
    Assert.assertFalse(authResult.isAuthorized());
    authResult = port.checkUserAuthorization("CN=node1, OU=nifi.test");
    Assert.assertTrue(authResult.isAuthorized());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 15 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TestStandardRootGroupPort method testCheckUserAuthorizationByDn.

@Test
public void testCheckUserAuthorizationByDn() {
    final NiFiProperties nifiProperties = mock(NiFiProperties.class);
    final RootGroupPort port = createRootGroupPort(nifiProperties);
    PortAuthorizationResult authResult = port.checkUserAuthorization("CN=node1, OU=nifi.test");
    Assert.assertFalse(authResult.isAuthorized());
    authResult = port.checkUserAuthorization("node1@nifi.test");
    Assert.assertTrue(authResult.isAuthorized());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

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