@Immutable public final class MongoCredential extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CANONICALIZE_HOST_NAME_KEY
Mechanism property key for specifying whether to canonicalize the host name for GSSAPI authentication.
|
static String |
GSSAPI_MECHANISM
The GSSAPI mechanism.
|
static String |
JAVA_SASL_CLIENT_PROPERTIES_KEY
Mechanism property key for overriding the SaslClient properties for GSSAPI authentication.
|
static String |
JAVA_SUBJECT_KEY
Mechanism property key for overriding the
Subject under which GSSAPI authentication executes. |
static String |
MONGODB_CR_MECHANISM
The MongoDB Challenge Response mechanism.
|
static String |
MONGODB_X509_MECHANISM
The MongoDB X.509
|
static String |
PLAIN_MECHANISM
The PLAIN mechanism.
|
static String |
SCRAM_SHA_1_MECHANISM
The SCRAM-SHA-1 Mechanism.
|
static String |
SERVICE_NAME_KEY
Mechanism property key for overriding the service name for GSSAPI authentication.
|
| Modifier and Type | Method and Description |
|---|---|
static MongoCredential |
createCredential(String userName,
String database,
char[] password)
Creates a MongoCredential instance with an unspecified mechanism.
|
static MongoCredential |
createGSSAPICredential(String userName)
Creates a MongoCredential instance for the GSSAPI SASL mechanism.
|
static MongoCredential |
createMongoCRCredential(String userName,
String database,
char[] password)
Creates a MongoCredential instance for the MongoDB Challenge Response protocol.
|
static MongoCredential |
createMongoX509Credential()
Creates a MongoCredential instance for the MongoDB X.509 protocol where the distinguished subject name of the client certificate
acts as the userName.
|
static MongoCredential |
createMongoX509Credential(String userName)
Creates a MongoCredential instance for the MongoDB X.509 protocol.
|
static MongoCredential |
createPlainCredential(String userName,
String source,
char[] password)
Creates a MongoCredential instance for the PLAIN SASL mechanism.
|
static MongoCredential |
createScramSha1Credential(String userName,
String source,
char[] password)
Creates a MongoCredential instance for the SCRAM-SHA-1 SASL mechanism.
|
boolean |
equals(Object o) |
AuthenticationMechanism |
getAuthenticationMechanism()
Gets the mechanism
|
String |
getMechanism()
Gets the mechanism
|
<T> T |
getMechanismProperty(String key,
T defaultValue)
Get the value of the given key to a mechanism property, or defaultValue if there is no mapping.
|
char[] |
getPassword()
Gets the password.
|
String |
getSource()
Gets the source of the user name, typically the name of the database where the user is defined.
|
String |
getUserName()
Gets the user name
|
int |
hashCode() |
String |
toString() |
<T> MongoCredential |
withMechanismProperty(String key,
T value)
Creates a new MongoCredential as a copy of this instance, with the specified mechanism property added.
|
public static final String MONGODB_CR_MECHANISM
public static final String MONGODB_X509_MECHANISM
public static final String SCRAM_SHA_1_MECHANISM
public static final String SERVICE_NAME_KEY
createGSSAPICredential(String),
withMechanismProperty(String, Object),
Constant Field Valuespublic static final String CANONICALIZE_HOST_NAME_KEY
createGSSAPICredential(String),
withMechanismProperty(String, Object),
Constant Field Valuespublic static final String JAVA_SASL_CLIENT_PROPERTIES_KEY
Map<String, Object>. In most cases there is no need to set this mechanism property.
But if an application does:
Sasl.CREDENTIALS property to an instance of
GSSCredential.Sasl.MAX_BUFFER property to "0" to ensure compatibility with all
versions of MongoDB.createGSSAPICredential(String),
withMechanismProperty(String, Object),
Sasl,
Sasl.CREDENTIALS,
Sasl.MAX_BUFFER,
Constant Field Valuespublic static final String JAVA_SUBJECT_KEY
Subject under which GSSAPI authentication executes.createGSSAPICredential(String),
withMechanismProperty(String, Object),
Constant Field Valuespublic static MongoCredential createCredential(String userName, String database, char[] password)
userName - the user namedatabase - the database where the user is definedpassword - the user's passwordpublic static MongoCredential createScramSha1Credential(String userName, String source, char[] password)
createCredential(String, String, char[]) method to allow the driver to
negotiate the best mechanism based on the server version.userName - the non-null user namesource - the source where the user is defined.password - the non-null user passwordcreateCredential(String, String, char[])public static MongoCredential createMongoCRCredential(String userName, String database, char[] password)
createCredential(String, String, char[]) method to allow the driver to
negotiate the best mechanism based on the server version.userName - the user namedatabase - the database where the user is definedpassword - the user's passwordcreateCredential(String, String, char[])public static MongoCredential createMongoX509Credential(String userName)
public static MongoCredential createMongoX509Credential()
Available on MongoDB server versions >= 3.4.
public static MongoCredential createPlainCredential(String userName, String source, char[] password)
public static MongoCredential createGSSAPICredential(String userName)
To override the default service name of "mongodb", add a mechanism property with the name "SERVICE_NAME".
To force canonicalization of the host name prior to authentication, add a mechanism property with the name
"CANONICALIZE_HOST_NAME" with the valuetrue.
To override the Subject with which the authentication executes, add a mechanism property with the name
"JAVA_SUBJECT" with the value of a Subject instance.
To override the properties of the SaslClient with which the authentication executes, add a mechanism
property with the name "JAVA_SASL_CLIENT_PROPERTIES" with the value of a Map<String, Object instance containing the
necessary properties. This can be useful if the application is customizing the default
SaslClientFactory.
userName - the non-null user namewithMechanismProperty(String, Object),
SERVICE_NAME_KEY,
CANONICALIZE_HOST_NAME_KEY,
JAVA_SUBJECT_KEY,
JAVA_SASL_CLIENT_PROPERTIES_KEYpublic <T> MongoCredential withMechanismProperty(String key, T value)
T - the property typekey - the key to the property, which is treated as case-insensitivevalue - the value of the propertypublic String getMechanism()
public AuthenticationMechanism getAuthenticationMechanism()
public String getUserName()
public String getSource()
public char[] getPassword()
public <T> T getMechanismProperty(String key, T defaultValue)
T - the value typekey - the mechanism property key, which is treated as case-insensitivedefaultValue - the default value, if no mapping exists