Plain SASL Authentication

  • Note: The plain SASL authenticator is provided via the driver's extensions jar available to license holders. See the Notes at the bottom of this documentation for details. Further, the use of plan SASL authentication requires the Enterprise version of the MongoDB server. See the MongoDB Tutorial for details.

With the release of MongoDB 2.6 Enterprise it is now possible to authenticate with the MongoDB server by proxying the authentication to either an LDAP server or even Linux PAM.

To configure the driver to use the plain SASL authentication simply add a Credential which is built with the plainSasl() option.

MongoClientConfiguration config = new MongoClientConfiguration("mongodb://locahost:27017/");

char[] password = new char[] { 's', 'u', 'p', 'e', 'r', 's', 'e', 'c', 'r', 'e', 't' };
config.addCredential(
   Credential.builder()
             .userName("<user>")
             .password(password)
             .plainSasl());
Arrays.fill( password, ' ' );

Configuring the Server

See the Authenticate Using SASL and LDAP tutorial.

Options

The following options are supported by the plain SASL authenticator.

Plain SASL Authentication Options
Option Name Default Value Description
plain.service.name mongodb The name of the SASL service the MongoDB server is providing.

Options are added to the credentials as they are built.

MongoClientConfiguration config = new MongoClientConfiguration("mongodb://locahost:27017/");

char[] password = new char[] { 's', 'u', 'p', 'e', 'r', 's', 'e', 'c', 'r', 'e', 't' };
config.addCredential(
   Credential.builder()
             .userName("<user>")
             .password(password)
             .plainSasl()
             .addOption("plain.service.name", "mongo"));
Arrays.fill( password, ' ' );

Notes

The plain SASL authenticator is provided via the driver's extensions jar available to license holders. Any attempt to add a credential to a configuration using plain SASL authentication will throw an IllegalArgumentException without the extensions jar on the classpath. Please contact Allanbank Consulting, Inc. for information on licensing the driver and obtaining the extensions jar.