use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NarThreadContextClassLoaderTest method validateWithDefaultConstructor.
@Test
public void validateWithDefaultConstructor() throws Exception {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties("src/test/resources/nifi.properties", null);
Bundle systemBundle = SystemBundle.create(properties);
ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
assertTrue(NarThreadContextClassLoader.createInstance(WithDefaultConstructor.class.getName(), WithDefaultConstructor.class, properties) instanceof WithDefaultConstructor);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NarThreadContextClassLoaderTest method validateWithPropertiesConstructorInstantiationFailure.
@Test(expected = IllegalStateException.class)
public void validateWithPropertiesConstructorInstantiationFailure() throws Exception {
Map<String, String> additionalProperties = new HashMap<>();
additionalProperties.put("fail", "true");
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties("src/test/resources/nifi.properties", additionalProperties);
Bundle systemBundle = SystemBundle.create(properties);
ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
NarThreadContextClassLoader.createInstance(WithPropertiesConstructor.class.getName(), WithPropertiesConstructor.class, properties);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NarUnpackerTest method testUnpackNarsFromNonDir.
@Test
public void testUnpackNarsFromNonDir() throws IOException {
final File nonDir = new File("./target/file.txt");
nonDir.createNewFile();
nonDir.deleteOnExit();
final Map<String, String> others = new HashMap<>();
others.put("nifi.nar.library.directory.alt", nonDir.toString());
NiFiProperties properties = loadSpecifiedProperties("/NarUnpacker/conf/nifi.properties", others);
final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties, SystemBundle.create(properties));
assertNull(extensionMapping);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NarUnpackerTest method testUnpackNarsFromNonExistantDir.
@Test
public void testUnpackNarsFromNonExistantDir() {
final File nonExistantDir = new File("./target/this/dir/should/not/exist/");
nonExistantDir.delete();
nonExistantDir.deleteOnExit();
final Map<String, String> others = new HashMap<>();
others.put("nifi.nar.library.directory.alt", nonExistantDir.toString());
NiFiProperties properties = loadSpecifiedProperties("/NarUnpacker/conf/nifi.properties", others);
final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties, SystemBundle.create(properties));
assertTrue(extensionMapping.getAllExtensionNames().keySet().contains("org.apache.nifi.processors.dummy.one"));
assertEquals(1, extensionMapping.getAllExtensionNames().size());
final File extensionsWorkingDir = properties.getExtensionsWorkingDirectory();
File[] extensionFiles = extensionsWorkingDir.listFiles();
assertEquals(1, extensionFiles.length);
assertEquals("dummy-one.nar-unpacked", extensionFiles[0].getName());
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class ProtectedNiFiProperties method getUnprotectedProperties.
/**
* Returns the unprotected {@link NiFiProperties} instance. If none of the properties
* loaded are marked as protected, it will simply pass through the internal instance.
* If any are protected, it will drop the protection scheme keys and translate each
* protected value (encrypted, HSM-retrieved, etc.) into the raw value and store it
* under the original key.
* <p>
* If any property fails to unprotect, it will save that key and continue. After
* attempting all properties, it will throw an exception containing all failed
* properties. This is necessary because the order is not enforced, so all failed
* properties should be gathered together.
*
* @return the NiFiProperties instance with all raw values
* @throws SensitivePropertyProtectionException if there is a problem unprotecting one or more keys
*/
public NiFiProperties getUnprotectedProperties() throws SensitivePropertyProtectionException {
if (hasProtectedKeys()) {
logger.info("There are {} protected properties of {} sensitive properties ({}%)", getProtectedPropertyKeys().size(), getSensitivePropertyKeys().size(), getPercentOfSensitivePropertiesProtected());
Properties rawProperties = new Properties();
Set<String> failedKeys = new HashSet<>();
for (String key : getPropertyKeys()) {
/* Three kinds of keys
* 1. protection schemes -- skip
* 2. protected keys -- unprotect and copy
* 3. normal keys -- copy over
*/
if (key.endsWith(".protected")) {
// Do nothing
} else if (isPropertyProtected(key)) {
try {
rawProperties.setProperty(key, unprotectValue(key, getProperty(key)));
} catch (SensitivePropertyProtectionException e) {
logger.warn("Failed to unprotect '{}'", key, e);
failedKeys.add(key);
}
} else {
rawProperties.setProperty(key, getProperty(key));
}
}
if (!failedKeys.isEmpty()) {
if (failedKeys.size() > 1) {
logger.warn("Combining {} failed keys [{}] into single exception", failedKeys.size(), StringUtils.join(failedKeys, ", "));
throw new MultipleSensitivePropertyProtectionException("Failed to unprotect keys", failedKeys);
} else {
throw new SensitivePropertyProtectionException("Failed to unprotect key " + failedKeys.iterator().next());
}
}
NiFiProperties unprotected = new StandardNiFiProperties(rawProperties);
return unprotected;
} else {
logger.debug("No protected properties");
return getInternalNiFiProperties();
}
}
Aggregations