I have a default install of Datastax enterprise on my macbook. I was able to create my keyspace and setup all my applications including using solr.
我的macbook上有一个默认的Datastax enterprise安装。我能够创建我的键空间并设置我的所有应用程序,包括使用solr。
I am trying to develop a set of steps to turn on password authentication for our dev cluster.
我正在尝试开发一组步骤来为我们的开发群集启用密码身份验证。
Thus far I have updated /usr/local/dse/resources/cassandra/conf/cassandra.yaml and changed the following properties: authenticator: PasswordAuthenticator authorizer: CassandraAuthorizer
到目前为止,我已更新/usr/local/dse/resources/cassandra/conf/cassandra.yaml并更改了以下属性:authenticator:PasswordAuthenticator authorizer:CassandraAuthorizer
I restarted the node and could login and query my keyspace using cqlsh: cqlsh -u cassandra -p cassandra
我重新启动了节点,可以使用cqlsh登录并查询我的密钥空间:cqlsh -u cassandra -p cassandra
At this point I tried setting the Credentials on the Session builder: Host is:cassandra.host=localhost
此时,我尝试在“会话”构建器上设置“凭据”:主机为:cassandra.host = localhost
Session session = keyspaceToSessionMap.get(keyspace);
if( session == null){
Cluster cluster = Cluster.builder().addContactPoints(hosts)
.withCredentials(username, password)
//.withSSL()
.build();
session = cluster.connect(keyspace);
keyspaceToSessionMap.put(keyspace,session);
}
I could not successfully connect however. So I added a new user and was able to again login via cqlsh but still cannot get the Java driver to connect.
但是我无法成功连接。所以我添加了一个新用户,并且能够再次通过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]
I am using 'com.datastax.cassandra:cassandra-driver-dse:2.1.9' via gradle for the driver.
我通过gradle为驱动程序使用'com.datastax.cassandra:cassandra-driver-dse:2.1.9'。
I always get the following stack trace and through debugging can see the username and password are set properly:
我总是得到以下堆栈跟踪,通过调试可以看到用户名和密码设置正确:
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)
This seems like it should be simple but I am stumped.
这似乎应该很简单,但我很难过。
My dependencies graph in relation to cassandra driver contains the following:
与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
I created the following test which passes.
我创建了以下测试通过。
Cluster cluster = Cluster.builder().addContactPoints("localhost")
.withCredentials("username", "password")
//.withSSL()
.build();
Session session = cluster.connect("keyspace");
Assert.assertNotNull(session);
The only difference I can tell between the two is that "localhost" is now a constant rather than an array of size 1.
我可以在两者之间区别的唯一区别是“localhost”现在是一个常量而不是大小为1的数组。
1 个解决方案
#1
6
Found I had a trailing whitespace and that was the root cause.
发现我有一个尾随空格,这是根本原因。
Cluster cluster = Cluster.builder().addContactPoints(hosts)
.withCredentials(username.trim(), password.trim())
//.withSSL()
.build();
#1
6
Found I had a trailing whitespace and that was the root cause.
发现我有一个尾随空格,这是根本原因。
Cluster cluster = Cluster.builder().addContactPoints(hosts)
.withCredentials(username.trim(), password.trim())
//.withSSL()
.build();