Java SDK authentication

Hi All,

I am new to Couchbase and need help in Java SDK authentication.
I have downloaded CB server comminity edition 6.0 and installed the same on my local machine.

I am trying to connect to the server using java SDK. I refer to following online documentation for the same.

    // Initialize the Connection
    Cluster cluster = CouchbaseCluster.create("localhost");
    cluster.authenticate("username", "password");
    Bucket bucket = cluster.openBucket("bucketname");

It seems the new SDK 2.7 needs Authenticator object to be passed as a parameter to cluster.ahthenticate method. Where as the docuemntation about states passing as user name and passwprd as string parameters. I could not find any documentation or example on how to use Authenticator object to pass on the authenticate method.

Can someone help?

@dilipapte The above code you pasted looks like a valid way to authenticate against your cluster. Is it not working for you?
If you must, you can use a PasswordAuthenticator object, see

Thanks David for your reply. No it gives an error. I made following change in the code and it worked.

bucket = cbCluster.authenticate(new Authenticator() {
public List getCredentials(CredentialContext credentialContext, String s) {
Credential cr = new Credential(bucketName,password);
List lst = new ArrayList<>();
return lst;

        public boolean isEmpty() {
            return false;

@dilipapte The original code should work just fine. If it didn’t, then there is something else going on. I don’t see how changing the code would make it work. If you are happy with where you at now, then that’s good. Otherwise, if you want this looked into, I would suggest you provide the logs showing the error you get.

Is there any code for certificate authenticator object , please share it.

@Shruti_Dixit does the documentation help you? Authenticating against Couchbase Server | Couchbase Docs

Yeah I am able to setup certificatesa and keystore but I need code that i can run to test that java application is authenticating via certificates. I can see 2 liner code snippet but not sure how the entire code look like. Can you share the code if you have

@daschl do you have something in your git repo for Certificate auth object?