【问题标题】:How to connect Cassandra over ssl using connection properties(url properties)如何使用连接属性(url 属性)通过 ssl 连接 Cassandra
【发布时间】:2019-08-02 20:53:58
【问题描述】:

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

感谢您的帮助!!

【问题讨论】:

标签: cassandra cassandra-2.0 cassandra-3.0 spark-cassandra-connector cassandra-2.1


【解决方案1】:

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;

查看他们的网站,看看您是否可以对其进行扩充以满足您的需求。

【讨论】:

    猜你喜欢
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2012-05-13
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多