com.mongodb
Class MongoCredential

java.lang.Object
  extended by com.mongodb.MongoCredential

@Immutable
public final class MongoCredential
extends Object

Represents credentials to authenticate to a mongo server, as well as the source of the credentials and the authentication mechanism to use.

Since:
2.11.0

Field Summary
static String GSSAPI_MECHANISM
          The GSSAPI mechanism.
static String MONGODB_CR_MECHANISM
          The MongoDB Challenge Response mechanism.
 
Method Summary
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.
 boolean equals(Object o)
           
 String getMechanism()
          Gets the mechanism
 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()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

GSSAPI_MECHANISM

public static final String GSSAPI_MECHANISM
The GSSAPI mechanism. See the RFC.

See Also:
Constant Field Values

MONGODB_CR_MECHANISM

public static final String MONGODB_CR_MECHANISM
The MongoDB Challenge Response mechanism.

See Also:
Constant Field Values
Method Detail

createMongoCRCredential

public static MongoCredential createMongoCRCredential(String userName,
                                                      String database,
                                                      char[] password)
Creates a MongoCredential instance for the MongoDB Challenge Response protocol.

Parameters:
userName - the user name
database - the database where the user is defined
password - the user's password
Returns:
the credential

createGSSAPICredential

public static MongoCredential createGSSAPICredential(String userName)
Creates a MongoCredential instance for the GSSAPI SASL mechanism.

Parameters:
userName - the user name
Returns:
the credential

getMechanism

public String getMechanism()
Gets the mechanism

Returns:
the mechanism.

getUserName

public String getUserName()
Gets the user name

Returns:
the user name. Can never be null.

getSource

public String getSource()
Gets the source of the user name, typically the name of the database where the user is defined.

Returns:
the user name. Can never be null.

getPassword

public char[] getPassword()
Gets the password.

Returns:
the password. Can be null for some mechanisms.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object