use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class ProtectedNiFiProperties method protectPlainProperties.
/**
* Returns a new instance of {@link NiFiProperties} with all populated sensitive values protected by the provided protection scheme. Plain non-sensitive values are copied directly.
*
* @param protectionScheme the identifier key of the {@link SensitivePropertyProvider} to use
* @return the protected properties in a {@link StandardNiFiProperties} object
*/
NiFiProperties protectPlainProperties(String protectionScheme) {
SensitivePropertyProvider spp = getSensitivePropertyProvider(protectionScheme);
// Make a new holder (settable)
Properties protectedProperties = new Properties();
// Copy over the plain keys
Set<String> plainKeys = getPropertyKeys();
plainKeys.removeAll(getSensitivePropertyKeys());
for (String key : plainKeys) {
protectedProperties.setProperty(key, getInternalNiFiProperties().getProperty(key));
}
// Add the protected keys and the protection schemes
for (String key : getSensitivePropertyKeys()) {
final String plainValue = getInternalNiFiProperties().getProperty(key);
if (plainValue != null && !plainValue.trim().isEmpty()) {
final String protectedValue = spp.protect(plainValue);
protectedProperties.setProperty(key, protectedValue);
protectedProperties.setProperty(getProtectionKey(key), protectionScheme);
}
}
return new StandardNiFiProperties(protectedProperties);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestSocketRemoteSiteListener method testRequestPeerList.
@Test
public void testRequestPeerList() throws Exception {
Method method = SocketRemoteSiteListener.class.getDeclaredMethod("handleRequest", ServerProtocol.class, Peer.class, RequestType.class);
method.setAccessible(true);
final NiFiProperties nifiProperties = spy(NiFiProperties.class);
final int apiPort = 8080;
final int remoteSocketPort = 8081;
final String remoteInputHost = "node1.example.com";
when(nifiProperties.getPort()).thenReturn(apiPort);
when(nifiProperties.getRemoteInputHost()).thenReturn(remoteInputHost);
when(nifiProperties.getRemoteInputPort()).thenReturn(remoteSocketPort);
// Even if HTTP transport is disabled, RAW should work.
when(nifiProperties.getRemoteInputHttpPort()).thenReturn(null);
when(nifiProperties.isSiteToSiteHttpEnabled()).thenReturn(false);
when(nifiProperties.isSiteToSiteSecure()).thenReturn(false);
final SocketRemoteSiteListener listener = new SocketRemoteSiteListener(remoteSocketPort, null, nifiProperties);
final ServerProtocol serverProtocol = mock(ServerProtocol.class);
doAnswer(invocation -> {
final NodeInformation self = invocation.getArgumentAt(2, NodeInformation.class);
// Listener should inform about itself properly:
assertEquals(remoteInputHost, self.getSiteToSiteHostname());
assertEquals(remoteSocketPort, self.getSiteToSitePort().intValue());
assertNull(self.getSiteToSiteHttpApiPort());
assertEquals(apiPort, self.getAPIPort());
return null;
}).when(serverProtocol).sendPeerList(any(Peer.class), any(Optional.class), any(NodeInformation.class));
final Peer peer = null;
method.invoke(listener, serverProtocol, peer, RequestType.REQUEST_PEER_LIST);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class JettyServerTest method testConfigureSslContextFactoryWithKeystorePassword.
@Test
public void testConfigureSslContextFactoryWithKeystorePassword() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
// Expect that with no KeyPassword, we use the same one from the KeyStore
String testKeystorePassword = "testKeystorePassword";
final Map<String, String> addProps = new HashMap<>();
addProps.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, testKeystorePassword);
NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
SslContextFactory contextFactory = mock(SslContextFactory.class);
JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
verify(contextFactory).setKeyStorePassword(testKeystorePassword);
verify(contextFactory).setKeyManagerPassword(testKeystorePassword);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class JettyServerTest method testConfigureSslContextFactoryWithJksTrustStore.
@Test
public void testConfigureSslContextFactoryWithJksTrustStore() {
// Expect that we will not set provider for jks truststore
final Map<String, String> addProps = new HashMap<>();
String trustStoreType = KeystoreType.JKS.toString();
addProps.put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE, trustStoreType);
NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
SslContextFactory contextFactory = mock(SslContextFactory.class);
JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
verify(contextFactory).setTrustStoreType(trustStoreType);
verify(contextFactory, never()).setTrustStoreProvider(anyString());
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class JettyServerTest method testConfigureSslContextFactoryWithPkcsKeyStore.
@Test
public void testConfigureSslContextFactoryWithPkcsKeyStore() {
// Expect that we will set Bouncy Castle provider for pkcs12 keystore
final Map<String, String> addProps = new HashMap<>();
String keyStoreType = KeystoreType.PKCS12.toString();
addProps.put(NiFiProperties.SECURITY_KEYSTORE_TYPE, keyStoreType);
NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
SslContextFactory contextFactory = mock(SslContextFactory.class);
JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
verify(contextFactory).setKeyStoreType(keyStoreType);
verify(contextFactory).setKeyStoreProvider(BouncyCastleProvider.PROVIDER_NAME);
}
Aggregations