Spring boot Cassandra configuration for enabling SSL

Viewed 730

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
1 Answers

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; }
Related