Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 无法在启用密码身份验证的情况下将java客户端连接到cassandra_Authentication_Cassandra_Datastax_Datastax Java Driver - Fatal编程技术网

Authentication 无法在启用密码身份验证的情况下将java客户端连接到cassandra

Authentication 无法在启用密码身份验证的情况下将java客户端连接到cassandra,authentication,cassandra,datastax,datastax-java-driver,Authentication,Cassandra,Datastax,Datastax Java Driver,我在macbook上默认安装了Datastax enterprise。我能够创建我的键空间并设置我的所有应用程序,包括使用solr 我正在尝试开发一组步骤来为我们的开发集群启用密码身份验证 到目前为止,我已经更新了/usr/local/dse/resources/cassandra/conf/cassandra.yaml,并更改了以下属性: authenticator:PasswordAuthenticator 授权人:卡桑德拉授权人 我重新启动了节点,可以使用cqlsh登录并查询我的密钥空间

我在macbook上默认安装了Datastax enterprise。我能够创建我的键空间并设置我的所有应用程序,包括使用solr

我正在尝试开发一组步骤来为我们的开发集群启用密码身份验证

到目前为止,我已经更新了
/usr/local/dse/resources/cassandra/conf/cassandra.yaml
,并更改了以下属性:

authenticator:PasswordAuthenticator
授权人:卡桑德拉授权人
我重新启动了节点,可以使用cqlsh登录并查询我的密钥空间:

cqlsh -u cassandra -p cassandra
此时,我尝试在会话生成器上设置凭据: 主机是:
cassandra.Host=localhost

会话会话=keyspaceToSessionMap.get(keyspace); if(会话==null){ Cluster Cluster=Cluster.builder().addContactPoints(主机) .withCredentials(用户名、密码) //.ssl() .build(); 会话=cluster.connect(键空间); keyspaceToSessionMap.put(键空间,会话); } 但是,我无法成功连接。因此,我添加了一个新用户,可以通过cqlsh再次登录,但仍然无法连接Java驱动程序

cqlsh -u username -p password
Connected to LocalCluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 2.1.8.689 | DSE 4.7.3 | CQL spec 3.2.0 | Native protocol v3]
我正在通过gradle为驱动程序使用
'com.datasax.cassandra:cassandra驱动程序dse:2.1.9'

我总是得到以下堆栈跟踪,通过调试可以看到用户名和密码设置正确:

Caused by: com.datastax.driver.core.exceptions.AuthenticationException: Authentication error on host localhost/127.0.0.1:9042: Username and/or password are incorrect
at com.datastax.driver.core.Connection$8.apply(Connection.java:376)
at com.datastax.driver.core.Connection$8.apply(Connection.java:346)
这看起来应该很简单,但我被难倒了

与cassandra驱动程序相关的我的依赖关系图包含以下内容:

+--- com.datastax.cassandra:cassandra-driver-dse:2.1.9
|    \--- com.datastax.cassandra:cassandra-driver-core:2.1.9 -> 2.1.8
|         +--- io.netty:netty-handler:4.0.27.Final
|         |    +--- io.netty:netty-buffer:4.0.27.Final
|         |    |    \--- io.netty:netty-common:4.0.27.Final
|         |    +--- io.netty:netty-transport:4.0.27.Final
|         |    |    \--- io.netty:netty-buffer:4.0.27.Final (*)
|         |    \--- io.netty:netty-codec:4.0.27.Final
|         |         \--- io.netty:netty-transport:4.0.27.Final (*)
|         +--- com.google.guava:guava:14.0.1 -> 18.0
|         \--- com.codahale.metrics:metrics-core:3.0.2
|              \--- org.slf4j:slf4j-api:1.7.5 -> 1.7.12
我创建了以下通过的测试

Cluster Cluster=Cluster.builder().addContactPoints(“localhost”)
.withCredentials(“用户名”、“密码”)
//.ssl()
.build();
会话=cluster.connect(“键空间”);
Assert.assertNotNull(会话);

我能分辨出两者之间的唯一区别是“localhost”现在是一个常量,而不是大小为1的数组。

发现后面有一个空格,这是根本原因

Cluster Cluster=Cluster.builder().addContactPoints(主机)
.withCredentials(username.trim()、password.trim())
//.ssl()
.build();

能否提供更完整的代码示例?在我看来,您提供的一切都是正确的,但可能代码中存在一些细微差别,可能会揭示问题。啊,这就解释了!感谢您分享解决方案,我曾一度担心驱动程序中可能存在错误:)