@Immutable public final class MongoCredential extends Object
Modifier and Type | Field and Description |
---|---|
static String |
GSSAPI_MECHANISM
The GSSAPI mechanism.
|
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.
|
Modifier and Type | Method and Description |
---|---|
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(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.
|
boolean |
equals(Object o) |
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 GSSAPI_MECHANISM
public static final String PLAIN_MECHANISM
public static final String MONGODB_X509_MECHANISM
public static MongoCredential createMongoCRCredential(String userName, String database, char[] password)
userName
- the user namedatabase
- the database where the user is definedpassword
- the user's passwordpublic static MongoCredential createGSSAPICredential(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(String userName)
userName
- the user namepublic static MongoCredential createPlainCredential(String userName, 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(String key, T value)
T
- the property typekey
- the key to the propertyvalue
- the value of the propertypublic String getMechanism()
public String getUserName()
public String getSource()
public char[] getPassword()
public <T> T getMechanismProperty(String key, T defaultValue)
T
- the value typekey
- the mechanism property keydefaultValue
- the default value, if no mapping exists