Configure password-based authentication with Cassandra

This commit updates the Cassandra auto-configuration to configure
password-based authentication on the CqlSession directly.

Closes gh-21487
This commit is contained in:
Stephane Nicoll
2020-06-10 09:40:45 +02:00
parent d30c0e8aec
commit 6534a9abaf
2 changed files with 98 additions and 0 deletions

View File

@@ -80,12 +80,19 @@ public class CassandraAutoConfiguration {
public CqlSessionBuilder cassandraSessionBuilder(CassandraProperties properties,
DriverConfigLoader driverConfigLoader, ObjectProvider<CqlSessionBuilderCustomizer> builderCustomizers) {
CqlSessionBuilder builder = CqlSession.builder().withConfigLoader(driverConfigLoader);
configureAuthentication(properties, builder);
configureSsl(properties, builder);
builder.withKeyspace(properties.getKeyspaceName());
builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
return builder;
}
private void configureAuthentication(CassandraProperties properties, CqlSessionBuilder builder) {
if (properties.getUsername() != null) {
builder.withAuthCredentials(properties.getUsername(), properties.getPassword());
}
}
private void configureSsl(CassandraProperties properties, CqlSessionBuilder builder) {
if (properties.isSsl()) {
try {