如何使用Java身份验证连接到Cassandra集群?

时间:2016-07-27 12:23:42

标签: java authentication cassandra

我正在使用Cassandra 3.7。我正在使用AuthProvider进行身份验证。我尝试了两种方法:

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

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

我收到以下错误:

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)

导致错误的原因是什么?如何解决?

1 个答案:

答案 0 :(得分:1)

更改cassandra.yaml中的身份验证器和授权程序的值:

  

authenticator:PasswordAuthenticator

     

授权人:CassandraAuthorizer