You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Chamila Wijayarathna <cd...@gmail.com> on 2015/02/10 21:24:08 UTC

Accesing Cassandra Database which uses 'PasswordAuthenticator' in Java

Hello all,

I changed the authenticator value of my Cassandra database to
'PasswordAuthenticator' in cassandra.yaml file. Previously I used following
code to connect to the database using java.


public void connect(String node) {

      cluster = Cluster.builder()

            .addContactPoint(node).build();

      Metadata metadata = cluster.getMetadata();

      System.out.printf("Connected to cluster: %s\n",

            metadata.getClusterName());

      for ( Host host : metadata.getAllHosts() ) {

         System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",

               host.getDatacenter(), host.getAddress(), host.getRack());

      }

      session = cluster.connect();

   }

Now this code gives me error saying


Exception in thread "main"
com.datastax.driver.core.exceptions.AuthenticationException: Authentication
error on host /127.0.0.1: Host /127.0.0.1 requires authentication, but no
authenticator found in Cluster configuration

I understand that I need to connect to the database with my super user
username and password. How can I give those details when connecting to
database using java?
Thank You!
-- 
*Chamila Dilshan Wijayarathna,*
SMIEEE, SMIESL,
Undergraduate,
Department of Computer Science and Engineering,
University of Moratuwa.

Re: Accesing Cassandra Database which uses 'PasswordAuthenticator' in Java

Posted by Chamila Wijayarathna <cd...@gmail.com>.
Hi Deepak,

Thanks.

Got it working by adding withCredentials method.

cluster = Cluster.builder()
        .addContactPoint(node)
        .withCredentials("yourusername", "yourpassword")
        .build();


On Wed, Feb 11, 2015 at 2:03 AM, Deepak Shetty <sh...@gmail.com> wrote:

> see the API docs
> http://www.datastax.com/drivers/java/2.0/index.html
> Cluster.builder has a withCredentials method
>
> regards
> deepak
>
> On Tue, Feb 10, 2015 at 12:24 PM, Chamila Wijayarathna <
> cdwijayarathna@gmail.com> wrote:
>
>> Hello all,
>>
>> I changed the authenticator value of my Cassandra database to
>> 'PasswordAuthenticator' in cassandra.yaml file. Previously I used following
>> code to connect to the database using java.
>>
>>
>> public void connect(String node) {
>>
>>       cluster = Cluster.builder()
>>
>>             .addContactPoint(node).build();
>>
>>       Metadata metadata = cluster.getMetadata();
>>
>>       System.out.printf("Connected to cluster: %s\n",
>>
>>             metadata.getClusterName());
>>
>>       for ( Host host : metadata.getAllHosts() ) {
>>
>>          System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
>>
>>                host.getDatacenter(), host.getAddress(), host.getRack());
>>
>>       }
>>
>>       session = cluster.connect();
>>
>>    }
>>
>> Now this code gives me error saying
>>
>>
>> Exception in thread "main"
>> com.datastax.driver.core.exceptions.AuthenticationException: Authentication
>> error on host /127.0.0.1: Host /127.0.0.1 requires authentication, but
>> no authenticator found in Cluster configuration
>>
>> I understand that I need to connect to the database with my super user
>> username and password. How can I give those details when connecting to
>> database using java?
>> Thank You!
>> --
>> *Chamila Dilshan Wijayarathna,*
>> SMIEEE, SMIESL,
>> Undergraduate,
>> Department of Computer Science and Engineering,
>> University of Moratuwa.
>>
>
>


-- 
*Chamila Dilshan Wijayarathna,*
SMIEEE, SMIESL,
Undergraduate,
Department of Computer Science and Engineering,
University of Moratuwa.

Re: Accesing Cassandra Database which uses 'PasswordAuthenticator' in Java

Posted by Deepak Shetty <sh...@gmail.com>.
see the API docs
http://www.datastax.com/drivers/java/2.0/index.html
Cluster.builder has a withCredentials method

regards
deepak

On Tue, Feb 10, 2015 at 12:24 PM, Chamila Wijayarathna <
cdwijayarathna@gmail.com> wrote:

> Hello all,
>
> I changed the authenticator value of my Cassandra database to
> 'PasswordAuthenticator' in cassandra.yaml file. Previously I used following
> code to connect to the database using java.
>
>
> public void connect(String node) {
>
>       cluster = Cluster.builder()
>
>             .addContactPoint(node).build();
>
>       Metadata metadata = cluster.getMetadata();
>
>       System.out.printf("Connected to cluster: %s\n",
>
>             metadata.getClusterName());
>
>       for ( Host host : metadata.getAllHosts() ) {
>
>          System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
>
>                host.getDatacenter(), host.getAddress(), host.getRack());
>
>       }
>
>       session = cluster.connect();
>
>    }
>
> Now this code gives me error saying
>
>
> Exception in thread "main"
> com.datastax.driver.core.exceptions.AuthenticationException: Authentication
> error on host /127.0.0.1: Host /127.0.0.1 requires authentication, but no
> authenticator found in Cluster configuration
>
> I understand that I need to connect to the database with my super user
> username and password. How can I give those details when connecting to
> database using java?
> Thank You!
> --
> *Chamila Dilshan Wijayarathna,*
> SMIEEE, SMIESL,
> Undergraduate,
> Department of Computer Science and Engineering,
> University of Moratuwa.
>