Springboot ssl connection example for Cassandra 3.x

1,373 views
Skip to first unread message

ravi ch

unread,
May 18, 2017, 1:07:01 PM5/18/17
to DataStax Java Driver for Apache Cassandra User Mailing List
I'm having hard time in establishing a secure connection (ssl) to Cassandra DB in my springboot application. I'm tried the various options with not much luck. Below is a sample code:

Any pointers or working example would be appreciated.

@Configuration
public class CassandraManager {

    private static final String KEYSPACE = "cassandra.keyspace";
    private static final String CONTACTPOINTS = "cassandra.contactpoints";
    private static final String PORT = "cassandra.port";
    private static final String SSLENABLED = "cassandra.sslEnabled";

    @Autowired
    private Environment environment;

    private String getKeyspaceName() {
        return environment.getProperty(KEYSPACE);
    }

    private String getContactPoints() {
        return environment
                .getProperty(CONTACTPOINTS);
    }

    private int getPortNumber() {
        return Integer.parseInt(environment
                .getProperty(PORT));
    }

    private boolean getSSLEnabled() {
        return Boolean.getBoolean(environment
                .getProperty(SSLENABLED));
    }

    public Cluster cluster() {
        System.setProperty("javax.net.ssl.trustStore", "XXX");
        System.setProperty("javax.net.ssl.trustStorePassword", "XXX");
        System.setProperty("javax.net.ssl.keyStore", "XXX");
        System.setProperty("javax.net.ssl.keyStorePassword", "XXX");

        Cluster cluster = Cluster
                .builder()
                .addContactPoints(getContactPoints())
                .withSSL()
                .build();

        return cluster;
    }

    @Bean
    public CassandraMappingContext mappingContext() {
        return new BasicCassandraMappingContext();
    }

    @Bean
    public CassandraConverter converter() {
        return new MappingCassandraConverter(mappingContext());
    }

    @Bean
    public CassandraSessionFactoryBean session() throws Exception {
        CassandraSessionFactoryBean cassandraSessionFactoryBean = new CassandraSessionFactoryBean();
        cassandraSessionFactoryBean.setCluster(cluster());
        cassandraSessionFactoryBean.setKeyspaceName(getKeyspaceName());
        cassandraSessionFactoryBean.setConverter(converter());
        cassandraSessionFactoryBean.setSchemaAction(SchemaAction.NONE);
        return cassandraSessionFactoryBean;
    }

    @Bean
    public CassandraOperations cassandraTemplate() throws Exception {
        return new CassandraTemplate(session().getObject());
    }
}

Nate McCall

unread,
May 18, 2017, 7:02:59 PM5/18/17
to java-dri...@lists.datastax.com
Add the following option to your command-line invocation:

-Djavax.net.debug=ssl

It will give you *a lot* of detail, but should narrow down what is wrong. 
> --
> You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.




--
-----------------
Nate McCall
Wellington, NZ
@zznate

CTO
Apache Cassandra Consulting
http://www.thelastpickle.com

srinivasa_ra...@homedepot.com

unread,
Feb 28, 2018, 8:29:33 AM2/28/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

we are trying to connect to cassandra ssl enabled from spring boot. we are not able to succeed. the following parameters. any help is appreciated?

spring.data.cassandra.ssl=true

spring.data.cassandra.ssl.trustStore=classpath:client.truststore

spring.data.cassandra.ssl.trustStorePassword=cassandra

javax.net.ssl.trustStore=classpath:client.truststore

javax.net.ssl.trustStorePassword=cassandra

Mayur -UD

unread,
Feb 27, 2019, 8:01:07 AM2/27/19
to DataStax Java Driver for Apache Cassandra User Mailing List, srinivasa_ra...@homedepot.com
Hi,

I am stuck at the same point. 

I have to configure trust store to be able to connect to Cassandra Database.

Request you to please post an update if anyone is able to get through.

Thanks,
Mayur

Mayur -UD

unread,
Feb 27, 2019, 8:01:50 AM2/27/19
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I am stuck at the same point. 

I have to configure trust store to be able to connect to Cassandra Database.

Request you to please post an update if you were able to get through.

Thanks,
Mayur
Reply all
Reply to author
Forward
0 new messages