public final class Credential extends Object implements Serializable
A given client can support a different set of credential for each database the client is accessing. The client can also authenticate against the "admin" database which will apply across all databases.
Note: While we use the term user name/password within this class the values may not actually be a user name or a password. In addition not all authentication mechanisms may use all of the fields in this class. See the documentation for the authenticator being used for details on what values are expected for each of the fields in this class.
Modifier and Type | Class and Description |
---|---|
static class |
Credential.Builder
Builder provides a helper for creating a
Credential . |
Modifier and Type | Field and Description |
---|---|
static String |
ADMIN_DB
The name of the administration database used to authenticate a
administrator to MongoDB.
|
static String |
KERBEROS
Constant for Kerberos authentication.
|
static String |
MONGODB_CR
Constant for traditional MongoDB Chllenge/Response.
|
static char[] |
NO_PASSWORD
An empty password array.
|
Constructor and Description |
---|
Credential(Credential.Builder builder)
Creates a new Credential.
|
Modifier and Type | Method and Description |
---|---|
Authenticator |
authenticator()
Returns an authenticator for the credential.
|
static Credential.Builder |
builder()
Creates a
Credential.Builder for creating a Credential . |
boolean |
equals(Object object) |
String |
getAuthenticationType()
Returns the authentication type or mode that the credential should be
used with.
|
Authenticator |
getAuthenticator()
Returns the authenticator value.
|
String |
getDatabase()
Returns the database the credential are valid for.
|
File |
getFile()
Returns the file containing the full credentials.
|
char[] |
getPassword()
Returns the password for the credential set.
|
String |
getUserName()
Returns the user name for the credential set.
|
int |
hashCode() |
boolean |
hasPassword()
Returns true if the password has atleast a single character.
|
String |
toString() |
public static final String ADMIN_DB
public static final String KERBEROS
Note: Use of the Kerberos for authentication requires the driver's extensions. See the Kerberos Usage Guide for details.
public static final String MONGODB_CR
public static final char[] NO_PASSWORD
public Credential(Credential.Builder builder)
builder
- The builder for the credentials.public static Credential.Builder builder()
Credential.Builder
for creating a Credential
.Credential.Builder
for creating a Credential
.public Authenticator authenticator() throws MongoDbAuthenticationException
MongoDbAuthenticationException
- On a failure to load the authenticator for the credential.public boolean equals(Object object)
Overridden to return true if the passed value equals these credential.
public String getAuthenticationType()
public Authenticator getAuthenticator()
public String getDatabase()
ADMIN_DB
to authenticate as an administrator.public File getFile()
null
.public char[] getPassword()
Arrays.fill(password, 0)
public String getUserName()
public int hashCode()
Overridden to hash the credential.
public boolean hasPassword()
Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.