Search in sources :

Example 6 with ProviderCreationException

use of org.apache.nifi.authentication.exception.ProviderCreationException in project nifi by apache.

the class AbstractMongoProcessor method createClient.

@OnScheduled
public final void createClient(ProcessContext context) throws IOException {
    if (mongoClient != null) {
        closeClient();
    }
    getLogger().info("Creating MongoClient");
    // Set up the client for secure (SSL/TLS communications) if configured to do so
    final SSLContextService sslService = context.getProperty(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;
    }
    try {
        if (sslContext == null) {
            mongoClient = new MongoClient(new MongoClientURI(getURI(context)));
        } else {
            mongoClient = new MongoClient(new MongoClientURI(getURI(context), getClientOptions(sslContext)));
        }
    } catch (Exception e) {
        getLogger().error("Failed to schedule {} due to {}", new Object[] { this.getClass().getName(), e }, e);
        throw e;
    }
}
Also used : MongoClient(com.mongodb.MongoClient) ProviderCreationException(org.apache.nifi.authentication.exception.ProviderCreationException) SSLContextService(org.apache.nifi.ssl.SSLContextService) MongoClientURI(com.mongodb.MongoClientURI) SSLContext(javax.net.ssl.SSLContext) ProviderCreationException(org.apache.nifi.authentication.exception.ProviderCreationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 7 with ProviderCreationException

use of org.apache.nifi.authentication.exception.ProviderCreationException 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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Metadata(com.datastax.driver.core.Metadata) PropertyValue(org.apache.nifi.components.PropertyValue) Cluster(com.datastax.driver.core.Cluster) SSLContext(javax.net.ssl.SSLContext) ComponentLog(org.apache.nifi.logging.ComponentLog) ProviderCreationException(org.apache.nifi.authentication.exception.ProviderCreationException) SSLContextService(org.apache.nifi.ssl.SSLContextService) Session(com.datastax.driver.core.Session)

Example 8 with ProviderCreationException

use of org.apache.nifi.authentication.exception.ProviderCreationException in project nifi by apache.

the class AbstractMongoDBControllerService method createClient.

protected final void createClient(ConfigurationContext context) throws IOException {
    if (mongoClient != null) {
        closeClient();
    }
    getLogger().info("Creating MongoClient");
    // Set up the client for secure (SSL/TLS communications) if configured to do so
    final SSLContextService sslService = context.getProperty(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;
    }
    try {
        if (sslContext == null) {
            mongoClient = new MongoClient(new MongoClientURI(getURI(context)));
        } else {
            mongoClient = new MongoClient(new MongoClientURI(getURI(context), getClientOptions(sslContext)));
        }
    } catch (Exception e) {
        getLogger().error("Failed to schedule {} due to {}", new Object[] { this.getClass().getName(), e }, e);
        throw e;
    }
}
Also used : MongoClient(com.mongodb.MongoClient) ProviderCreationException(org.apache.nifi.authentication.exception.ProviderCreationException) SSLContextService(org.apache.nifi.ssl.SSLContextService) MongoClientURI(com.mongodb.MongoClientURI) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ProviderCreationException(org.apache.nifi.authentication.exception.ProviderCreationException)

Aggregations

ProviderCreationException (org.apache.nifi.authentication.exception.ProviderCreationException)8 SSLContext (javax.net.ssl.SSLContext)6 IOException (java.io.IOException)4 SSLContextService (org.apache.nifi.ssl.SSLContextService)4 MongoClient (com.mongodb.MongoClient)2 MongoClientURI (com.mongodb.MongoClientURI)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 Cluster (com.datastax.driver.core.Cluster)1 Metadata (com.datastax.driver.core.Metadata)1 Session (com.datastax.driver.core.Session)1 Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1