use of org.apache.nifi.components.PropertyValue in project nifi by apache.
the class AbstractCassandraProcessor method connectToCassandra.
protected void connectToCassandra(ProcessContext context) {
if (cluster.get() == null) {
ComponentLog log = getLogger();
final String contactPointList = context.getProperty(CONTACT_POINTS).evaluateAttributeExpressions().getValue();
final String consistencyLevel = context.getProperty(CONSISTENCY_LEVEL).getValue();
List<InetSocketAddress> contactPoints = getContactPoints(contactPointList);
// Set up the client for secure (SSL/TLS communications) if configured to do so
final SSLContextService sslService = context.getProperty(PROP_SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
final String rawClientAuth = context.getProperty(CLIENT_AUTH).getValue();
final SSLContext sslContext;
if (sslService != null) {
final SSLContextService.ClientAuth clientAuth;
if (StringUtils.isBlank(rawClientAuth)) {
clientAuth = SSLContextService.ClientAuth.REQUIRED;
} else {
try {
clientAuth = SSLContextService.ClientAuth.valueOf(rawClientAuth);
} catch (final IllegalArgumentException iae) {
throw new ProviderCreationException(String.format("Unrecognized client auth '%s'. Possible values are [%s]", rawClientAuth, StringUtils.join(SslContextFactory.ClientAuth.values(), ", ")));
}
}
sslContext = sslService.createSSLContext(clientAuth);
} else {
sslContext = null;
}
final String username, password;
PropertyValue usernameProperty = context.getProperty(USERNAME).evaluateAttributeExpressions();
PropertyValue passwordProperty = context.getProperty(PASSWORD).evaluateAttributeExpressions();
if (usernameProperty != null && passwordProperty != null) {
username = usernameProperty.getValue();
password = passwordProperty.getValue();
} else {
username = null;
password = null;
}
// Create the cluster and connect to it
Cluster newCluster = createCluster(contactPoints, sslContext, username, password);
PropertyValue keyspaceProperty = context.getProperty(KEYSPACE).evaluateAttributeExpressions();
final Session newSession;
if (keyspaceProperty != null) {
newSession = newCluster.connect(keyspaceProperty.getValue());
} else {
newSession = newCluster.connect();
}
newCluster.getConfiguration().getQueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel));
Metadata metadata = newCluster.getMetadata();
log.info("Connected to Cassandra cluster: {}", new Object[] { metadata.getClusterName() });
cluster.set(newCluster);
cassandraSession.set(newSession);
}
}
use of org.apache.nifi.components.PropertyValue in project nifi by apache.
the class HttpNotificationService method getSslSocketFactory.
private static SSLSocketFactory getSslSocketFactory(NotificationInitializationContext context) throws Exception {
final String protocol = context.getProperty(SSL_ALGORITHM).getValue();
try {
final PropertyValue keyPasswdProp = context.getProperty(PROP_KEY_PASSWORD);
final char[] keyPassword = keyPasswdProp.isSet() ? keyPasswdProp.getValue().toCharArray() : null;
final SSLContext sslContext;
final String truststoreFile = context.getProperty(PROP_TRUSTSTORE).getValue();
final String keystoreFile = context.getProperty(PROP_KEYSTORE).getValue();
if (keystoreFile == null) {
// If keystore not specified, create SSL Context based only on trust store.
sslContext = SslContextFactory.createTrustSslContext(context.getProperty(PROP_TRUSTSTORE).getValue(), context.getProperty(PROP_TRUSTSTORE_PASSWORD).getValue().toCharArray(), context.getProperty(PROP_TRUSTSTORE_TYPE).getValue(), protocol);
} else if (truststoreFile == null) {
// If truststore not specified, create SSL Context based only on key store.
sslContext = SslContextFactory.createSslContext(context.getProperty(PROP_KEYSTORE).getValue(), context.getProperty(PROP_KEYSTORE_PASSWORD).getValue().toCharArray(), keyPassword, context.getProperty(PROP_KEYSTORE_TYPE).getValue(), protocol);
} else {
sslContext = SslContextFactory.createSslContext(context.getProperty(PROP_KEYSTORE).getValue(), context.getProperty(PROP_KEYSTORE_PASSWORD).getValue().toCharArray(), keyPassword, context.getProperty(PROP_KEYSTORE_TYPE).getValue(), context.getProperty(PROP_TRUSTSTORE).getValue(), context.getProperty(PROP_TRUSTSTORE_PASSWORD).getValue().toCharArray(), context.getProperty(PROP_TRUSTSTORE_TYPE).getValue(), SslContextFactory.ClientAuth.REQUIRED, protocol);
}
return sslContext.getSocketFactory();
} catch (final Exception e) {
throw new ProcessException(e);
}
}
use of org.apache.nifi.components.PropertyValue in project nifi by apache.
the class StandardSSLContextService method createSSLContext.
@Override
public SSLContext createSSLContext(final ClientAuth clientAuth) throws ProcessException {
final String protocol = getSslAlgorithm();
try {
final PropertyValue keyPasswdProp = configContext.getProperty(KEY_PASSWORD);
final char[] keyPassword = keyPasswdProp.isSet() ? keyPasswdProp.getValue().toCharArray() : null;
final String keystoreFile = configContext.getProperty(KEYSTORE).getValue();
if (keystoreFile == null) {
// If keystore not specified, create SSL Context based only on trust store.
return SslContextFactory.createTrustSslContext(configContext.getProperty(TRUSTSTORE).getValue(), configContext.getProperty(TRUSTSTORE_PASSWORD).getValue().toCharArray(), configContext.getProperty(TRUSTSTORE_TYPE).getValue(), protocol);
}
final String truststoreFile = configContext.getProperty(TRUSTSTORE).getValue();
if (truststoreFile == null) {
// If truststore not specified, create SSL Context based only on key store.
return SslContextFactory.createSslContext(configContext.getProperty(KEYSTORE).getValue(), configContext.getProperty(KEYSTORE_PASSWORD).getValue().toCharArray(), keyPassword, configContext.getProperty(KEYSTORE_TYPE).getValue(), protocol);
}
return SslContextFactory.createSslContext(configContext.getProperty(KEYSTORE).getValue(), configContext.getProperty(KEYSTORE_PASSWORD).getValue().toCharArray(), keyPassword, configContext.getProperty(KEYSTORE_TYPE).getValue(), configContext.getProperty(TRUSTSTORE).getValue(), configContext.getProperty(TRUSTSTORE_PASSWORD).getValue().toCharArray(), configContext.getProperty(TRUSTSTORE_TYPE).getValue(), org.apache.nifi.security.util.SslContextFactory.ClientAuth.valueOf(clientAuth.name()), protocol);
} catch (final Exception e) {
throw new ProcessException(e);
}
}
Aggregations