title: Cannot connect java client to cassandra with password authentication enabled
body: <p>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.</p>
  
  <p>I am trying to develop a set of steps to turn on password authentication for our dev cluster.</p>
  
  <p>Thus far I have updated <code>/usr/local/dse/resources/cassandra/conf/cassandra.yaml</code> and changed the following properties:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>authenticator: PasswordAuthenticator
  authorizer: CassandraAuthorizer
  </code></pre>
  
  <p>I restarted the node and could login and query my keyspace using cqlsh:</p>
  
  <pre><code>cqlsh -u cassandra -p cassandra
  </code></pre>
  
  <p>At this point I tried setting the Credentials on the Session builder:
  Host is: <code>cassandra.host=localhost</code></p>
  
  <pre class="lang-java prettyprint-override"><code>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);
      }
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>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]
  </code></pre>
  
  <p>I am using <code>'com.datastax.cassandra:cassandra-driver-dse:2.1.9'</code> via gradle for the driver.</p>
  
  <p>I always get the following stack trace and through debugging can see the username and password are set properly:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>This seems like it should be simple but I am stumped.</p>
  
  <p>My dependencies graph in relation to cassandra driver contains the following:</p>
  
  <pre><code>+--- com.datastax.cassandra:cassandra-driver-dse:2.1.9
  |    \--- com.datastax.cassandra:cassandra-driver-core:2.1.9 -&gt; 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 -&gt; 18.0
  |         \--- com.codahale.metrics:metrics-core:3.0.2
  |              \--- org.slf4j:slf4j-api:1.7.5 -&gt; 1.7.12
  </code></pre>
  
  <p>I created the following test which passes.</p>
  
  <pre class="lang-java prettyprint-override"><code>Cluster cluster = Cluster.builder().addContactPoints("localhost")
                      .withCredentials("username", "password")
                      //.withSSL()
                      .build();
              Session session = cluster.connect("keyspace");
              Assert.assertNotNull(session);
  </code></pre>
  
  <p>The only difference I can tell between the two is that "localhost" is now a constant rather than an array of size 1.</p>