Connecting to Cassandra using Java DBCP

369 views Asked by At

I am connection to a Cassandra database with Java using the "BasicDataSource" class in the Apache Common DBCP library and using the DataStax driver "com.simba.cassandra.jdbc42.Driver". When Cassandra is configured with the "authenticator" set to "AllowAllAuthenticator", I can connection to the database. However when I enable "PasswordAuthenticator" and set the username/password in the "BasicDataSource" object, I cannot connect and get the exception "Authentication error on host /IP Address:Port: Host /IP Address:Port requires authentication, but no authenticator found in Cluster configuration.". What is needed to establish a secure connection ?

1

There are 1 answers

1
lgriffin On BEST ANSWER

I have answered my own question. For anyone with the same problem, the solution is to include the option "AuthMech=1" in the JDBC connection string as it is needed for authenticated connections. The following is from the "Simba Cassandra JDBC Driver with SQL Connector" installation and configuration guide:

"AuthMech

This property specifies whether the driver connects to a Cassandra or Astra database, and whether the driver authenticates the connection.

  • 0: The driver connects to a Cassandra database without authenticating the connection.
  • 1: The driver connects to a Cassandra database, and authenticates the connection using a user name and password.
  • 2: The driver connects to an Astra database, and authenticates the connection using a user name, password, and secure connection bundle."

Ref: https://docs.datastax.com/en/driver-matrix/doc/latestSimbaCassJDBCDriver.html (Page 31)