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, ' ' );
See the Authenticate Using SASL and LDAP tutorial.
The following options are supported by the plain SASL authenticator.
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, ' ' );
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.