2

I am working on a spring boot application that is using Cassandra. I want to enable SSL in my application, but can't seem to find how to configure Cassandra to use SSL.

@Configuration
 class CassandraApplicationConfiguration extends AbstractCassandraConfiguration {

        @Value("${spring.data.cassandra.contact-points:localhost}")
        private String contactPoints;

        @Value("${spring.data.cassandra.keyspace-name:my_keyspace}")
        private String keySpace;

        @Value("${spring.data.cassandra.port:9042}")
        private int port;

        @Value("${spring.data.cassandra.username:cassandra}")
        private String username;

        @Value("${spring.data.cassandra.password:cassandra}")
        private String password;

        @Value("${spring.data.cassandra.schema-action:NONE}")
        private String schemaAction;

       @Override
       protected AuthProvider getAuthProvider() {
           return new PlainTextAuthProvider(username, password);
       }
}

Also I am using the default driver that comes with the following dependency.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-cassandra</artifactId>
    <version>2.2.0.RELEASE</version>
</dependency>

and just the following flags to pass the truststore and password

-Djavax.net.ssl.trustStore=~/keys/internal-truststore
-Djavax.net.ssl.trustStorePassword=password
amrit sandhu
  • 131
  • 1
  • 9

1 Answers1

0

If you are using cluster factory bean

@Bean 
@Override public CassandraClusterFactoryBean cluster() {
    CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); 
    PlainTextAuthProvider sap = new PlainTextAuthProvider(env.getProperty("cassandra.username"), env.getProperty("cassandra.password"));
    cluster.setContactPoints(env.getProperty("cassandra.contactpoints"));
    cluster.setPort(Integer.parseInt(env.getProperty("cassandra.port")));
    cluster.setAuthProvider(sap);
    cluster.setSslEnabled(true);
    return cluster; }
  • Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: xxx.xx.x.xxx/xxx.xx.x.xxx:9042 (com.datastax.driver.core.exceptions.TransportException: [ xxx.xx.x.xxx/xxx.xx.x.xxx::9042] Error writing)) --- I keep getting this error – amrit sandhu Dec 31 '20 at 18:08