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);
}
}
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;
}
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);
}
}
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());
}
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());
}
Aggregations