builder.withSSL();
/** * Create new cassandra cluster using builder. */ @PostConstruct public void init() { Cluster.Builder builder = Cluster.builder() .addContactPointsWithPorts(parseNodeList(nodeList)) .withClusterName(clusterName) .withSocketOptions(clientOptions.getSocketOptions()); if (!useJmx) { builder.withoutJMXReporting(); } if (disableMetrics) { builder.withoutMetrics(); } if (useCredentials) { builder.withCredentials(username, password); } if (useSsl) { builder.withSSL(); } builder.withQueryOptions(clientOptions.getQueryOptions()); builder.withCompression(parseCompression(compression)); cluster = builder.build(); }
@Override protected UsageAwareDatastoreConnection<CassandraDataContext> createDatastoreConnection() { Builder clusterBuilder = Cluster.builder(); clusterBuilder = clusterBuilder.addContactPoint(_hostname); clusterBuilder = clusterBuilder.withPort(_port); if (_ssl) { clusterBuilder = clusterBuilder.withSSL(); } if (_username != null && _password != null) { clusterBuilder = clusterBuilder.withCredentials(_username, _password); } final Cluster cluster = clusterBuilder.build(); final CassandraDataContext dataContext; if (_tableDefs == null || _tableDefs.length == 0) { dataContext = new CassandraDataContext(cluster, _keyspace); } else { dataContext = new CassandraDataContext(cluster, _keyspace, _tableDefs); } return new DatastoreConnectionImpl<>(dataContext, this); }
private Session createSession() { Cluster.Builder clusterBuilder = new Cluster.Builder(); String nodes = System.getProperty("hawkular.metrics.cassandra.nodes", "hawkular-cassandra"); Arrays.stream(nodes.split(",")).forEach(clusterBuilder::addContactPoint); if (System.getProperty("hawkular.metrics.cassandra.use-ssl") != null && !System.getProperty("hawkular.metrics.cassandra.use-ssl").equals("false")) { SSLOptions sslOptions = null; try { String[] defaultCipherSuites = {"TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA"}; sslOptions = JdkSSLOptions.builder().withSSLContext(SSLContext.getDefault()) .withCipherSuites(defaultCipherSuites).build(); clusterBuilder.withSSL(sslOptions); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("SSL support is required but is not available in the JVM.", e); } } Cluster cluster = clusterBuilder.build(); cluster.init(); Session session = cluster.connect(); return session; }
@Override public Cluster.Builder configure(Cluster.Builder clusterBuilder) { if (CassandraConfiguration.this.cassandraProperties.isUseSsl()) { JdkSSLOptions.Builder optsBuilder = JdkSSLOptions.builder(); if (CassandraConfiguration.this.cassandraProperties.isSkipSslValidation()) { try { optsBuilder.withSSLContext(TrustAllSSLContextFactory.getSslContext()); } catch (NoSuchAlgorithmException | KeyManagementException e) { throw new RuntimeException("Unable to configure a Cassandra cluster using SSL.", e); } } return clusterBuilder.withSSL(optsBuilder.build()); } else { return clusterBuilder; } } };
@Override protected UsageAwareDatastoreConnection<CassandraDataContext> createDatastoreConnection() { Builder clusterBuilder = Cluster.builder(); clusterBuilder = clusterBuilder.addContactPoint(_hostname); clusterBuilder = clusterBuilder.withPort(_port); if (_ssl) { clusterBuilder = clusterBuilder.withSSL(); } if (_username != null && _password != null) { clusterBuilder = clusterBuilder.withCredentials(_username, _password); } final Cluster cluster = clusterBuilder.build(); final CassandraDataContext dataContext; if (_tableDefs == null || _tableDefs.length == 0) { dataContext = new CassandraDataContext(cluster, _keySpace); } else { dataContext = new CassandraDataContext(cluster, _keySpace, _tableDefs); } return new DatastoreConnectionImpl<CassandraDataContext>(dataContext, this); }
@Inject public SchemaManager(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.host") String host, @Named("cassandra.port") int port, @Named("cassandra.username") String username, @Named("cassandra.password") String password, @Named("cassandra.ssl") boolean ssl) { m_keyspace = keyspace; Builder builder = Cluster.builder() .withPort(port) .addContactPoints(host.split(",")); if (username != null && password != null) { LOG.info("Using username: {} and password: XXXXXXXX", username); builder.withCredentials(username, password); } if (ssl) { LOG.info("Using SSL."); builder.withSSL(); } m_cluster= builder.build(); m_session = m_cluster.connect(); }
/** * Attempts to connect to a cassandra cluster with using {@link Cluster.Builder#withSSL} with no * provided {@link SSLOptions} and then closes the created {@link Cluster} instance. * * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will * be raised here if connection cannot be established. */ protected void connectWithSSL() throws Exception { Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withSSL() .build()); cluster.connect(); }
@Inject public SchemaManager(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.host") String host, @Named("cassandra.port") int port, @Named("cassandra.username") String username, @Named("cassandra.password") String password, @Named("cassandra.ssl") boolean ssl) { m_keyspace = keyspace; Builder builder = Cluster.builder() .withPort(port) .addContactPoints(host.split(",")); if (username != null && password != null) { LOG.info("Using username: {} and password: XXXXXXXX", username); builder.withCredentials(username, password); } if (ssl) { LOG.info("Using SSL."); builder.withSSL(); } m_cluster= builder.build(); m_session = m_cluster.connect(); }
@Bean @Order(0) @Conditional(CassandraDaemonCondition.class) public ClusterBuilderCustomizer cassandraDaemonClusterBuilderCustomizer() { return builder -> { InetAddress rpcAddress = DatabaseDescriptor.getRpcAddress(); int port = DatabaseDescriptor.getNativeTransportPort(); builder.addContactPoints(rpcAddress).withPort(port); if (DatabaseDescriptor.getClientEncryptionOptions().enabled) { int sslPort = DatabaseDescriptor.getNativeTransportPortSSL(); if (sslPort == port) { builder.withSSL(); } } }; }
/** * Attempts to connect to a cassandra cluster with the given SSLOptions and then closes the * created {@link Cluster} instance. * * @param sslOptions SSLOptions to use. * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will * be raised here if connection cannot be established. */ protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception { Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withSSL(sslOptions) .build()); cluster.connect(); }
@Bean @Order(0) public ClusterBuilderCustomizer embeddedCassandraClusterBuilderCustomizer() { return builder -> { Settings settings = this.cassandra.getSettings(); builder.addContactPoints(settings.getRealAddress()).withPort(settings.getPort()); if (settings.getSslPort() != null && settings.getSslPort() == settings.getPort()) { builder.withSSL(); } }; } }
getConfiguration().getSSLTrustStorePassword()); builder.withSSL(JdkSSLOptions.builder() .withSSLContext(context) .withCipherSuites(CIPHER_SUITES).build());
builder.withSSL(sslOptions);
/** * Validates that if connection is lost to a node that is using SSL authentication, that * connection can be re-established when the node becomes available again. * * @test_category connection:ssl * @expected_result Connection is re-established within a sufficient amount of time after a node * comes back online. */ @CCMConfig(dirtiesContext = true) @Test(groups = "long", dataProvider = "sslImplementation", dataProviderClass = SSLTestBase.class) public void should_reconnect_with_ssl_on_node_up(SslImplementation sslImplementation) throws Exception { Cluster cluster = register( Cluster.builder() .addContactPoints(this.getContactPoints()) .withPort(ccm().getBinaryPort()) .withSSL(getSSLOptions(sslImplementation, true, true)) .build()); cluster.connect(); ccm().stop(1); ccm().start(1); assertThat(cluster).host(1).comesUpWithin(TestUtils.TEST_BASE_NODE_WAIT, TimeUnit.SECONDS); }
/** * Attempts to connect to a cassandra cluster with the given SSLOptions and then closes the * created {@link Cluster} instance. * * @param sslOptions SSLOptions to use. * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will * be raised here if connection cannot be established. */ protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception { Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withSSL(sslOptions) .build()); cluster.connect(); }
/** * Attempts to connect to a cassandra cluster with using {@link Cluster.Builder#withSSL} with no * provided {@link SSLOptions} and then closes the created {@link Cluster} instance. * * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will * be raised here if connection cannot be established. */ protected void connectWithSSL() throws Exception { Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withSSL() .build()); cluster.connect(); }
/** * Uses a Cluster.Builder to create a Cassandra cluster reference using the given parameters * * @param contactPoints The contact points (hostname:port list of Cassandra nodes) * @param sslContext The SSL context (used for secure connections) * @param username The username for connection authentication * @param password The password for connection authentication * @return A reference to the Cluster object associated with the given Cassandra configuration */ protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password) { Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints); if (sslContext != null) { JdkSSLOptions sslOptions = JdkSSLOptions.builder() .withSSLContext(sslContext) .build(); builder = builder.withSSL(sslOptions); } if (username != null && password != null) { builder = builder.withCredentials(username, password); } return builder.build(); }
private Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password) { Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints); if (sslContext != null) { JdkSSLOptions sslOptions = JdkSSLOptions.builder() .withSSLContext(sslContext) .build(); builder = builder.withSSL(sslOptions); } if (username != null && password != null) { builder = builder.withCredentials(username, password); } return builder.build(); } }