@Immutable public final class MongoCredential extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CANONICALIZE_HOST_NAME_KEY
Mechanism property key for specifying whether to canonicalize the host name for GSSAPI authentication.
|
static java.lang.String |
GSSAPI_MECHANISM
The GSSAPI mechanism.
|
static java.lang.String |
JAVA_SASL_CLIENT_PROPERTIES_KEY
Mechanism property key for overriding the SaslClient properties for GSSAPI authentication.
|
static java.lang.String |
JAVA_SUBJECT_KEY
Mechanism property key for overriding the
Subject under which GSSAPI authentication executes. |
static java.lang.String |
MONGODB_CR_MECHANISM
Deprecated.
This mechanism was replaced by
SCRAM_SHA_1_MECHANISM in MongoDB 3.0, and is now deprecated |
static java.lang.String |
MONGODB_X509_MECHANISM
The MongoDB X.509
|
static java.lang.String |
PLAIN_MECHANISM
The PLAIN mechanism.
|
static java.lang.String |
SCRAM_SHA_1_MECHANISM
The SCRAM-SHA-1 Mechanism.
|
static java.lang.String |
SCRAM_SHA_256_MECHANISM
The SCRAM-SHA-256 Mechanism.
|
static java.lang.String |
SERVICE_NAME_KEY
Mechanism property key for overriding the service name for GSSAPI authentication.
|
| Modifier and Type | Method and Description |
|---|---|
static MongoCredential |
createCredential(java.lang.String userName,
java.lang.String database,
char[] password)
Creates a MongoCredential instance with an unspecified mechanism.
|
static MongoCredential |
createGSSAPICredential(java.lang.String userName)
Creates a MongoCredential instance for the GSSAPI SASL mechanism.
|
static MongoCredential |
createMongoCRCredential(java.lang.String userName,
java.lang.String database,
char[] password)
Deprecated.
MONGODB-CR was replaced by SCRAM-SHA-1 in MongoDB 3.0, and is now deprecated. Use
the
createCredential(String, String, char[]) factory method instead. |
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(java.lang.String userName)
Creates a MongoCredential instance for the MongoDB X.509 protocol.
|
static MongoCredential |
createPlainCredential(java.lang.String userName,
java.lang.String source,
char[] password)
Creates a MongoCredential instance for the PLAIN SASL mechanism.
|
static MongoCredential |
createScramSha1Credential(java.lang.String userName,
java.lang.String source,
char[] password)
Creates a MongoCredential instance for the SCRAM-SHA-1 SASL mechanism.
|
static MongoCredential |
createScramSha256Credential(java.lang.String userName,
java.lang.String source,
char[] password)
Creates a MongoCredential instance for the SCRAM-SHA-256 SASL mechanism.
|
boolean |
equals(java.lang.Object o) |
AuthenticationMechanism |
getAuthenticationMechanism()
Gets the mechanism
|
java.lang.String |
getMechanism()
Gets the mechanism
|
<T> T |
getMechanismProperty(java.lang.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.
|
java.lang.String |
getSource()
Gets the source of the user name, typically the name of the database where the user is defined.
|
java.lang.String |
getUserName()
Gets the user name
|
int |
hashCode() |
java.lang.String |
toString() |
MongoCredential |
withMechanism(AuthenticationMechanism mechanism)
Creates a new MongoCredential with the set mechanism.
|
<T> MongoCredential |
withMechanismProperty(java.lang.String key,
T value)
Creates a new MongoCredential as a copy of this instance, with the specified mechanism property added.
|
@Deprecated public static final java.lang.String MONGODB_CR_MECHANISM
SCRAM_SHA_1_MECHANISM in MongoDB 3.0, and is now deprecatedpublic static final java.lang.String GSSAPI_MECHANISM
public static final java.lang.String PLAIN_MECHANISM
public static final java.lang.String MONGODB_X509_MECHANISM
public static final java.lang.String SCRAM_SHA_1_MECHANISM
public static final java.lang.String SCRAM_SHA_256_MECHANISM
public static final java.lang.String SERVICE_NAME_KEY
createGSSAPICredential(String),
withMechanismProperty(String, Object),
Constant Field Valuespublic static final java.lang.String CANONICALIZE_HOST_NAME_KEY
createGSSAPICredential(String),
withMechanismProperty(String, Object),
Constant Field Valuespublic static final java.lang.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 java.lang.String JAVA_SUBJECT_KEY
Subject under which GSSAPI authentication executes.createGSSAPICredential(String),
withMechanismProperty(String, Object),
Constant Field Valuespublic static MongoCredential createCredential(java.lang.String userName, java.lang.String database, char[] password)
If the server version is 4.0 or higher, the driver will negotiate with the server preferring the SCRAM-SHA-256 mechanism. 3.x servers will authenticate using SCRAM-SHA-1, older servers will authenticate using the MONGODB_CR mechanism.
userName - the user namedatabase - the database where the user is definedpassword - the user's passwordpublic static MongoCredential createScramSha1Credential(java.lang.String userName, java.lang.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 createScramSha256Credential(java.lang.String userName, java.lang.String source, char[] password)
userName - the non-null user namesource - the source where the user is defined.password - the non-null user passwordcreateCredential(String, String, char[])@Deprecated public static MongoCredential createMongoCRCredential(java.lang.String userName, java.lang.String database, char[] password)
createCredential(String, String, char[]) factory method instead.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(java.lang.String userName)
userName - the user namepublic static MongoCredential createMongoX509Credential()
Available on MongoDB server versions >= 3.4.
public static MongoCredential createPlainCredential(java.lang.String userName, java.lang.String source, char[] password)
userName - the non-null user namesource - the source where the user is defined. This can be either "$external" or the name of a database.password - the non-null user passwordpublic static MongoCredential createGSSAPICredential(java.lang.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(java.lang.String key, T value)
T - the property typekey - the key to the property, which is treated as case-insensitivevalue - the value of the propertypublic MongoCredential withMechanism(AuthenticationMechanism mechanism)
mechanism - the mechanism to set@Nullable public java.lang.String getMechanism()
@Nullable public AuthenticationMechanism getAuthenticationMechanism()
@Nullable public java.lang.String getUserName()
public java.lang.String getSource()
@Nullable public char[] getPassword()
@Nullable
public <T> T getMechanismProperty(java.lang.String key,
@Nullable
T defaultValue)
T - the value typekey - the mechanism property key, which is treated as case-insensitivedefaultValue - the default value, if no mapping existspublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2010 - 2023 Adobe. All Rights Reserved