@Immutable
public final class MongoCredential
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
GSSAPI_MECHANISM
The GSSAPI mechanism.
|
static java.lang.String |
MONGODB_CR_MECHANISM
The MongoDB Challenge Response mechanism.
|
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.
|
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)
Creates a MongoCredential instance for the MongoDB Challenge Response protocol.
|
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.
|
boolean |
equals(java.lang.Object o) |
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() |
<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.
|
public static final java.lang.String MONGODB_CR_MECHANISM
public static final java.lang.String GSSAPI_MECHANISM
public static final java.lang.String PLAIN_MECHANISM
public static final java.lang.String SCRAM_SHA_1_MECHANISM
public static final java.lang.String MONGODB_X509_MECHANISM
public static MongoCredential createCredential(java.lang.String userName, java.lang.String database, char[] password)
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 createMongoCRCredential(java.lang.String userName, java.lang.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 createGSSAPICredential(java.lang.String userName)
"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
.userName
- the user namewithMechanismProperty(String, Object)
public static MongoCredential createMongoX509Credential(java.lang.String userName)
userName
- the user namepublic 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 <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 java.lang.String getMechanism()
public java.lang.String getUserName()
public java.lang.String getSource()
public char[] getPassword()
public <T> T getMechanismProperty(java.lang.String key, 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.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object