khateeb
khateeb

Reputation: 5469

How to connect to a Cassandra cluster with authentication in Java?

I am using Cassandra 3.7. I am using AuthProvider to for authentication. I have tried two methods:

AuthProvider authProvider = new PlainTextAuthProvider("abcd", "xyz");
Cluster cluster = Cluster.builder().addContactPoint(node).withAuthProvider(authProvider).build();
Session session = cluster.connect();

and

Cluster cluster = Cluster.builder().addContactPoint(node)..withCredentials("abcd", "xyz").build();
Session session = cluster.connect();

I am getting the following error:

Exception in thread "main" com.datastax.driver.core.exceptions.AuthenticationException: Authentication error on host /127.0.0.1:9042: Host /127.0.0.1:9042 requires authentication, but no authenticator found in Cluster configuration
    at com.datastax.driver.core.AuthProvider$1.newAuthenticator(AuthProvider.java:40)

What is causing the error and how do I fix it?

Upvotes: 0

Views: 2677

Answers (1)

Anastasia Osintseva
Anastasia Osintseva

Reputation: 100

Change value of authenticator and authorizer in cassandra.yaml:

authenticator: PasswordAuthenticator

authorizer: CassandraAuthorizer

Upvotes: 1

Related Questions