Search:

Search all manuals
Search this manual
Manual
Membase Client Library: Java
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
1 Membase Client Library: Java — Getting Started
Chapter Sections
Chapters

1.4. Connecting using Hostname and Port with SASL

If you want to use SASL to provide secure connectivity to your Membase server then you must create a ConnectionFactory that uses the binary protocol and a previously defined AuthDescriptor object that defines the SASL connection type, username and password.

You can create the required AuthDescriptor object:

AuthDescriptor ad = new AuthDescriptor(new String[]{"PLAIN"},
                                new PlainCallbackHandler(username, password));

Where username and password are the login credentials.

The connection to Membase must use the binary protocol for SASL connections, but you must use the native ConnectionFactoryBuilder class so that you can specify the authorization descriptor and protocol type to build a new connection factory:

MemcachedClient mc = new MemcachedClient(
     new ConnectionFactoryBuilder().setProtocol(Protocol.BINARY)
     .setAuthDescriptor(ad)
     .build(),
     AddrUtil.getAddresses("servera:11211 serverb:11211"));