如何使用连接属性(url属性)在ssl上连接Cassandra

问题描述 投票:1回答:1

我有信任库和密钥库文件以及与cassandra帐户相关的所有信息。我用来连接cassandra的应用程序存在限制,因为它没有为我提供指定我的信任库和密钥库文件的选项,因此我在寻找是否可以使用连接url属性(url属性)通过ssl连接到cassandra )

感谢您的帮助!!

cassandra cassandra-2.0 cassandra-3.0 spark-cassandra-connector cassandra-2.1
1个回答
0
投票

Instaclustr在他们的网站上有一篇文章描述了如何通过SSL连接Spark到Cassandra:Instaclustr Spark with SSL Configured Cassandra

在步骤#6中,它们提供了有关创建Cassandra连接工厂类的详细信息,该类具有createSSLOptions方法,该方法允许指定特定的详细信息:

    SSLOptions createSSLOPtions (CassandraConnectorConf.CassandraSSLConf conf) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException, KeyManagementException {
 if (conf.trustStorePath().isEmpty()) {
            return null;
        }
        try (InputStream trustStore = this.getClass().getClassLoader().getResourceAsStream(conf.trustStorePath().get())) {
                KeyStore keyStore = KeyStore.getInstance(conf.trustStoreType());
                keyStore.load(trustStore, conf.trustStorePassword().isDefined() ? conf.trustStorePassword().get().toCharArray() : null);

                TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                tmf.init(keyStore);

                SSLContext context = SSLContext.getInstance(conf.protocol());
                context.init(null, tmf.getTrustManagers(), new SecureRandom());

                ClassTag<String> tag = scala.reflect.ClassTag$.MODULE$.apply(String.class);

                return JdkSSLOptions.builder()
                        .withSSLContext(context)
                        .withCipherSuites((String[]) conf.enabledAlgorithms().toArray(tag)).build();
            }
        }

然后,他们调用该方法对其连接构建器对象进行最后润色:

    if (conf.cassandraSSLConf().enabled()) {
        SSLOptions options = createSSLOPtions(conf.cassandraSSLConf());
        if (null != options) {
            builder = builder.withSSL(options);
        } else {
            builder = builder.withSSL();
        }
    }
    return builder;

查看他们的网站,看看你是否可以根据自己的需要进行扩充。

© www.soinside.com 2019 - 2024. All rights reserved.